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 Overflow
🌐
GitHub
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
🌐
Gitbook
dailyjournal.gitbook.io › solutions › hackerrank-solutions › certify › rest-api-intermediate
Rest API (Intermediate) | HackerRank | Solutions
The function must return an integer denoting the number of matches in the given year that ended up in a draw. You can safely assume that no team ever scored more than 10 goals. ... Explanation The year is 2011.
Top answer
1 of 1
4

https.get is a callbacked function so await won't work. You should promisify it first like they did in this other SO question;

const https = require("https");                                      // only require this once

const getJSONAsync = url => new Promise((resolve, reject) => {       // define a function getJSONAsync which returns a Promise that wraps the https.get call, getJSONAsync is awaitable
  let req = https.get(url, res => {                                  // make the https.get request
    if(res.statusCode < 200 || res.statusCode >= 300) {              // if the status code is an error one
      return reject(new Error('statusCode=' + res.statusCode));      // reject and skip the rest
    }

    let body = [];                                                   // otherwise accumulate..
    res.on('data', chunk => body.push(chunk));                       // ..the data
    res.on('end', () => {                                            // on end                               
      try {
        body = JSON.parse(Buffer.concat(body).toString());           // try to JSON.parse the data
      } catch(e) {
        reject(e);                                                   // reject if an error occurs
      }
      resolve(body);                                                 // resolve the parsed json object otherwise
    });
  });

  req.on("error", error => reject(error));                           // reject if the request fails too (if something went wrong before the request is sent for example)
});

async function getNumDraws(year) {
  let result = 0;

  for(let goal = 0; goal < 11; goal++) {
    let data = await getJSONAsync(`https://jsonmock.hackerrank.com/api/football_matches?year=${year}&team1goals=${goal}&team2goals=${goal}`);
    result += data.total;
  }

  return result;
}

Note: getJSONAsync is not specific to getNumDraws, you can use it somewhere else if you need it, and since it returns a Promise you can either await it like getNumDraws does or use it with then/catch blocks like so:

getJSONAsync("url")
  .then(data => {
    // data is the parsed json returned by the request
  })
  .catch(error => {
    // the error message if something fails
  })
🌐
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
Find elsewhere
🌐
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
Published   Aug 01, 2022
Author   claurennt
🌐
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