Private
Public Access
1
0

updated scraoper

This commit is contained in:
Sander Roosendaal
2023-03-13 19:41:41 +01:00
parent 2f41551df2
commit 3d81244c31
5 changed files with 17 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import requests
from boatmovers.models import *
import pandas as pd
from django.core.exceptions import ValidationError
from django.db.utils import IntegrityError
url_heineken = ''
@@ -115,11 +116,14 @@ def time_team_scraper(url,raceid,gender='m',startorder=1):
try:
first_name = str(df['naam'][i])
last_name = ''
full_name = first_name
dummy=False
except TypeError:
first_name = 'Unknown'
last_name = 'Athlete'
full_name = 'Unknown Athlete'
dummy=True
print(full_name)
athletes = Athlete.objects.filter(full_name=full_name)
if len(athletes) >= 1:
athlete = athletes[0]
@@ -131,11 +135,15 @@ def time_team_scraper(url,raceid,gender='m',startorder=1):
dummy=dummy)
try:
athlete.save()
except IntegrityError:
athletes = Athlete.objects.filter(full_name__icontains=full_name)
if len(athletes) >= 1:
athlete = athletes[0]
except ValidationError as e:
text, id = e.message.split(':')
athlete = Athlete.objects.get(id=id)
print(athlete)
#print(athlete)
crew.athletes.add(athlete)