-
Notifications
You must be signed in to change notification settings - Fork 1
/
event.py
69 lines (43 loc) · 1.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
import re
class Event:
def __init__(self, data):
assert data is not None
assert len(data) > 0
self.__dict__.update(data)
def when(self):
""" Pretty-printed date (e.g. 27 Feb-2 Mar 2012). """
if not self.__dict__.has_key('startDate'): return None
start = self.startDate
end = self.endDate
s = None
if start.year != end.year: s = start.strftime("%d %b %Y").lstrip("0")
elif start.month != end.month: s = start.strftime("%d %b").lstrip("0")
elif start.day != end.day: s = str(start.day)
if s is None: s = ""
else: s += "-"
s += end.strftime("%d %b %Y").lstrip("0")
return s
def where(self):
location = (self.location, self.region, self.country)
return ", ".join(
[ unicode(i, "utf8") for i in location if i is not None ])
def format_deadline(self, which = None):
date = None
if which is None: date = self.deadline
else: date = self.__dict__[which + "Deadline"]
if date is None: return ""
return date.strftime("%d %b %Y").lstrip("0")
def tag_names(self, all_tags):
if 'tags' not in self.__dict__: return []
if self.tags is None: return []
my_tags = [ int(i) for i in self.tags.split(',') ]
return ', '.join([ all_tags[i] for i in my_tags ])
def proceedings_site(self):
""" Return the hostname that proceedings can be found on. """
if self.proceedings is None: return None
return re.sub("/.*$", "",
re.sub("^[a-z]+://", "", self.proceedings))
def __str__(self):
return "%s: %s in %s" % (self.abbreviation, self.when(), self.where())
def __repr__(self):
return repr(self.__dict__)