8
8
from tqdm import tqdm
9
9
import json
10
10
import requests
11
+ from flask import jsonify
12
+ import eventbrite
13
+
14
+ # eventbrite = eventbrite.Eventbrite(EVENTBRITE_USER_KEY)
11
15
12
16
from definitions import CENTER_LATITUDE , CENTER_LONGITUDE
13
17
@@ -43,50 +47,72 @@ def get_raw_events(days_back_in_time):
43
47
past_bound = (now - datetime .timedelta (days = days_back )).strftime ('%Y-%m-%dT%H:%M:%S' )
44
48
future_bound = (now + datetime .timedelta (days = days_forward )).strftime ('%Y-%m-%dT%H:%M:%S' )
45
49
46
- session = requests .Session ()
50
+ # session = requests.Session()
47
51
48
- personal_token = EVENTBRITE_USER_KEY
49
- base_endpoint = 'https://www.eventbriteapi.com/v3'
50
- sample_headers = {
51
- 'Authorization' : 'Bearer ' + personal_token
52
- }
52
+ eb = eventbrite .Eventbrite (EVENTBRITE_USER_KEY )
53
+
54
+ # personal_token = EVENTBRITE_USER_KEY
55
+ # base_endpoint = 'https://www.eventbriteapi.com/v3'
56
+ # sample_headers = {
57
+ # 'Authorization': 'Bearer ' + personal_token,
58
+ # }
53
59
54
60
# Most events on 1 page = 50, want more
55
- page_num = 1
56
- request_new_results = True
61
+ # page_num = 1
62
+ # request_new_results = True
57
63
58
- events_search_ep = '/events/search'
64
+ # events_search_ep = '/events/search'
59
65
search_args = {
60
- ' location.latitude' : CENTER_LATITUDE ,
61
- ' location.longitude' : CENTER_LONGITUDE ,
62
- ' location.within' : ' 1mi' ,
63
- ' start_date.range_start' : past_bound ,
64
- ' start_date.range_end' : future_bound ,
65
- ' sort_by' : ' best'
66
+ " location.latitude" : CENTER_LATITUDE ,
67
+ " location.longitude" : CENTER_LONGITUDE ,
68
+ " location.within" : " 1mi" ,
69
+ " start_date.range_start" : past_bound ,
70
+ " start_date.range_end" : future_bound ,
71
+ " sort_by" : " best"
66
72
}
67
73
74
+ response = eb .event_search (** search_args )
75
+
76
+ print (response )
77
+
78
+ all_events = response .get ('events' )
79
+
80
+ # TODO: We need to add pagination back. Cindy can try scheduling this to get
81
+ # each page after every 10 minutes until has_more_items is false
82
+ # to get around rate limiting.
83
+
68
84
# Loop through returned pages of events until no more, or enough
69
- all_events = []
70
- while request_new_results and page_num <= 20 :
71
- # There's always a 1st page result that works
72
- search_args ['page' ] = str (page_num )
73
- response = session .get (
74
- base_endpoint + events_search_ep ,
75
- headers = sample_headers ,
76
- verify = True , # Verify SSL certificate
77
- params = search_args ,
78
- ).json ()
85
+ # while request_new_results and page_num <= 20:
86
+
87
+ # response = eventbrite2.event_search(**search_args)
88
+
89
+ # print(response)
90
+
91
+ # # There's always a 1st page result that works
92
+ # search_args["page"] = page_num
93
+ # print("search_args")
94
+ # print(search_args)
95
+ # # responseSession = session.get(
96
+ # # base_endpoint + events_search_ep,
97
+ # # headers = sample_headers,
98
+ # # verify = True, # Verify SSL certificate
99
+ # # params = search_args,
100
+ # # ).json()
101
+
102
+
103
+ # # print(responseSession)
104
+ # # print(responseSession.text)
79
105
80
- # Extend, not append!
81
- # combines elements of two lists as expected vs adds in the new list as ONE element
82
- all_events .extend (response .get ('events' ))
83
- if 'pagination' in response and response ['pagination' ]['has_more_items' ]:
84
- request_new_results = True
85
- page_num += 1
86
- else :
87
- request_new_results = False
88
-
89
- print ('Finished collecting Eventbrite events!' )
106
+ # # Extend, not append!
107
+ # # combines elements of two lists as expected vs adds in the new list as ONE element
108
+ # all_events.extend(response.get('events'))
109
+ # if 'pagination' in response and response['pagination']['has_more_items']:
110
+ # request_new_results = True
111
+ # page_num += 1
112
+ # else:
113
+ # request_new_results = False
114
+
115
+ # print('Finished collecting Eventbrite events!')
90
116
return all_events
91
117
92
118
# Database updating
@@ -102,6 +128,8 @@ def update_database(all_events):
102
128
events_eventbrite_collection .delete_many ({})
103
129
events_eventbrite_collection .insert_many (all_events )
104
130
131
+ print ('inserted properly' )
132
+
105
133
all_cat_ep = '/categories'
106
134
session = requests .Session ()
107
135
cat_resp = session .get (
0 commit comments