-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.py
58 lines (55 loc) · 1.89 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
import datetime
import json
"""
Event class
An event is represented by its date and a title.
It has other attributes like:
- description
- imageLink
- facebookLink
- eventbriteLink
- instagramLink
"""
class Event:
title = 'A title'
description = 'Text'
date = datetime.datetime(1943,3, 13) #year, month, day
imageLink = str() #optional
facebookLink = str() #optional
eventbriteLink = str() #optional
instagramLink = str() #optional
def __init__(self, title, description, date, imageLink=None, facebookLink=None, eventbriteLink=None, instagramLink=None):
self.title = title
self.description = description
self.date = date
self.imageLink = imageLink
self.facebookLink = facebookLink
self.eventbriteLink = eventbriteLink
self.instagramLink = instagramLink
"""
Load from events.json the list of events with the same language
of the one specified by the langString field
"""
def load_events(langString):
eventList = []
# try catch
try:
with open("events.json", "r", encoding="utf-8") as f:
data = json.load(f)
for x in data:
e = Event(
title = x["Title"],
date = datetime.datetime.strptime(x["Datetime"], "%Y %m %d"),
description = x["Description"],
imageLink = x["Image Link"],
eventbriteLink = x["Eventbrite Link"],
facebookLink = x["Facebook Link"],
instagramLink = x["Instagram Link"]
)
if x["Lang"] == langString:
eventList.append(e)
except Exception as e:
print("This error occurs: " + str(e))
# If an error occurs I erase the eventList
eventList = []
return eventList