-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutls.py
71 lines (56 loc) · 1.89 KB
/
utls.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
from datetime import datetime
import requests
def get_json_from_url(url: str):
""" """
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)
if response.status_code == 200:
pass
elif response.status_code == 401:
raise ConnectionRefusedError(
f"Could not connect. The connection was refused.\nHTTP Status Code 401."
)
else:
raise ConnectionError(
f"Could not connect.\nHTTP Status code {response.status_code}"
)
json_data = response.json()
return json_data
def convert_numeric(value: str):
if "." in value:
try:
return float(value)
except ValueError as e:
print(f"Error: {e}")
else:
try:
return int(value)
except ValueError as e:
print(f"Error: {e}")
def get_latest_season_year():
curr_date = datetime.now()
curr_month = curr_date.month
season_start_month = 3
season_end_month = 10
latest_season_year = (
curr_date.year if curr_month >= season_start_month else curr_date.year - 1
)
return latest_season_year
def team_ids_list():
team_ids = {
"巨人": 1, # Yomiuri Giants
"ヤクルト": 2, # Tokyo YakultSwallows
"DeNA": 3, # Yokohama DeNA Bay Stars
"中日": 4, # Chunichi Dragons
"阪神": 5, # Hanshin Tigers
"広島": 6, # Hiroshima Toyo Carp
"西武": 7, # Saitama Seibu Lions
"日本ハム": 8, # Hokkaido Nippon-Ham Fighters
"ロッテ": 9, # Chiba Lotte Marines
"オリックス": 11, # Orix Buffaloes
"ソフトバンク": 12, # Fukuoka SoftBank Hawks
"楽天": 376, # Tohoku Rakuten Golden Eagles
}
return team_ids