91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
|
|
import json
|
||
|
|
|
||
|
|
import os, sys
|
||
|
|
from datetime import datetime
|
||
|
|
from dateutil import relativedelta
|
||
|
|
|
||
|
|
import django
|
||
|
|
sys.path.append('../../../../')
|
||
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.django.local'
|
||
|
|
django.setup()
|
||
|
|
|
||
|
|
from time import sleep
|
||
|
|
from pprint import pprint as ppr
|
||
|
|
import pytz
|
||
|
|
|
||
|
|
from events.models import Organization, Scraper, Calendar, Event
|
||
|
|
import events.digitools as digitools
|
||
|
|
|
||
|
|
|
||
|
|
venue, created = Organization.objects.get_or_create(
|
||
|
|
name="Eventario",
|
||
|
|
city="Medellin",
|
||
|
|
website="https://www.eventario.co",
|
||
|
|
is_venue=True
|
||
|
|
)
|
||
|
|
|
||
|
|
scraper,item_count_start,virtcal = digitools.getScraper(venue, 'mde')
|
||
|
|
|
||
|
|
DATETIME_FORMAT = '%-d/%-m/%y %I:%M %p'
|
||
|
|
|
||
|
|
|
||
|
|
with open('data.json') as f:
|
||
|
|
data = json.load(f)
|
||
|
|
|
||
|
|
paisa = []
|
||
|
|
|
||
|
|
for d in data:
|
||
|
|
if len(d['dateTime']) != 0:
|
||
|
|
if 'Familia' in d['label']:
|
||
|
|
d['category'] = 'Ot'
|
||
|
|
elif 'Comedia' in d['label']:
|
||
|
|
d['category'] = 'Co'
|
||
|
|
elif ('Magic' in d['title']) or ('Juegos' in d['label']):
|
||
|
|
d['category'] = 'Ot'
|
||
|
|
elif ('Conferencias' in d['label']) or ('Intercambio' in d['label']):
|
||
|
|
d['category'] = 'Ed'
|
||
|
|
else:
|
||
|
|
d['category'] = 'Mu'
|
||
|
|
if "Antioquia" in d['location']:
|
||
|
|
try:
|
||
|
|
d['city'] = d['location'].split(',')[0]
|
||
|
|
paisa.append(d)
|
||
|
|
except:
|
||
|
|
continue
|
||
|
|
|
||
|
|
# ppr(paisa)
|
||
|
|
with open('data.updated.json', 'w', encoding='utf-8') as f:
|
||
|
|
json.dump(data, f, ensure_ascii=False, indent=4)
|
||
|
|
|
||
|
|
|
||
|
|
cal = Calendar.objects.get(shortcode='mde')
|
||
|
|
|
||
|
|
|
||
|
|
for d in paisa:
|
||
|
|
d['dateStamp'] =datetime.strptime(d['dateTime'][0], DATETIME_FORMAT)
|
||
|
|
try:
|
||
|
|
nvenue, created = Organization.objects.get_or_create(
|
||
|
|
name=d['venue'],
|
||
|
|
city=d['city'],
|
||
|
|
website=d['venueLink'],
|
||
|
|
address_complete = d['address'],
|
||
|
|
is_venue=True
|
||
|
|
)
|
||
|
|
except:
|
||
|
|
nvenue = Organization.objects.get(name=d['venue'])
|
||
|
|
nvenue.address_complete = d['address']
|
||
|
|
nvenue.save()
|
||
|
|
new_event, created = Event.objects.update_or_create(
|
||
|
|
event_type = d['category'],
|
||
|
|
show_title = d['title'],
|
||
|
|
show_link = d['link'],
|
||
|
|
show_date = d['dateStamp'],
|
||
|
|
show_day = d['dateStamp'],
|
||
|
|
scraper = scraper,
|
||
|
|
venue = nvenue
|
||
|
|
)
|
||
|
|
new_event.calendar.add(cal)
|
||
|
|
new_event.save()
|
||
|
|
print(new_event)
|
||
|
|
|
||
|
|
digitools.updateScraper(scraper, item_count_start)
|