This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_xfl_transactions.py
87 lines (75 loc) · 4.96 KB
/
get_xfl_transactions.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
# from urllib.request import urlopen
from bs4 import BeautifulSoup
import pandas as pd
import requests
from tqdm import tqdm
def get_xfl_transactions(season=2024, save=False):
main_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"}
url = f"https://www.xfl.com/xfl-transactions"
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, features='lxml')
table_rows = soup.find_all('tr')
for i in tqdm(range(1, len(table_rows))):
t_rows = table_rows[i]
t_cells = t_rows.find_all('td')
team_logo_url = t_cells[0].find('img').get('src')
team_id = ""
match team_logo_url:
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-st-louis-battlehawks-500x500.png":
team_id = "STL"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555934/xfl-prod/logos/logo-st-louis-battlehawks-500x500.png":
team_id = "STL"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-houston-roughnecks-500x500.png":
team_id = "HOU"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555934/xfl-prod/logos/logo-houston-roughnecks-500x500.png":
team_id = "HOU"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-orlando-guardians-500x500.png":
team_id = "ORL"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-orlando-guardians-500x500.png":
team_id = "ORL"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555934/xfl-prod/logos/logo-orlando-guardians-500x500.png.png":
team_id = "ORL"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555934/xfl-prod/logos/logo-orlando-guardians-500x500.png":
team_id = "SEA"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-seattle-sea-dragons-500x500.png":
team_id = "SEA"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-vegas-vipers-500x500.png":
team_id = "VGS"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555934/xfl-prod/logos/logo-vegas-vipers-500x500.png":
team_id = "VGS"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555935/xfl-prod/logos/logo-vegas-vipers-500x500.png":
team_id = "VGS"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-arlington-renegades-500x500.png":
team_id = "ARL"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555934/xfl-prod/logos/logo-arlington-renegades-500x500.png":
team_id = "ARL"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-dc-defenders-500x500.png":
team_id = "DC"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555934/xfl-prod/logos/logo-dc-defenders-500x500.png":
team_id = "DC"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100/v1671555934/xfl-prod/logos/logo-san-antonio-brahmas-500x500.png":
team_id = "SA"
case "https://res.cloudinary.com/xfl-production/image/upload/c_thumb,w_100,g_face/v1671555934/xfl-prod/logos/logo-san-antonio-brahmas-500x500.png":
team_id = "SA"
case "https://res.cloudinary.com/xfl-production/image/upload/v1698177464/xfl-prod/logos/logo-xfl-500x500.png":
team_id = "XFL"
case _:
raise ValueError(
f'Unhandled Team abreviation: {team_logo_url}')
row_df = pd.DataFrame(columns=['team_id', 'team_logo_url'], data=[
[team_id, team_logo_url]])
row_df['date'] = t_cells[1].text
row_df['player_name'] = t_cells[2].text
row_df['player_position'] = t_cells[3].text
row_df['transaction_type'] = t_cells[4].text
main_df = pd.concat([main_df, row_df], ignore_index=True)
print(main_df)
if save == True:
main_df.to_csv(
f'player_info/transactions/{season}_xfl_transactions.csv', index=False)
return main_df
if __name__ == "__main__":
get_xfl_transactions(save=True)