summaryrefslogtreecommitdiff
path: root/preseason
diff options
context:
space:
mode:
Diffstat (limited to 'preseason')
-rwxr-xr-xpreseason/check-all.sh2
-rw-r--r--preseason/checks.py71
2 files changed, 49 insertions, 24 deletions
diff --git a/preseason/check-all.sh b/preseason/check-all.sh
index 3847cff..ed701d5 100755
--- a/preseason/check-all.sh
+++ b/preseason/check-all.sh
@@ -2,5 +2,5 @@
find config -name *.json |
while read JSON
do
- python3 checks.py ${JSON}
+ python3 checks.py ${JSON} dates logoh vp_table page_language team_names kolorki
done
diff --git a/preseason/checks.py b/preseason/checks.py
index c9d1acb..77cc57a 100644
--- a/preseason/checks.py
+++ b/preseason/checks.py
@@ -1,4 +1,4 @@
-import difflib, json, sys
+import difflib, io, json, sys
import requests
from bs4 import BeautifulSoup as bs
@@ -24,7 +24,7 @@ def check_round_date(round_no, round_date):
round_content = bs(round_html, 'lxml')
date_cell = round_content.select('td.bdnt12')[0].text.split('\xa0\xa0')
if date_cell[1] != round_date:
- print('Round date for round %d differs: expected "%s" got "%s"' % (
+ print('\tRound date for round %d differs: expected "%s" got "%s"' % (
round_no, round_date, date_cell[1]))
@@ -33,6 +33,16 @@ def check_dates():
check_round_date(i+1, config['round_dates'][i])
+def print_diff(str_1, str_2):
+ d = difflib.Differ()
+ for diff in d.compare(
+ [l.strip() for l in str_1.splitlines()],
+ [l.strip() for l in str_2.splitlines()]
+ ):
+ if not diff.startswith(' '):
+ print('\t' + diff)
+
+
def check_logoh():
if 'custom_file' in config['logoh']:
html_logoh = get_file(config['logoh']['custom_file'], prefixed=False)
@@ -42,13 +52,14 @@ def check_logoh():
template_logoh = logoh_file.read()
for var, val in config['logoh'].get('variables', {}).items():
template_logoh = template_logoh.replace('%' + var + '%', val)
- d = difflib.Differ()
- for diff in d.compare(
- [l.strip() for l in template_logoh.splitlines()],
- [l.strip() for l in html_logoh.splitlines()]
- ):
- if not diff.startswith(' '):
- print(diff)
+ print_diff(template_logoh, html_logoh)
+
+
+def check_kolorki():
+ server_kolorki = get_file('css/kolorki.css', prefixed=False)
+ with io.open('config/' + config['kolorki'], encoding='iso-8859-2') as kolorki_file:
+ template_kolorki = kolorki_file.read()
+ print_diff(template_kolorki, server_kolorki)
def check_vp_table():
@@ -64,7 +75,7 @@ def check_vp_table():
for i in range(0, len(imp_cells)):
if (imp_cells[i].text.strip().replace('\xa0', ' ') != vp_table[vp_row][0].strip()) or \
(vp_cells[i].text.strip().replace('\xa0', ' ') != vp_table[vp_row][1].strip()):
- print('VP table differs: expected (%s - %s), got (%s - %s)' % (
+ print('\tVP table differs: expected (%s - %s), got (%s - %s)' % (
*vp_table[vp_row],
imp_cells[i].text.strip(), vp_cells[i].text.strip()))
vp_row += 1
@@ -74,18 +85,22 @@ def check_page_language():
leaderboard = bs(get_file('leaderb.html'), 'lxml')
place_str = leaderboard.select('tr > td.bdcc12')[0].text
if place_str != config['language']:
- print('Page language does not match: expected "%s", got "%s"' % (
+ print('\tPage language does not match: expected "%s", got "%s"' % (
config['language'],
place_str))
-def get_cezar_team(team_id):
+def get_cezar_data(team_id):
r = requests.get('https://msc.com.pl/cezar/?p=213&action=1&id=%d' % (team_id))
r.raise_for_status()
r.encoding = 'utf8'
cezar_html = bs(r.text, 'lxml')
- title = cezar_html.select('p.msc_pagetitle')[0].contents[0].strip().replace('Drużyna ', '')
- return title
+ title = cezar_html.select('p.msc_pagetitle')[0].contents[0].strip().replace('Drużyna ', '').replace('\xa0', ' ').replace(' ', ' ')
+ player_ids = []
+ for link in cezar_html.select('a[href]'):
+ if link['href'].startswith('?p=21&pid='):
+ player_ids.append(int(link['href'].replace('?p=21&pid=', '')))
+ return (title, player_ids)
def get_cezar_names():
@@ -97,7 +112,7 @@ def get_cezar_names():
if t:
t = t.split()
teams[int(t[0])] = int(t[1])
- return { team_no: get_cezar_team(team_id) for team_no, team_id in teams.items() }
+ return { team_no: get_cezar_data(team_id) for team_no, team_id in teams.items() }
def get_html_names():
@@ -110,7 +125,12 @@ def get_html_names():
if link['href'].startswith(config['source']['prefix'] + 'T'):
team_id = int(link['href'].replace(config['source']['prefix'] + 'T', '').split('.')[0])
team_name = link.text.strip()
- teams[team_id] = team_name
+ team_page = bs(get_file('T%d.html' % (team_id)), 'lxml')
+ team_players = []
+ for link in team_page.select('a[href]'):
+ if link['href'].startswith('http://www.msc.com.pl/cezar/?mycl=1&p=21&r='):
+ team_players.append(int(link['href'].replace('http://www.msc.com.pl/cezar/?mycl=1&p=21&r=', '')))
+ teams[team_id] = (team_name, team_players)
return teams
@@ -118,13 +138,18 @@ def check_team_names():
cezar_names = get_cezar_names()
html_names = get_html_names()
for team_id, team_name in cezar_names.items():
- if html_names[team_id] != cezar_names[team_id]:
- print('Team name differs: expected "%s", got "%s"' % (cezar_names[team_id], html_names[team_id]))
+ if html_names[team_id][0] != cezar_names[team_id][0]:
+ print('\tTeam name differs: expected "%s", got "%s"' % (cezar_names[team_id][0], html_names[team_id][0]))
+ if not html_names[team_id][1]:
+ print('\tNo player links found for team "%s"' % (html_names[team_id][0]))
+ else:
+ for pid in html_names[team_id][1]:
+ if pid not in cezar_names[team_id][1]:
+ print('\tPlayer #%d not a member of team "%s"' % (pid, html_names[team_id][0]))
+
print('Checking %s' % (sys.argv[1]))
-check_dates()
-check_logoh()
-check_vp_table()
-check_page_language()
-check_team_names()
+for check in sys.argv[2:]:
+ print(' ' + check)
+ globals()['check_' + check]()