Skip to content

Commit 2e9a397

Browse files
authored
Merge pull request #136 from ucladevx/hakan-eventbrite
Hakan eventbrite changes to get backend to build
2 parents 0cfc420 + 14e66c8 commit 2e9a397

File tree

3 files changed

+65
-36
lines changed

3 files changed

+65
-36
lines changed

Diff for: src/mappening/api/utils/eventbrite/eb_event_collector.py

+63-35
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

@@ -43,50 +47,72 @@ def get_raw_events(days_back_in_time):
4347
past_bound = (now - datetime.timedelta(days=days_back)).strftime('%Y-%m-%dT%H:%M:%S')
4448
future_bound = (now + datetime.timedelta(days=days_forward)).strftime('%Y-%m-%dT%H:%M:%S')
4549

46-
session = requests.Session()
50+
# session = requests.Session()
4751

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+
# }
5359

5460
# 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
5763

58-
events_search_ep = '/events/search'
64+
# 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 = 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+
6884
# 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)
79105

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!')
90116
return all_events
91117

92118
# Database updating
@@ -102,6 +128,8 @@ def update_database(all_events):
102128
events_eventbrite_collection.delete_many({})
103129
events_eventbrite_collection.insert_many(all_events)
104130

131+
print('inserted properly')
132+
105133
all_cat_ep = '/categories'
106134
session = requests.Session()
107135
cat_resp = session.get(

Diff for: src/mappening/utils/database.py

+1-1
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)

Diff for: src/requirements.txt

+1
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)