-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-games.py
122 lines (110 loc) · 2.86 KB
/
add-games.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
import pandas as pd
import requests
def getTeamId(teamName):
teams = [
{
"teamId": "65fd15627f6bf13de4d6688f",
"fullName": "Chennai Super Kings",
"shortName": "CSK",
"colorCode": "#FCCA06"
},
{
"teamId": "65fd15627f6bf13de4d66892",
"fullName": "Delhi Capitals",
"shortName": "DC",
"colorCode": "#0078BC"
},
{
"teamId": "65fd15627f6bf13de4d66895",
"fullName": "Gujarat Titans",
"shortName": "GT",
"colorCode": "#315079"
},
{
"teamId": "65fd15627f6bf13de4d66898",
"fullName": "Kolkata Knight Riders",
"shortName": "KKR",
"colorCode": "#3B215D"
},
{
"teamId": "65fd15627f6bf13de4d6689b",
"fullName": "Lucknow Super Giants",
"shortName": "LSG",
"colorCode": "#D6296E"
},
{
"teamId": "65fd15637f6bf13de4d6689e",
"fullName": "Mumbai Indians",
"shortName": "MI",
"colorCode": "#006CB7"
},
{
"teamId": "65fd15637f6bf13de4d668a1",
"fullName": "Punjab Kings",
"shortName": "PBKS",
"colorCode": "#D71920"
},
{
"teamId": "65fd15637f6bf13de4d668a4",
"fullName": "Rajasthan Royals",
"shortName": "RR",
"colorCode": "#EA1A85"
},
{
"teamId": "65fd15637f6bf13de4d668a7",
"fullName": "Royal Challengers Bengaluru",
"shortName": "RCB",
"colorCode": "#84171B"
},
{
"teamId": "65fd15637f6bf13de4d668aa",
"fullName": "Sunrisers Hyderabad",
"shortName": "SRH",
"colorCode": "#F26522"
}
]
for obj in teams:
if obj['fullName'] == teamName:
return obj['teamId']
def setTeams(row):
arr = row['Match'].split(" vs ")
print(arr)
row['Team 1'] = getTeamId(arr[0])
row['Team 2'] = getTeamId(arr[1])
return row
def getStartTime(row):
arr = row['Month']
month = "03"
if arr == "Apr":
month = "04"
elif arr == "May":
month = "05"
date = str(row['Date'])
if len(date) == 1:
date = "0" + date
time = "14:00"
if row['Time (IST)'] == "15:30":
time = "10:00"
row['Start Time'] = "2024-" + month + "-" + date + "T" + time + ":00.000Z"
return row
def updateDB(row):
body = {
'gameNumber': row['No'],
'team1': row['Team 1'],
'team2': row['Team 2'],
'startTime': row['Start Time'],
}
print(body)
r = requests.post('http://localhost:8000/game/add', data=body)
print (r.text, row['No'])
file = open("ipl 2024.csv")
df = pd.read_csv(file)
df['Team 1'] = ""
df['Team 2'] = ""
df = df.apply(lambda x: setTeams(x), axis='columns')
df['Start Time'] = ""
df = df.apply(lambda x: getStartTime(x), axis='columns')
# df['Match No'] = df['Match No'] + 100
df = df[['No', 'Team 1', 'Team 2', 'Start Time']]
print (df)
df.apply(lambda x: updateDB(x), axis='columns')