-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgettotalgoals.py
60 lines (48 loc) · 1.66 KB
/
gettotalgoals.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
#!/bin/python3
import math
import os
import random
import re
import sys
import requests
#
# Complete the 'getTotalGoals' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. STRING team
# 2. INTEGER year
#
def getTotalGoals(team, year):
# Write your code here
c = 0
r=requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&team1='+str(team)+'&page=1').json()
total1=r['total_pages']
per2 = r['per_page']
for j in range(1,total1+1):
r = requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&team1='+str(team)+'&page='+str(j)).json()
try:
for i in range(0,per2):
team1 = r['data'][i]['team1goals']
c+=int(team1)
except:
pass
r1 =requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&team2='+str(team)+'&page=1').json()
total2=r1['total_pages']
per2=r1['per_page']
for j in range(1,total2+1):
r1 = requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&team2='+str(team)+'&page='+str(j)).json()
try:
for i in range(0,per2):
team2 = r1['data'][i]['team2goals']
c+=int(team2)
except:
pass
return c
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
team = input()
year = int(input().strip())
result = getTotalGoals(team, year)
fptr.write(str(result) + '\n')
fptr.close()