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
The task is to get the number of matches for a given year that ended in a draw. A match is drawn when both teams scored the same number of goals. To access a collection of matches played in a given year, perform an HTTP GET request to · ...
Author aashahin
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.
Videos
19:47
Hacker Rank REST API Certification #3 - YouTube
48:05
HackerRank Skills Certification | Rest API (Intermediate) Certificate ...
Doing the Rest API Intermediate | NodeJS - HackerRank ...
08:22
HackerRank API Interview Question and Answer - YouTube
Rest API (intermediate) solution Hackerrank certificate free Vedio ...
GitHub
github.com › saro-mano › Hackerrank-Rest-API
GitHub - saro-mano/Hackerrank-Rest-API: Solution for Hackerrank REST API Certification · GitHub
Starred by 14 users
Forked by 9 users
Languages Python
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
Solutions for React API Hackerrank certification problems in Python - React-API-Intermediate-Hackerrank/(REST API) Number of Drawn Matches.py at master · Harika-BV/React-API-Intermediate-Hackerrank
Author Harika-BV
LinkedIn
linkedin.com › posts › sakhi-chatterjee_rest-api-intermediate-activity-7354928247526092801-F_M_
Solved REST API challenges on HackerRank using Python
We cannot provide a description for this page right now
Brainly
brainly.in › computer science › secondary school
REST API: Number of Drawn Matches In this challenge, the REST API contains information about football - Brainly.in
November 4, 2024 - This solution efficiently utilizes the API's filtering capability to avoid examining individual match objects, ensuring a timely response.
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 - import requests import json team = 'Barcelona' year = 2011 goals = 0 for tm in ['team1', 'team2']: url = 'jsonmock.hackerrank/api/football_matches?year=' +str(year)+ '&' +tm+ '=' +team+ '&page=1' response = requests('GET', url, headers={}, data={}) total_pages = json(response.text('utf8'))['total_pages'] for i in range(1, total_pages+1): url = 'jsonmock.hackerrank/api/football_matches?year=' +str(year)+ '&' +tm+ '=' +team+ '&page=' +str(i) response = requests('GET', url, headers={}, data={}) r = json(response.text('utf8')) r_data = r['data'] for record in r_data: goals += int(record[tm+'goals']) goals
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 › sumantopal07 › Rest-API-Intermediate-Hackerrank-Test
GitHub - sumantopal07/Rest-API-Intermediate-Hackerrank-Test · GitHub
Solution : Only done with 10 GET requests by taking advantage of the constraint of maximum of 10 goals scored by any team. const fetch = require("node-fetch"); let goals=[]; for(let i=0;i<=10;i++) goals.push(i); let ans=0; async function ...
Starred by 36 users
Forked by 8 users
YouTube
youtube.com › watch
REST API Intermediate Certification #03 - YouTube
HackerRank All skills certifications Github Link https://github.com/tkssharma/hackerrank-full-stack/tree/master/Full Stack Certifications- https://github...
Published December 13, 2021
GitHub
github.com › Reterics › -Hackerrank-Rest-API
GitHub - Reterics/-Hackerrank-Rest-API: Javascript Solution for Hackerrank Intermediate 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
Unm
unm.ge › tags › 7c8b39-rest-api-number-of-drawn-matches-hackerrank-solution
rest api number of drawn matches hackerrank solution
APIs work in much the same way except instead of the web browser asking for a webpage, the program asks for data. Python Conditional: Exercise-10 with Solution. On the HackerRank Coding environment, most of your programs require to read input and write the output using the Standard Input stream ...
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 › 3RB16 › Rest-API-Intermediate-hackerrank-solution › blob › main › getWinnerTotalGoals.py
Rest-API-Intermediate-hackerrank-solution/getWinnerTotalGoals.py at main · 3RB16/Rest-API-Intermediate-hackerrank-solution
Rest-API-Intermediate-hackerrank-solution. Contribute to 3RB16/Rest-API-Intermediate-hackerrank-solution development by creating an account on GitHub.
Author 3RB16
YouTube
youtube.com › watch
Hackerrank Certification REST APIs Certification (Football matches APIs) #hackerrank - YouTube
This Video is a part of playlist "Crack javascript Interviews"https://www.youtube.com/watch?v=ET3IiPLI-JI&list=PLIGDNOJWiL18kcjnrT0KT64bo-kOYyQUF&ab_channel=...
Published May 16, 2023
HackerRank
hackerrank.com › skills-verification › rest_api_intermediate
Rest API Intermediate Certificate
Proficiency in MySQL, a critical aspect of database management, is evaluated through database design, SQL queries, normalization, and optimization techniques. Additionally, expertise in REST APIs, vital for modern web applications, is assessed in terms of RESTful principles, HTTP methods, authentication, and API design best practices.
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.md · View all files · This repo is not for cheating! hackerrank problem-solving · Activity · 1 star · 1 watching · 1 fork · Report repository · No releases published · No packages published ·
Author aashahin