Skip to content

Commit 005e2cf

Browse files
committed
eb_event_collector.py changing it to not getting all the pages, just the first one, to avoid rate limiting. We will not keep this code but I'm pushing it to production for now.
1 parent 921cdb7 commit 005e2cf

File tree

3 files changed

+67
-29
lines changed

3 files changed

+67
-29
lines changed

src/mappening/api/utils/eventbrite/eb_event_collector.py

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from tqdm import tqdm
99
import json
1010
import requests
11+
from flask import jsonify
12+
import eventbrite
13+
14+
# eventbrite = eventbrite.Eventbrite(EVENTBRITE_USER_KEY)
1115

1216
from definitions import CENTER_LATITUDE, CENTER_LONGITUDE
1317

@@ -45,48 +49,79 @@ def get_raw_events(days_back_in_time):
4549

4650
session = requests.Session()
4751

52+
eventbrite2 = eventbrite.Eventbrite("GUD57Y44YXYVNP4VMQII")
53+
4854
personal_token = EVENTBRITE_USER_KEY
4955
base_endpoint = 'https://www.eventbriteapi.com/v3'
5056
sample_headers = {
51-
'Authorization': 'Bearer ' + personal_token
57+
'Authorization': 'Bearer ' + personal_token,
5258
}
5359

5460
# Most events on 1 page = 50, want more
55-
page_num = 1
61+
# page_num = 3
5662
request_new_results = True
5763

5864
events_search_ep = '/events/search'
5965
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"
6672
}
6773

74+
# response = eventbrite2.event_search(**search_args)
75+
76+
# print(response)
77+
6878
# 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()
79+
# all_events = response['events']
80+
81+
# request_more_events = response['pagination']['has_more_items']
82+
83+
# while request_more_events:
84+
85+
# search_args["page"]
86+
87+
# request_more_events = response['pagination']['has_more_items']
88+
89+
response = eventbrite2.event_search(**search_args)
90+
91+
print(response)
92+
93+
all_events = response.get('events')
94+
# while request_new_results and page_num <= 20:
95+
96+
# response = eventbrite2.event_search(**search_args)
97+
98+
# print(response)
99+
100+
# # There's always a 1st page result that works
101+
# search_args["page"] = page_num
102+
# print("search_args")
103+
# print(search_args)
104+
# # responseSession = session.get(
105+
# # base_endpoint + events_search_ep,
106+
# # headers = sample_headers,
107+
# # verify = True, # Verify SSL certificate
108+
# # params = search_args,
109+
# # ).json()
110+
111+
112+
# # print(responseSession)
113+
# # print(responseSession.text)
79114

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!')
115+
# # Extend, not append!
116+
# # combines elements of two lists as expected vs adds in the new list as ONE element
117+
# all_events.extend(response.get('events'))
118+
# if 'pagination' in response and response['pagination']['has_more_items']:
119+
# request_new_results = True
120+
# page_num += 1
121+
# else:
122+
# request_new_results = False
123+
124+
# print('Finished collecting Eventbrite events!')
90125
return all_events
91126

92127
# Database updating
@@ -102,6 +137,8 @@ def update_database(all_events):
102137
events_eventbrite_collection.delete_many({})
103138
events_eventbrite_collection.insert_many(all_events)
104139

140+
print('inserted properly')
141+
105142
all_cat_ep = '/categories'
106143
session = requests.Session()
107144
cat_resp = session.get(

src/mappening/utils/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pymongo import MongoClient
44

55
# Standard URI format: mongodb://[dbuser:dbpassword@]host:port/dbname
6-
events_uri = 'mongodb://{0}:{1}@{2}/events'.format(MLAB_USERNAME, MLAB_PASSWORD, MLAB_HOST)
6+
events_uri = 'mongodb://{0}:{1}@{2}/events?retryWrites=false'.format(MLAB_USERNAME, MLAB_PASSWORD, MLAB_HOST)
77
locations_uri = 'mongodb://{0}:{1}@{2}/locations'.format(MLAB_USERNAME, MLAB_PASSWORD, MLAB_HOST)
88
users_uri = 'mongodb://{0}:{1}@{2}/users'.format(MLAB_USERNAME, MLAB_PASSWORD, MLAB_HOST)
99
tkinter_uri = 'mongodb://{0}:{1}@{2}/tkinter'.format(MLAB_USERNAME, MLAB_PASSWORD, MLAB_HOST)

src/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ fuzzywuzzy
1616
unidecode
1717
psycopg2
1818
Flask-SQLAlchemy
19+
eventbrite

0 commit comments

Comments
 (0)