-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.py
142 lines (117 loc) · 4.54 KB
/
event.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import urllib.request, urllib.error
from datetime import datetime
from icalendar import Event, vText
from typing import List
class TourEvent:
def __init__(self, stage: str, start_date: datetime, end_hour: int):
self._stage = stage
self._start_date = start_date
self._end_hour = end_hour
@property
def stage(self) -> str:
return self._stage
@property
def start_date(self) -> datetime:
return self._start_date
@property
def end_date(self) -> datetime:
return self.start_date.replace(hour=self._end_hour)
def start_datestr(self) -> str:
return self.start_date.strftime('%Y%m%dT%H%M%S')
def get_summary(self) -> str:
pass
def get_location(self) -> vText:
return None
def get_description(self) -> str:
pass
def get_uid(self) -> str:
return '{}@{}'.format(self.start_datestr(), self.stage)
def to_ical(self) -> Event:
event = Event()
event.add('dtstart', self.start_date)
event.add('dtend', self.end_date)
event.add('dtstamp', self.start_date)
event.add('summary', self.get_summary())
if self.get_location():
event['location'] = self.get_location()
event['uid'] = self.get_uid()
event.add('description', self.get_description())
return event
class PerfectEvent(TourEvent):
END_HOUR = 20
def __init__(self, stage: str, start_date: datetime, location: str, venue: str, point: str, is_men: bool, is_women: bool):
self._location = location
self._venue = venue
self._point = point
self._is_men = is_men
self._is_women = is_women
super().__init__(stage, start_date, self.END_HOUR)
def get_summary(self) -> str:
participants = []
if self._is_men:
participants.append('男子')
if self._is_women:
participants.append('女子')
return 'PERFECT {}: {} ({}) ({})'.format(self.stage, self._location, '/'.join(participants), self._point)
def get_location(self) -> vText:
return vText(self._venue)
def get_description(self) -> str:
date = self.start_datestr()
url = 'https://www.prodarts.jp/archives/outline/{}'.format(date[:date.index('T')])
req = urllib.request.Request(url, method='HEAD')
try:
resp = urllib.request.urlopen(req)
if resp.status == 200:
return url
except urllib.error.HTTPError:
return ''
class JapanEvent(TourEvent):
END_HOUR = 23
def __init__(self, stage: str, start_date: datetime, location: str, venue: str, japan_year: int, is_ex: bool):
self._location = location
self._venue = venue
self._japan_year = japan_year
self._is_ex = is_ex
super().__init__(stage, start_date, self.END_HOUR)
def get_summary(self) -> str:
summary = 'JAPAN {}: {}'.format(self.stage, self._location)
if self._is_ex:
summary += ' (EX)'
return summary
def get_location(self) -> vText:
return vText(self._venue)
def get_description(self) -> str:
url = 'https://japanprodarts.jp/{}/{}.php'.format(self._japan_year, self.stage)
req = urllib.request.Request(url, method='HEAD')
try:
resp = urllib.request.urlopen(req)
if resp.status == 200:
return url
except urllib.error.HTTPError:
pass
url = 'https://japanprodarts.jp/{}/{}.php'.format(self._japan_year, self.stage.lower())
req = urllib.request.Request(url, method='HEAD')
try:
resp = urllib.request.urlopen(req)
if resp.status == 200:
return url
except urllib.error.HTTPError:
pass
return ''
class DTourEvent(TourEvent):
END_HOUR = 22
def __init__(self, stage: str, start_date: datetime, division: str, details_url: str, prelim_info: str, end_date: datetime = None):
self._division = division
self._details_url = details_url
self._prelim_info = prelim_info
self._end_date = end_date
super().__init__(stage, start_date, self.END_HOUR)
@property
def end_date(self) -> datetime:
if self._end_date is not None:
return self._end_date
return self.start_date.replace(hour=self._end_hour)
def get_summary(self) -> str:
return 'DTOUR {} {}'.format(self._division, self.stage)
def get_description(self) -> str:
return '{}\n{}'.format(self._details_url, self._prelim_info)