Skip to content

Commit 4975600

Browse files
authored
Merge pull request #162 from ucladevx/hakan-facebook-place-error
facebook place error fixed by putting the event times addition event …
2 parents d8c96a6 + dfdbaad commit 4975600

File tree

2 files changed

+54
-142
lines changed

2 files changed

+54
-142
lines changed

src/mappening/api/utils/facebook2/fb2_event_processor.py

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,53 +31,19 @@
3131
# Process for frontend to use it
3232
def process_events(all_events):
3333

34-
filtered_events = []
34+
3535

3636
print(len(all_events))
3737

38-
for event in all_events:
39-
40-
# some events don't have a place, if they don't maybe just remove them for now and later try to get the place
41-
# TODO: find place from owner's location if place is not present
42-
if "place" not in event:
43-
# print("no place")
44-
# print(event)
45-
46-
# don't add to filtered_events
47-
continue
48-
49-
# some events have "place" but no "place.location"
50-
# this happens with some events that are imported to facebook from eventbrite
51-
# I.E. they have "owner" == Eventbrite
52-
# if this happens we can just exclude them from the facebook database collection
53-
# this might even be a good thing because if they are eventbrite events, it would be difficult to dedupe across collections anyways
54-
if "location" not in event["place"]:
55-
# print ("no location")
56-
# print(event)
57-
58-
# don't add to filtered_events
59-
continue
60-
61-
# change "zip" of place.location to "zipcode"
62-
if 'location' in event['place'] and 'zip' in event['place']['location']:
63-
event['place']['location']['zipcode'] = event['place']['location'].pop('zip')
64-
65-
# if event does not have an endtime, give it an endtime 1 hour into the future
66-
if "end_time" not in event:
67-
# print("no end_time")
68-
event["end_time"] = (datetime.datetime.strptime(event["start_time"], '%Y-%m-%dT%H:%M:%S%z') + datetime.timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%S%z')
69-
# print(event["end_time"])
70-
71-
filtered_events.append(event)
72-
38+
7339
# URL parameters for refreshing / updating events info, including subevents
7440
sub_event_call_args = {
7541
'fields': ','.join(EVENT_FIELDS),
7642
# 'fields': "id,name,cover,description,start_time,end_time,place,event_times",
7743
'access_token': app_access_token
7844
}
7945

80-
additional_events = []
46+
complete_events = []
8147

8248
# check for multiday events
8349
for event in all_events:
@@ -117,15 +83,60 @@ def process_events(all_events):
11783
# if sub_event['start_time'] != event['start_time']:
11884
# sub_event['duplicate_occurrence'] = True
11985

120-
additional_events.append(expanded_event_dict)
86+
# additional_events.append(expanded_event_dict)
87+
complete_events.append(expanded_event_dict)
88+
89+
# finally we want to remove this top level event to prevent duplication,
90+
# so just don't add it to complete_events
91+
12192
# More expanded_event_dict stuff: --haki
122-
# else:
123-
# expanded_event_dict.update({event['id']: event})
93+
else:
94+
complete_events.append(event)
95+
# expanded_event_dict.update({event['id']: event})
96+
97+
# print("additional facebook events")
98+
# print(len(additional_events))
99+
100+
# filtered_events.extend(additional_events)
101+
102+
filtered_events = []
103+
104+
for event in complete_events:
105+
106+
# some events don't have a place, if they don't maybe just remove them for now and later try to get the place
107+
# TODO: find place from owner's location if place is not present
108+
if "place" not in event:
109+
# print("no place")
110+
# print(event)
111+
112+
# don't add to filtered_events
113+
continue
114+
115+
# some events have "place" but no "place.location"
116+
# this happens with some events that are imported to facebook from eventbrite
117+
# I.E. they have "owner" == Eventbrite
118+
# if this happens we can just exclude them from the facebook database collection
119+
# this might even be a good thing because if they are eventbrite events, it would be difficult to dedupe across collections anyways
120+
if "location" not in event["place"]:
121+
# print ("no location")
122+
# print(event)
123+
124+
# don't add to filtered_events
125+
continue
126+
127+
# change "zip" of place.location to "zipcode"
128+
if 'location' in event['place'] and 'zip' in event['place']['location']:
129+
event['place']['location']['zipcode'] = event['place']['location'].pop('zip')
130+
131+
# if event does not have an endtime, give it an endtime 1 hour into the future
132+
if "end_time" not in event:
133+
# print("no end_time")
134+
event["end_time"] = (datetime.datetime.strptime(event["start_time"], '%Y-%m-%dT%H:%M:%S%z') + datetime.timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%S%z')
135+
# print(event["end_time"])
136+
137+
filtered_events.append(event)
124138

125-
print("additional facebook events")
126-
print(len(additional_events))
127139

128-
filtered_events.extend(additional_events)
129140

130141
print("filtered facebook events")
131142
print(len(filtered_events))

src/mappening/api/utils/facebook2/fb2_old_event_collector.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)