Created
November 7, 2018 12:51
-
-
Save Haaroon/1e9a4834a73245d5d215cc3ef5d99f87 to your computer and use it in GitHub Desktop.
Tally matches from a cricket calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from icalendar import Calendar | |
g = open('calendar_name.ics','rb') | |
gcal = Calendar.from_ical(g.read()) | |
tally = { | |
'U8':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'U9':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'U10':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'U11':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'U12':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'U13':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'U15':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'U17':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'U19':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
'MDL':{'H':0, 'A':0, 'Day':0, 'Night':0, 'HDay':0, 'HNight':0, 'ADay':0, 'ANight':0}, | |
} | |
days = { | |
0:{'H':0, 'A':0, 'Day':0, 'Night':0}, | |
1:{'H':0, 'A':0, 'Day':0, 'Night':0}, | |
2:{'H':0, 'A':0, 'Day':0, 'Night':0}, | |
3:{'H':0, 'A':0, 'Day':0, 'Night':0}, | |
4:{'H':0, 'A':0, 'Day':0, 'Night':0}, | |
5:{'H':0, 'A':0, 'Day':0, 'Night':0}, | |
6:{'H':0, 'A':0, 'Day':0, 'Night':0}, | |
} | |
for comp in gcal.walk(): | |
evening = False | |
home = False | |
if comp.name == 'VEVENT': | |
if comp.get('dtstart').dt.year != 2018: | |
continue | |
day = comp.get('dtstart').dt.weekday() | |
if type(comp.get('dtstart').dt) is datetime.datetime: | |
if comp.get('dtstart').dt.hour >= 15: | |
evening = True | |
if '(H)' in comp.get('summary'): | |
home = True | |
if 'U7' in comp.get('summary'): | |
team = 'U7' | |
elif 'U8' in comp.get('summary'): | |
team = 'U8' | |
elif 'U9' in comp.get('summary'): | |
team = 'U9' | |
elif 'U10' in comp.get('summary'): | |
team = 'U10' | |
elif 'U11' in comp.get('summary'): | |
team = 'U11' | |
elif 'U12' in comp.get('summary'): | |
team = 'U12' | |
elif 'U13' in comp.get('summary'): | |
team = 'U13' | |
elif 'U14' in comp.get('summary'): | |
team = 'U14' | |
elif 'U15' in comp.get('summary'): | |
team = 'U15' | |
elif 'U16' in comp.get('summary'): | |
team = 'U16' | |
elif 'U17' in comp.get('summary'): | |
team = 'U17' | |
elif 'U18' in comp.get('summary'): | |
team = 'U18' | |
elif 'U19' in comp.get('summary'): | |
team = 'U19' | |
elif 'U20' in comp.get('summary'): | |
team = 'U20' | |
elif 'U21' in comp.get('summary'): | |
team = 'U21' | |
elif 'MDL'in comp.get('summary'): | |
team = 'MDL' | |
else: | |
continue | |
if home: | |
tally[team]['H'] += 1 | |
days[day]['H'] += 1 | |
else: | |
tally[team]['A'] += 1 | |
if home and evening: | |
tally[team]['HNight'] += 1 | |
elif home and not evening: | |
tally[team]['HDay'] += 1 | |
elif not home and evening: | |
tally[team]['ANight'] += 1 | |
elif not home and not evening: | |
tally[team]['ADay'] += 1 | |
if evening: | |
tally[team]['Night'] += 1 | |
if home: | |
days[day]['Night'] += 1 | |
else: | |
tally[team]['Day'] += 1 | |
if home: | |
days[day]['Day'] += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment