diff --git a/events/models.py b/events/models.py index 59c0f4304..ba72244ee 100644 --- a/events/models.py +++ b/events/models.py @@ -137,7 +137,7 @@ async def read_wp_events_api(self, name, api, categorize): 'state': l['state'], } async with aiohttp.ClientSession(headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) as session: - async with session.get(api + "events/?event_end_after=" + (timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d") + "T00:00:00&page=1&per_page=20") as response: + async with session.get(api + "events/?event_end_after=" + (timezone.now()-timedelta(days=7)).strftime("%Y-%m-%d") + "T00:00:00&page=1&per_page=100") as response: result = json.loads(await response.text()) #print("Connected to " + name) @@ -153,115 +153,122 @@ async def read_wp_events_api(self, name, api, categorize): print("Failed requesting to " + name) async def wp_events_api_create_event(self, event_json, api, host, categorize, locations): - if not await self.filter(event_url=event_json['link'], start_time=datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone())).aexists(): - event = await self.acreate( - title=event_json['title'], - event_url=event_json['link'], - hash=self.hashing(event_json['link'] + str(event_json['start'])) - ) - else: - event = await self.filter(event_url=event_json['link'], start_time=datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone())).afirst() - if event.update_mode != 2: - return None - - event.title = str(event_json['title']['rendered'].encode('utf-8'), 'UTF-8') + if len(event_json['link']) > 150 and "?" in event_json['link']: + event_json['link'] = event_json['link'].split("?")[0] + try: + if not await self.filter(event_url=event_json['link'], start_time=datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone())).aexists(): + event = await self.acreate( + title=event_json['title'], + event_url=event_json['link'], + hash=self.hashing(event_json['link'] + str(event_json['start'])) + ) + else: + event = await self.filter(event_url=event_json['link'], start_time=datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone())).afirst() + if event.update_mode != 2: + return None - if event.hash == "": - event.hash = self.hashing(event_json['link'] + str(event_json['start'])) + event.title = str(event_json['title']['rendered'].encode('utf-8'), 'UTF-8') - event.description = str(event_json['excerpt']['rendered'].encode('utf-8'), 'UTF-8') + if event.hash == "": + event.hash = self.hashing(event_json['link'] + str(event_json['start'])) - event.start_time = datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone()) - event.end_time = datetime.fromisoformat(event_json['end']).astimezone(timezone.get_current_timezone()) + event.description = str(event_json['excerpt']['rendered'].encode('utf-8'), 'UTF-8') - if len(event_json['event-venues']) > 0: - if event_json['event-venues'][0] in locations: - venue = locations[event_json['event-venues'][0]] - else: - async with aiohttp.ClientSession(headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) as session: - async with session.get(api + 'event-venues/' + str(event_json['event-venues'][0])) as response: - venue = json.loads(await response.text()) - event.location=str(venue['name'].encode('utf-8'), 'UTF-8') - event.address=str((venue['address'] + ", " + venue['city'] + ", " + venue['state']).encode('utf-8'), 'UTF-8') - else: - event.location='' - event.address='' + event.start_time = datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone()) + event.end_time = datetime.fromisoformat(event_json['end']).astimezone(timezone.get_current_timezone()) - event.email='' - event.event_url=event_json['link'] + if len(event_json['event-venues']) > 0: + if event_json['event-venues'][0] in locations: + venue = locations[event_json['event-venues'][0]] + else: + async with aiohttp.ClientSession(headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) as session: + async with session.get(api + 'event-venues/' + str(event_json['event-venues'][0])) as response: + venue = json.loads(await response.text()) + event.location=str(venue['name'].encode('utf-8'), 'UTF-8') + event.address=str((venue['address'] + ", " + venue['city'] + ", " + venue['state']).encode('utf-8'), 'UTF-8') + else: + event.location='' + event.address='' - event.category = categorize['default'] - categories = ['entertainment', 'seminar', 'community', 'sports'] + event.email='' + event.event_url=event_json['link'] - for category in categories: - if event.category != categorize['default']: - break - categorize_key = category + '_title_terms' - if categorize_key in categorize: - - for term in categorize[categorize_key]: - if term.lower() in event.title.lower(): - event.category = category - break + event.category = categorize['default'] + categories = ['entertainment', 'seminar', 'community', 'sports'] - for category in categories: - if event.category != categorize['default']: - break - categorize_key = category + '_type' - if categorize_key in categorize: - for event_type in event_json['event-type']: + for category in categories: + if event.category != categorize['default']: + break + categorize_key = category + '_title_terms' + if categorize_key in categorize: - for category_type in categorize[categorize_key]: - if event_type == category_type: + for term in categorize[categorize_key]: + if term.lower() in event.title.lower(): event.category = category break - if event.category != categorize['default']: - break - - if event.hidden == False and 'hidden_title_terms' in categorize: - for term in categorize['hidden_title_terms']: - if term.lower() in event.title.lower(): - event.hidden = True + for category in categories: + if event.category != categorize['default']: break + categorize_key = category + '_type' + if categorize_key in categorize: + for event_type in event_json['event-type']: + + for category_type in categorize[categorize_key]: + if event_type == category_type: + event.category = category + break - event.hidden=False - if 'hidden_topics' in categorize: - for id in event_json['event-topic']: - - for topic in categorize['hidden_topics']: - if id == topic: + if event.category != categorize['default']: + break + + if event.hidden == False and 'hidden_title_terms' in categorize: + for term in categorize['hidden_title_terms']: + if term.lower() in event.title.lower(): event.hidden = True break - if event.hidden == True: - break + event.hidden=False + if 'hidden_topics' in categorize: + for id in event_json['event-topic']: + + for topic in categorize['hidden_topics']: + if id == topic: + event.hidden = True + break - if event.hidden == False and 'hidden_title_terms' in categorize: - for term in categorize['hidden_title_terms']: - if term.lower() in event.title.lower(): - event.hidden = True - break + if event.hidden == True: + break + + if event.hidden == False and 'hidden_title_terms' in categorize: + for term in categorize['hidden_title_terms']: + if term.lower() in event.title.lower(): + event.hidden = True + break - if timedelta(days=14) < event.end_time - event.start_time: - event.hidden=True + if timedelta(days=14) < event.end_time - event.start_time: + event.hidden=True - req = Request(api, headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) - if req.host in event_json['link']: - event.host = host - else: - if await self.filter(title=event.title, start_time=datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone())).exclude(id=event.id).aexists(): - event.hidden = True - elif 'chancentre.com' in event_json['link']: - event.host = 'Chan Centre for the Performing Arts' - elif not '.ubc.ca' in event_json['link']: + req = Request(api, headers={'User-Agent': "The Ubyssey https://ubyssey.ca/"}) + if req.host in event_json['link']: event.host = host + else: + if await self.filter(title=event.title, start_time=datetime.fromisoformat(event_json['start']).astimezone(timezone.get_current_timezone())).exclude(id=event.id).aexists(): + event.hidden = True + elif 'chancentre.com' in event_json['link']: + event.host = 'Chan Centre for the Performing Arts' + elif not '.ubc.ca' in event_json['link']: + event.host = host - event.update_mode = 1 - - await event.asave() - #print("Finished event " + event.event_url) - return event + event.update_mode = 1 + + await event.asave() + #print("Finished event " + event.event_url) + return event + except: + print("Failed on " + api) + print("- " + str(event_json['title']['rendered'].encode('utf-8'), 'UTF-8') + ": " + event_json['link']) + return None def wp_events_api_get_type_ids(self, api, terms): ids = [] diff --git a/ubyssey/static_src/src/js/components/Events/calendar.jsx b/ubyssey/static_src/src/js/components/Events/calendar.jsx index 628cc7d80..6300c9244 100644 --- a/ubyssey/static_src/src/js/components/Events/calendar.jsx +++ b/ubyssey/static_src/src/js/components/Events/calendar.jsx @@ -305,7 +305,7 @@ function EventsCalendar({events}) { if (event.end_time.getTime() - event.start_time.getTime() >= d-h || event.start_time.getHours() == 0) { event.displayTime = ""; } - while(cur <= new Date(event.end_time)) { + while(cur < new Date(event.end_time) || cur==event.start_time) { const delta = Math.floor((cur.getTime() - start.getTime()) / d); if (delta >= 0 && delta < (7*4)) { calendar[Math.floor(delta/7)]['days'][delta % 7]['events'].push(event);