fixed feki.de events room import bug

This commit is contained in:
Götz 2017-10-09 00:39:40 +02:00
parent 7d9ad7601b
commit 20b68ecf9d
3 changed files with 46 additions and 28 deletions

View File

@ -22,19 +22,30 @@ def writeFekideDataInDB(data):
for event in date['events']: for event in date['events']:
try: try:
Location.objects.create(name=event['location']) Location.objects.create(name=event['location'])
event_obj = Event.objects.create() except IntegrityError:
event_obj.save() # print("Location %s already exists." % event['location'])
event_obj.date = datetime.strptime(date['date'], "%d.%m.%Y") pass
try:
event_obj, new = Event.objects.get_or_create(date=datetime.strptime(date['date'], "%d.%m.%Y"),
title=event['title'])
if new:
event_obj.category = event['category'] event_obj.category = event['category']
event_obj.link = event['link'] event_obj.link = event['link']
event_obj.time = datetime.strptime(str(event['time']).split()[1], "%H:%M") event_obj.time = datetime.strptime(str(event['time']).split()[1], "%H:%M")
event_obj.title = event['title']
event_obj.locations.add(Location.objects.get(name=event['location'])) event_obj.locations.add(Location.objects.get(name=event['location']))
event_obj.save() event_obj.save()
Event.objects.filter(title="").delete() Event.objects.filter(title="").delete()
else:
print("Event %s already exists. Start Update" % str(event_obj.title))
event_obj.category = event['category']
event_obj.link = event['link']
event_obj.time = datetime.strptime(str(event['time']).split()[1], "%H:%M")
event_obj.locations.add(Location.objects.get(name=event['location']))
event_obj.save()
except IntegrityError: except IntegrityError:
# ignored # ignored
break pass
def deleteUnivisObjects(): def deleteUnivisObjects():
@ -107,22 +118,30 @@ def writeUnivisEventsInDB(events: list):
Event.objects.filter(title="").delete() Event.objects.filter(title="").delete()
def main(): def write_out_db_objects():
deleteUnivisObjects()
events, rooms, persons = univis_eventpage_parser.parsePage(UNIVIS_RPG_HuWi)
writeUnivisDataInDB(events, rooms, persons)
events, rooms, persons = univis_eventpage_parser.parsePage(UNIVIS_RPG_SoWi)
writeUnivisDataInDB(events, rooms, persons)
events, rooms, persons = univis_eventpage_parser.parsePage(UNIVIS_RPG_GuK)
writeUnivisDataInDB(events, rooms, persons)
events, rooms, persons = univis_eventpage_parser.parsePage(UNIVIS_RPG_WIAI)
writeUnivisDataInDB(events, rooms, persons)
writeFekideDataInDB(fekide_eventpage_parser.parsePage())
pprint("Event: " + str(Event.objects.count())) pprint("Event: " + str(Event.objects.count()))
pprint("Location: " + str(Location.objects.count())) pprint("Location: " + str(Location.objects.count()))
def main():
print("Aktueller Stand:")
write_out_db_objects()
# deleteUnivisObjects()
# events, rooms, persons = univis_eventpage_parser.parsePage(UNIVIS_RPG_HuWi)
# writeUnivisDataInDB(events, rooms, persons)
# events, rooms, persons = univis_eventpage_parser.parsePage(UNIVIS_RPG_SoWi)
# writeUnivisDataInDB(events, rooms, persons)
# events, rooms, persons = univis_eventpage_parser.parsePage(UNIVIS_RPG_GuK)
# writeUnivisDataInDB(events, rooms, persons)
# events, rooms, persons = univis_eventpage_parser.parsePage(UNIVIS_RPG_WIAI)
# writeUnivisDataInDB(events, rooms, persons)
writeFekideDataInDB(fekide_eventpage_parser.parsePage())
print("Neuer Stand:")
write_out_db_objects()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -39,7 +39,6 @@ def writeStudentenwerkDataInDB(data):
def writeFekideDataInDB(data): def writeFekideDataInDB(data):
print(data)
for happyhour_data in data['happyhours']: for happyhour_data in data['happyhours']:
time = str(happyhour_data['time']).replace(" ", "").split("-") time = str(happyhour_data['time']).replace(" ", "").split("-")
happyhour, new = HappyHour.objects.get_or_create(date=datetime.strptime(data['day'], "%A, %d.%m.%Y"), happyhour, new = HappyHour.objects.get_or_create(date=datetime.strptime(data['day'], "%A, %d.%m.%Y"),
@ -47,9 +46,7 @@ def writeFekideDataInDB(data):
description=happyhour_data['description'], description=happyhour_data['description'],
starttime=datetime.strptime(time[0], "%H:%M").time(), starttime=datetime.strptime(time[0], "%H:%M").time(),
endtime=datetime.strptime(time[1], "%H:%M").time()) endtime=datetime.strptime(time[1], "%H:%M").time())
print("HH: %s, NEW: %s" % (str(happyhour), str(new)))
if not new: if not new:
print("Update db object " + happyhour.location)
happyhour.date = datetime.strptime(data['day'], "%A, %d.%m.%Y") happyhour.date = datetime.strptime(data['day'], "%A, %d.%m.%Y")
happyhour.location = happyhour_data['location'] happyhour.location = happyhour_data['location']
happyhour.description = happyhour_data['description'] happyhour.description = happyhour_data['description']

View File

@ -17,7 +17,9 @@
<li>{{ location.name }}</li> <li>{{ location.name }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% if event.link %}
<a href="{{ event.link }}">Details</a> <a href="{{ event.link }}">Details</a>
{% endif %}
<p>Kategorie: {{ event.category }}</p> <p>Kategorie: {{ event.category }}</p>
</div> </div>
</div> </div>