-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_event.py
128 lines (116 loc) · 3.92 KB
/
create_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
from datetime import datetime
import re
import boto3
from seats import create_seats
client = boto3.client('dynamodb',region_name='ap-southeast-2',aws_access_key_id='AKIAQPNE33YVPQHU7F64',aws_secret_access_key='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')
event_types = ["Sports", "Arts", "Festivals", "Theatre"]
postcode_regex = re.compile(r'\d{4}')
url_safe = set("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$–_.+!*‘(),")
def post_event_details(event_info):
check_output = client.put_item(TableName='event_details',
Item={
# 'Event ID':{'S': event_info['event_id']},
'Event Title':{'S': event_info['title']},
'Description':{'S': event_info['description']},
'Type':{'S': event_info['type']},
'Venue':{'S': event_info['venue']},
'Start Date':{'S': event_info['start_date']},
'End Date':{'S': event_info['end_date']},
'Tickets Available': {'S': event_info['tickets_available']},
'Ticket Price': {'S': event_info['ticket_price']},
'List of Attendees': {'L': event_info['list_attendees']},
'Seats' : { 'M': create_seats()},
'Host': {'S': event_info['host']},
'Postcode' : {'S': str(event_info['postcode'])}
}
)
client.put_item(TableName='review_details',
Item={
# 'Event ID':{'S': event_info['event_id']},
'Event Title':{'S': event_info['title']},
'Reviews':{'M': {}}
}
)
return check_output
"""
event_info = {
"title": request.form['title'],
"description": request.form['description'],
"type": request.form['type'],
"venue": request.form['venue'],
"start_date": request.form['start_date'],
"end_date": request.form['end_date'],
"tickets_available": request.form['tickets_available'],
"ticket_price": request.form['ticket_price'],
"postcode": request.form['postcode'],
"host": user,
}
"""
def check_event_title(title):
try:
if set(title) <= url_safe:
return True #Check the title contains only URL safe characters
except:
pass
return False
def check_event_type(type):
try:
if type in event_types:
return True
except:
pass
return False
def check_event_dates(start_date, end_date):
try:
start_parsed = datetime.strptime(start_date,"%d/%m/%Y")
end_parsed = datetime.strptime(end_date,"%d/%m/%Y")
if datetime.today() > start_date:
return False #Events must be in the future!
if start_parsed > end_parsed:
return False #Events must end after they start!
return True
except:
pass
return False
def check_event_tickets(tickets_available, ticket_price):
try:
if int(tickets_available) <= 0:
return False
if int(ticket_price) < 0:
return False
return True
except:
pass
return False
def check_event_postcode(postcode):
try:
if re.fullmatch(postcode_regex, postcode):
return True
except:
pass
return False
def check_event_details(event_info):
if (
not event_info['title'] or
not event_info['description'] or
not event_info['type'] or
not event_info['venue'] or
not event_info['start_date'] or
not event_info['end_date'] or
not event_info['tickets_available'] or
not event_info['ticket_price'] or
not event_info['postcode'] or
not event_info['host']
):
return False
if not check_event_title(event_info['title']):
return False
if not check_event_title(event_info['type']):
return False
if not check_event_dates(event_info['start_date'], event_info['end_date']):
return False
if not check_event_tickets(event_info['tickets_available'], event_info['ticket_price']):
return False
if not check_event_postcode(event_info['postcode']):
return False
return True