-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (48 loc) · 1.86 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# coding: utf-8
import os
import sys
from textprocess import process
from graph import plot
from setupAndDownload import download, upload, getProfile, getTeamnames, getPedaleurs
#gather the data
race = sys.argv[1]
year = sys.argv[2]
raceString = 'race/' + race + '/' + year + '/'
URLBase = 'https://www.procyclingstats.com/'
URL = URLBase + raceString
folderName = os.path.basename(raceString.replace("/", "@"))
if not os.path.exists(folderName):
os.makedirs(folderName)
(stageProfile, stageNames) = getProfile(URL)
fileName = os.path.join(folderName, 'stageProfile')
if not os.path.isfile(fileName):
with open(fileName, 'w', encoding='utf-8') as file:
file.write(str(stageProfile))
fileName = os.path.join(folderName, 'teamAbbrevations')
if not os.path.isfile(fileName):
teamAbbrevations = getTeamnames(URL)
with open(fileName, 'w', encoding='utf-8') as file:
file.write(str(teamAbbrevations))
fileName = os.path.join(folderName, 'pedaleurs')
if not os.path.isfile(fileName):
pedaleurs = getPedaleurs(URL)
with open(fileName, 'w', encoding='utf-8') as file:
file.write(str(pedaleurs))
stageNumber = 0
for stage in stageNames:
fileName = os.path.join(folderName,
stage.replace("/", "@") + '%' + str(stageNumber))
if not os.path.isfile(fileName):
print('creating stage:' + str(stage))
stageURL = URLBase + str(stage)
page = download(stageURL)
#with open(fileName + 'test', 'w', encoding='utf-8') as file:
# file.write(page)
stageResults = process(page)
with open(fileName, 'w', encoding='utf-8') as file:
file.write(str(stageResults))
stageNumber = stageNumber + 1
print(str(stage) + ' is processed')
print('processing done')
imageName = plot(stageNumber, race, year)
print('Your image is uploaded at: ' + str(upload(imageName)))