-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_racing_reference.py
708 lines (649 loc) · 36.7 KB
/
parse_racing_reference.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
import time
import pandas as pd
import requests
from bs4 import BeautifulSoup
from tqdm import tqdm
from datetime import datetime
def get_racing_reference_standings(season:int,series_id="W"):
main_df = pd.DataFrame()
row_df = pd.DataFrame()
url = f"https://www.racing-reference.info/season-stats/{season}/{series_id}/"
#driver.get(url)
headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"}
response = requests.get(url,headers=headers)
soup = BeautifulSoup(response.text, features='lxml')
table_rows = soup.find_all("div", {"itemprop":"SportsEvent","class":"table-row","role":"row"})
#print(table_rows)
for i in tqdm(table_rows):
#print('\n')
#print(i)
row_df = pd.DataFrame(columns=['season'],data=[season])
row_df['series_id'] = series_id
row_df['race_num'] = int(str(i.find('div',{'class':'race-number','role':'cell'}).text).replace(" ",""))
row_df['race_date'] = i.find('div',{'class':f'date {series_id}','role':'cell'}).text
row_df['race_track_name'] = i.find('div',{'class':f'track {series_id}','role':'cell'}).text
race_track_url = i.find('div',{'class':f'track {series_id}'}).find('a').get("href")
row_df['race_track_id'] = str(race_track_url).replace('https://www.racing-reference.info/tracks/','').replace(' ','')
row_df['race_car_count'] = int(str(i.find('div',{'class':'cars no-mobile','role':'cell'}).text).replace(' ',''))
row_df['race_winner_name'] = i.find('div',{'class':f'winners {series_id}','role':'cell'}).text
race_winner_url = i.find('div',{'class':f'winners {series_id}'}).find('a').get("href")
row_df['race_winner_real_id'] = race_winner_url.replace('https://www.racing-reference.info/driver/','').replace('/','')
try:
row_df['race_winner_starting_pos'] = int(str(i.find('div',{'class':'st no-mobile','role':'cell'}).text).replace(' ',''))
except:
row_df['race_winner_starting_pos'] = None
row_df['race_winner_make'] = i.find('div',{'class':f'manufacturer {series_id} no-mobile landscape','role':'cell'}).text
row_df['race_lap_len'] = i.find('div',{'class':'len no-mobile','role':'cell'}).text
row_df['race_track_surface'] = i.find('div',{'class':'sfc no-mobile','role':'cell'}).text
row_df['race_miles_completed'] = i.find('div',{'class':f'miles no-mobile {series_id} no-right-border','role':'cell'}).text
try:
row_df['race_purse_completed'] = int(str(i.find('div',{'class':f'purse no-mobile {series_id}','role':'cell'}).text).replace(' ','').replace(',',''))
except:
row_df['race_purse_completed'] = None
row_df['race_pole_time'] = i.find('div',{'class':'pole no-mobile no-tablet','role':'cell'}).text
row_df['race_cautions'] = str(i.find('div',{'class':'cautions no-mobile no-tablet','role':'cell'}).text).replace(' ','')
row_df['race_speed'] = i.find('div',{'class':'speed no-mobile no-tablet','role':'cell'}).text
row_df['race_lead_changes'] = i.find('div',{'class':'lc no-mobile no-tablet','role':'cell'}).text
row_df['race_url'] = str(i.find('div',{'class':'race-number'}).find("a").get("href")).replace(' ','')
row_df['race_track_url'] = race_track_url
row_df['race_winner_url'] = race_winner_url
#print(race_num,race_winner_real_id)
#print('\n')
main_df = pd.concat([main_df,row_df],ignore_index=True)
print(main_df)
time.sleep(1)
#main_df.to_csv('test.csv',index=False)
return main_df
def get_racing_reference_race_results(season:int,series_id="W"):
"""
"""
sched_df = pd.DataFrame()
## Cup series
if series_id.upper() == "W":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_cup/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Cup season.')
## Xfinity (Busch) series
elif series_id.upper() == "B":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_busch/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} Xfinity (Busch) season.')
## Craftsman Truck series
elif series_id.upper() == "C":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_trucks/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} Craftsman Truck season.')
## ARCA series
elif series_id.upper() == "A":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_arca/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} ARCA season.')
## ARCA East series
elif series_id.upper() == "P":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_arca_east/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} ARCA East season.')
## ARCA West series
elif series_id.upper() == "E":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_arca_west/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} ARCA West season.')
## Modified series
elif series_id.upper() == "N":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_arca/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Modified season.')
## NASCAR Pinty's series
elif series_id.upper() == "T":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_pintys/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Pinty\'s season.')
## NASCAR Convertable series
elif series_id.upper() == "V":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_convertible/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Convertible season.')
## NASCAR Grand National East series
elif series_id.upper() == "G":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_grand_national_east/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Grand National East season.')
## NASCAR North Tour series
elif series_id.upper() == "NN":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_north_tour/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR North Tour season.')
## IndyCar Series
elif series_id.upper() == "O":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_arca/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} IndyCar season.')
## Championship Auto Racing Teams (CART)
elif series_id.upper() == "R":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_arca/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} IndyCar season.')
## United States Auto Club (USAC) Championship Car Series
elif series_id.upper() == "UO":
try:
sched_df = pd.read_csv(f'racing_reference/usac_champ_car/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} USAC Championship Car Series season.')
## International Race of Champions (IROC)
elif series_id.upper() == "I":
try:
sched_df = pd.read_csv(f'racing_reference/iroc/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} International Race of Champions (IROC) season.')
## Indy NXT (Indy Lights)
elif series_id.upper() == "IL":
try:
sched_df = pd.read_csv(f'racing_reference/indy_lights/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} Indy NXT (Indy Lights) season.')
## ACT Late Model Tour
elif series_id.upper() == "AC":
try:
sched_df = pd.read_csv(f'racing_reference/act_late_model/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} ACT Late Model Tour season.')
## A1 Grand Prix
elif series_id.upper() == "A1":
try:
sched_df = pd.read_csv(f'racing_reference/a1_grand_prix/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} A1 Grand Prix season.')
## North American Touring Car Championship (NATCC)
elif series_id.upper() == "NA":
try:
sched_df = pd.read_csv(f'racing_reference/natcc/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} North American Touring Car Championship (NATCC) season.')
## NASCAR Whelen Southern Modified Tour (WSMT)
elif series_id.upper() == "M":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_whelen_southern_modified/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Whelen Southern Modified Tour (WSMT) season.')
## CARS Tour
elif series_id.upper() == "US":
try:
sched_df = pd.read_csv(f'racing_reference/cars_tour/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} CARS Tour season.')
## NASCAR Southeast Series
elif series_id.upper() == "SE":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_southeast_series/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Southeast Series season.')
## NASCAR Midwest Series
elif series_id.upper() == "MW":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_midwest_series/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Midwest Series season.')
## NASCAR Southwest Series
elif series_id.upper() == "SW":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_southwest_series/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Southwest Series season.')
## NASCAR Northwest Series
elif series_id.upper() == "NW":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_northwest_series/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Northwest Series season.')
## ASA National Tour
elif series_id.upper() == "AS":
try:
sched_df = pd.read_csv(f'racing_reference/asa_national_tour/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} ASA National Tour season.')
## ASA National Tour
elif series_id.upper() == "AS":
try:
sched_df = pd.read_csv(f'racing_reference/asa_national_tour/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} ASA National Tour season.')
## Whelen Southern Modified Tour
elif series_id.upper() == "M":
try:
sched_df = pd.read_csv(f'racing_reference/whelen_southern_modified_tour/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} Whelen Southern Modified Tour season.')
## NASCAR Peak Mexico Series
elif series_id.upper() == "MX":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_peak_mexico/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR Peak Mexico Series season.')
## NASCAR FedEx Challenge
elif series_id.upper() == "M2":
try:
sched_df = pd.read_csv(f'racing_reference/nascar_fedex_challenge/schedule/{season}_schedule.csv')
except:
raise FileNotFoundError(f'Could not find a schedule file for the {season} NASCAR FedEx Challenge.')
else:
raise ValueError("The input for series_id is invalid.")
race_url_arr = sched_df['race_url'].to_list()
race_num_arr = sched_df['race_num'].to_list()
#main_df = pd.DataFrame()
race_df = pd.DataFrame()
row_df = pd.DataFrame()
headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"}
for i in tqdm(range(0,len(race_url_arr))):
url = race_url_arr[i]
response = requests.get(url,headers=headers)
soup = BeautifulSoup(response.text, features='lxml')
# table 0: Race info table.
# table 1: Header table (links to stuff like race results, loop data, and pit stop data).
html_table = soup.find_all('table',{'class':'tb race-results-tbl'})[0]
#print(f"\n{html_table}")
race_id = str(url).replace("https://www.racing-reference.info/race-results/","").replace(f"/{series_id.upper()}","")
if race_num_arr[i] < 10:
race_id_short = f"{season}_0{race_num_arr[i]}_{series_id}"
else:
race_id_short = f"{season}_{race_num_arr[i]}_{series_id}"
for j in html_table.find_all('tr'):
row_df = pd.DataFrame({'season':season,'series_id':series_id,'race_id':race_id,'race_id_short':race_id_short},index=[0])
row = j.find_all('td')
if len(row) < 2:
## If this is less than 2, this is the header.
## We don't need the header.
pass
else:
#print(race_id)
row_df['finish_position'] = row[0].text.strip()
row_df['starting_position'] = row[1].text.strip()
row_df['driver_number'] = str(row[2].text.strip())
row_df['driver_nationality'] = str(row[3].find("img").get("src")).replace('//www.racing-reference.info/wp-content/themes/ndms/images/racing-reference/flags/','').replace('.png','')
try:
row_df['driver_id'] = str(row[3].find("a").get("href")).replace('https://www.racing-reference.info/driver/','').replace('/','')
except:
row_df['driver_id'] = None
row_df['driver_name'] = row[3].text.strip()
sponsor_owner = row[4].text.strip()
row_df['sponsor'] = sponsor_owner.split(' ')[0]
try:
row_df['owner_id'] = str(row[4].find("a").get("href")).replace('https://www.racing-reference.info/owner/','')
except:
row_df['owner_id'] = None
try:
row_df['car'] = row[5].text.strip()
except:
row_df['car'] = None
row_df['race_laps_run'] = row[6].text.strip()
row_df['race_status'] = row[7].text.strip()
row_df['race_laps_lead'] = row[8].text.strip()
try:
row_df['points_earned'] = row[9].text.strip()
except:
row_df['points_earned'] = None
try:
row_df['playoff_points_earned'] = row[10].text.strip()
except:
row_df['playoff_points_earned'] = None
race_df = pd.concat([race_df,row_df],ignore_index=True)
#print(race_df)
time.sleep(1)
return race_df
def main():
#current_year = datetime.now().year
now = datetime.now()
current_year = now.year
current_month = now.month
current_day = now.day
for i in range(current_year,current_year+1):
## Cup Series
if i >= 1949:
sched_df = get_racing_reference_standings(season=i,series_id="W")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_cup/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="W")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_cup/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Cup season.')
## Xfinity (Busch) Series
if i >= 1984:
sched_df = get_racing_reference_standings(season=i,series_id="B")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_busch/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="B")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_busch/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Xfinity season.')
## Truck Series
if i >= 1995:
sched_df = get_racing_reference_standings(season=i,series_id="C")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_trucks/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="C")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_trucks/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Trucks season.')
## ARCA Series
if i >= 1979:
sched_df = get_racing_reference_standings(season=i,series_id="A")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_arca/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="A")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_arca/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR ARCA season.')
## ARCA East Series
if i >= 1954:
sched_df = get_racing_reference_standings(season=i,series_id="P")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_arca_east/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="P")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_arca_east/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR ARCA East season.')
## ARCA West Series
if i >= 1987:
sched_df = get_racing_reference_standings(season=i,series_id="E") # Yes, this is the actual leauge ID for ARCA West.
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_arca_west/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="E")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_arca_west/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR ARCA West season.')
## Modified Series
if i >= 1948:
sched_df = get_racing_reference_standings(season=i,series_id="N")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_modified/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="N")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_modified/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Modifieds season.')
# NASCAR Pinty's Series
if i >= 2007:
sched_df = get_racing_reference_standings(season=i,series_id="T")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_pintys/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="T")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_pintys/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Pinty\'s season.')
## IndyCar Series
if i >= 1996:
sched_df = get_racing_reference_standings(season=i,series_id="O")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/indycar/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="O")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/indycar/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} IndyCar season.')
## Indy NXT (Indy Lights)
if i >= 1986:
sched_df = get_racing_reference_standings(season=i,series_id="IL")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/indy_lights/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="IL")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/indy_lights/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} Indy NXT (Indy Lights) season.')
# ACT Late Model Tour
if i >= 2006:
sched_df = get_racing_reference_standings(season=i,series_id="AC")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/act_late_model/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="AC")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/act_late_model/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} Indy NXT (Indy Lights) season.')
# Needs diffrient parser for this leauge.
## Supercars Championship
if i >= 1960:
sched_df = get_racing_reference_standings(season=i,series_id="V8")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/supercars_championship/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="V8")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/supercars_championship/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} Supercars Championship season.')
## NASCAR Peak Mexico
if i >= 2008:
sched_df = get_racing_reference_standings(season=i,series_id="MX")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_peak_mexico/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="MX")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_peak_mexico/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Peak Mexico season.')
## NASCAR FedEx Challenge
if i >= 2017:
sched_df = get_racing_reference_standings(season=i,series_id="M2")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_fedex_challenge/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="M2")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_fedex_challenge/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR FedEx Challenge season.')
# #####################################################################################################################################3
# ## Defunct Series
# #####################################################################################################################################3
## NASCAR Convertible Series
if i >= 1956 and i <= 1959:
sched_df = get_racing_reference_standings(season=i,series_id="V")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_convertible/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="V")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_convertible/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Convertible season.')
## NASCAR Grand National East Series
if i >= 1972 and i <= 1973:
sched_df = get_racing_reference_standings(season=i,series_id="G")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_grand_national_east/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="G")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_grand_national_east/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Convertible season.')
## NASCAR North Tour
if i >= 1979 and i <= 1985:
sched_df = get_racing_reference_standings(season=i,series_id="NN")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_north_tour/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="NN")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_north_tour/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR North Tour season.')
## Championship Auto Racing Teams (CART)
if i >= 1979 and i <= 2007:
sched_df = get_racing_reference_standings(season=i,series_id="R")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/cart/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="R")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/cart/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Convertible season.')
## USAC Champ Car Series
if i >= 1905 and i <= 1995:
sched_df = get_racing_reference_standings(season=i,series_id="UO")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/usac_champ_car/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="UO")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/usac_champ_car/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} USAC Champ Car Series season.')
## International Race of Champions (IROC)
if i >= 1974 and i <= 2006:
sched_df = get_racing_reference_standings(season=i,series_id="I")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/iroc/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="I")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/iroc/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} USAC Champ Car Series season.')
## A1 Grand Prix
if i >= 2005 and i <= 2008:
sched_df = get_racing_reference_standings(season=i,series_id="A1")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/a1_grand_prix/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="A1")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/a1_grand_prix/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} A1 Grand Prix season.')
## North American Touring Car Championship (NATCC)
if i >= 1996 and i <= 1997:
sched_df = get_racing_reference_standings(season=i,series_id="NA")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/natcc/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="NA")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/natcc/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} North American Touring Car Championship (NATCC) season.')
## NASCAR Whelen Southern Modified Tour (WSMT)
if i >= 2005 and i <= 2016:
sched_df = get_racing_reference_standings(season=i,series_id="M")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_whelen_southern_modified/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="M")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_whelen_southern_modified/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Whelen Southern Modified Tour (WSMT) season.')
## CARS Tour
if i >= 1997 and i <= 2014:
sched_df = get_racing_reference_standings(season=i,series_id="US")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/cars_tour/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="US")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/cars_tour/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} CARS Tour season.')
## NASCAR Southeast Series
if i >= 1991 and i <= 2006:
sched_df = get_racing_reference_standings(season=i,series_id="SE")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_southeast_series/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="SE")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_southeast_series/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Southeast Series season.')
## NASCAR Midwest Series
if i >= 1998 and i <= 2006:
sched_df = get_racing_reference_standings(season=i,series_id="MW")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_midwest_series/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="MW")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_midwest_series/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Midwest Series season.')
## NASCAR Southwest Series
if i >= 1986 and i <= 2006:
sched_df = get_racing_reference_standings(season=i,series_id="SW")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_southwest_series/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="SW")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_southwest_series/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Southwest Series season.')
## NASCAR Northwest Series
if i >= 1985 and i <= 2006:
sched_df = get_racing_reference_standings(season=i,series_id="NW")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/nascar_northwest_series/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="NW")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/nascar_northwest_series/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} NASCAR Northwest Series season.')
## ASA National Tour
if i >= 1998 and i <= 2004:
sched_df = get_racing_reference_standings(season=i,series_id="NW")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/asa_national_tour/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="MW")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/asa_national_tour/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} ASA National Tour season.')
## WHELEN SOUTHERN MODIFIED TOUR
if i >= 2005 and i <= 2016:
sched_df = get_racing_reference_standings(season=i,series_id="M")
if len(sched_df) > 0:
sched_df.to_csv(f"racing_reference/whelen_southern_modified_tour/schedule/{i}_schedule.csv",index=False)
try:
results_df = get_racing_reference_race_results(season=i,series_id="M")
if len(results_df) > 0:
results_df.to_csv(f"racing_reference/whelen_southern_modified_tour/race_results/{i}_race_results.csv",index=False)
except:
print(f'Could not get race results for the {i} ASA National Tour season.')
with open('racing_reference_status.json','w+') as f:
f.write(f"{{ \"year\":{current_year},\"month\":{current_month},\"day\":{current_day} }}")
if __name__ == "__main__":
main()