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)

View File

@@ -14,6 +14,6 @@ importsources = {
'nk': NKIntegration,
'tp':TPIntegration,
'rp3':RP3Integration,
'polar': PolarIntegration
'polar': PolarIntegration,
}

View File

@@ -269,7 +269,7 @@ class NKIntegration(SyncIntegration):
def open(self, *args, **kwargs) -> str:
r = self.rower
if (r.nktoken == '') or (r.nktoken is None): # pragma: no cover
if not r.nktoken: # pragma: no cover
raise NoTokenError("User has no token")
else:
if (timezone.now() > r.nktokenexpirydate):

Binary file not shown.

View File

@@ -361,7 +361,12 @@ def workout_import_view(request, source='c2'):
enddate = enddate.date()
r = getrequestrower(request)
integration = importsources[source](request.user)
try:
integration = importsources[source](request.user)
except KeyError:
messages.error(request,"This integration is not supported")
url = reverse('workouts_view')
return HttpResponseRedirect(url)
try:
_ = integration.open()