If the API allows these many calls, you can use a multiprocessing.pool.Pool function and iterate through each page parallelly to reduce time. This should work:
Copyimport requests
from functools import partial
from multiprocessing.pool import Pool
def loop(page,year,r,per_page):
r = requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&page='+str(page)).json()
try:
for i in range(0, per_page):
if int(r['data'][i]['team1goals']) == int(r['data'][i]['team2goals']):
increase = 1
else:
increase = 0
except:
increase = 0
return increase
if __name__ == "__main__":
year = 2011
draw = []
r = requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&page=1').json()
total_pages = r['total_pages']
per_page = r['per_page']
pages = range(1, total_pages+1)
pool = Pool()
f = pool.map(partial(loop,year=year,r=r,per_page=per_page),pages)
draw += f
final = 0
for x in draw:
x = int(x)
final += x
print(final) #516
Answer from Prateek Jain on Stack OverflowGitHub
github.com › aashahin › HackerRank-Certification-REST-API › blob › main › 2. REST API: Number of Drawn Matches.md
HackerRank-Certification-REST-API/2. REST API: Number of Drawn Matches.md at main · aashahin/HackerRank-Certification-REST-API
returns data associated with matches ... getNumDraws in the editor below. ... The function must return an integer denoting the number of matches in the given year that ended up in a draw....
Author aashahin
GitHub
github.com › Reterics › -Hackerrank-Rest-API
GitHub - Reterics/-Hackerrank-Rest-API: Javascript Solution for Hackerrank Intermediate Rest API
This repository includes solutions for 1. REST API: Total Goals by a Team, and 1. REST API: Number of Drawn Matches exam tasks.
Author Reterics
Top answer 1 of 3
2
If the API allows these many calls, you can use a multiprocessing.pool.Pool function and iterate through each page parallelly to reduce time. This should work:
Copyimport requests
from functools import partial
from multiprocessing.pool import Pool
def loop(page,year,r,per_page):
r = requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&page='+str(page)).json()
try:
for i in range(0, per_page):
if int(r['data'][i]['team1goals']) == int(r['data'][i]['team2goals']):
increase = 1
else:
increase = 0
except:
increase = 0
return increase
if __name__ == "__main__":
year = 2011
draw = []
r = requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&page=1').json()
total_pages = r['total_pages']
per_page = r['per_page']
pages = range(1, total_pages+1)
pool = Pool()
f = pool.map(partial(loop,year=year,r=r,per_page=per_page),pages)
draw += f
final = 0
for x in draw:
x = int(x)
final += x
print(final) #516
2 of 3
2
You should use multithreading and make multiple requests in parallel.
GitHub
github.com › shashi94310 › Hackerrank-Rest-Api › blob › main › Rest Api: Number of Drawn Matches
Hackerrank-Rest-Api/Rest Api: Number of Drawn Matches at main · shashi94310/Hackerrank-Rest-Api
url="https://jsonmock.hackerrank.com/api/football_matches?year="+str(year)+"&team1goals="+str(i)+"&team2goals="+str(i)
Author shashi94310
GitHub
github.com › Harika-BV › React-API-Intermediate-Hackerrank › blob › master › (REST API) Number of Drawn Matches.py
React-API-Intermediate-Hackerrank/(REST API) Number of Drawn Matches.py at master · Harika-BV/React-API-Intermediate-Hackerrank
search_url_find_page = "https://jsonmock.hackerrank.com/api/football_matches?year="+str(year)+"&team1goals="+str(i)+"&team2goals="+str(i)+"&page=1"
Author Harika-BV
GitHub
github.com › aashahin › HackerRank-Certification-REST-API
GitHub - aashahin/HackerRank-Certification-REST-API: This repo is not for cheating!
2. REST API: Number of Drawn Matches.js · 2. REST API: Number of Drawn Matches.js · 2. REST API: Number of Drawn Matches.md · 2. REST API: Number of Drawn Matches.md · View all files · This repo is not for cheating! hackerrank problem-solving · Activity · 1 star ·
Author aashahin
GitHub
github.com › Neelam099 › Hackerrank-Rest-API-INTERMEDIATE-API-SOLVE
GitHub - Neelam099/Hackerrank-Rest-API-INTERMEDIATE-API-SOLVE: Hackerrank-Rest-API Javascript Solution for Hackerrank Intermediate Rest API This repository includes solutions for 1. REST API: Total Goals by a Team, and 1. REST API: Number of Drawn Matches exam tasks. I copied my codes, and i didn't modify/upgrade in order to represent the real circumstances. · GitHub
Hackerrank-Rest-API Javascript Solution for Hackerrank Intermediate Rest API This repository includes solutions for 1. REST API: Total Goals by a Team, and 1. REST API: Number of Drawn Matches exam tasks. I copied my codes, and i didn't modify/upgrade in order to represent the real circumstances.
Author Neelam099
Kamadotech
kamadotech.com › 2rax5w › hackerrank-rest-api-number-of-drawn-matches-48218c
hackerrank rest api number of drawn matches
To get matched expression a HackerRank 1 hour challenge on HackerRank share,! Site where you can test your programming skills and learn something New in many domains a hard time to,! From a company who wants me to take a one hour challenge we added improved screening we got number. Diagonal Difference HackerRank solution in C, C++ hackerrank rest api number of drawn matches and snippets lightweight web services that conform to user!
GitHub
github.com › kaarthikraajan › rest-api-hackerrank
GitHub - kaarthikraajan/rest-api-hackerrank: This is a solution to the problem presented in the hackerrank problem.
This is a solution to the problem presented in the hackerrank problem. - kaarthikraajan/rest-api-hackerrank
Starred by 6 users
Forked by 2 users
Languages Java 100.0% | Java 100.0%
Studocu
studocu.com › jadavpur university › information and coding theory › rest api timed assessment challenge: team goals & draw analysis
REST API Timed Assessment Challenge: Team Goals & Draw Analysis - Studocu
September 7, 2024 - url = 'jsonmock.hackerrank/api/football_matches?year=' +str(year)+ '&team2=' +team+ '&page=1' response = requests('GET', url, headers={}, data={}) r = json(response.text('utf8')) r {'page': '1', 'per_page': 10, 'total': 6, 'total_pages': 1, 'data': [{'competition': 'UEFA Champions League', 'year': 2011, 'round': 'GroupH', 'team1': 'BATE Borisov', 'team2': 'Barcelona', 'team1goals': '0', 'team2goals': '5'}, {'competition': 'UEFA Champions League', 'year': 2011, 'round': 'GroupH', 'team1': 'Viktoria Plzen', 'team2': 'Barcelona', 'team1goals': '0', 'team2goals': '4'}, {'competition': 'UEFA Champi
Ezsoftpk
codepoint.ezsoftpk.com › qac96l › igvrl.php
Rest api number of drawn matches hackerrank solution in java
I guess because their main product is a payments API, they can hyper-optimize for candidates that are good at backend. WebSocket is a new protocol in HTML5. Specify the product version when the Java name was added to the API specification (if different from the implementation). We can either name it only Get or with any suffix. hackerrank rest api number of drawn matches.
Unm
unm.ge › tags › 7c8b39-rest-api-number-of-drawn-matches-hackerrank-solution
rest api number of drawn matches hackerrank solution
If-Match. This allows WC data to be created, read, updated, and deleted using requests in JSON format and using WordPress REST API Authentication methods and standard HTTP … In this case, Microsoft Flow will serve as an integration glue between your application and large number of other services.
API-Football
api-football.com
API-Football - Restful API for Football data
Restful API for Football data +1 200 competitions, Livescore, standings, teams, odds, bookmakers, fixtures, events, line-ups, players, statistics, predictions, widgets
CodeSandbox
codesandbox.io › s › hackerrank-rest-api-exercise-1-solution-6so4m0
Hackerrank rest api exercise 1 solution - CodeSandbox
August 16, 2022 - Hackerrank rest api exercise 1 solution by claurennt using @xioo/xios, axios, react, react-dom, react-scripts
GitHub
github.com › devreena03 › hackerrank-restapi-java › blob › main › football-matches.md
hackerrank-restapi-java/football-matches.md at main · devreena03/hackerrank-restapi-java
To access collection of match perform GET request https://jsonmock.hackerrank.com/api/football_matches?year=<year>&team1=<team>&page=<page> and https://jsonmock.hackerrank.com/api/football_matches?year=<year>&team2=<team>&page=<page> <year>: year of competition · <team>: name of team · <page>: page number of request ·
Author devreena03