Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:23:17+00:00 2026-06-11T10:23:17+00:00

I am accessing a api and extracting a json but I want to make

  • 0

I am accessing a api and extracting a json but I want to make sure I stay within the hourly request limit, what would be the best way to do this?

This where I make the request:

# return the json
def returnJSONQuestion(id):
    url = 'http://someApi.com?index_id={0}&output=json'
    format_url = url.format(id)
    try:
        urlobject = urllib2.urlopen(format_url)
        jsondata = json.loads(urlobject.read().decode("utf-8"))
        print jsondata
        shortRandomSleep()
    except urllib2.URLError, e:
        print e.reason
    except(json.decoder.JSONDecodeError,ValueError):
        print 'Decode JSON has failed'
    return jsondata
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:23:18+00:00Added an answer on June 11, 2026 at 10:23 am

    I usually use a cheap hack where I make the script run every other minute by checking the current time. This is the general form of the function:

    def minuteMod(x, p=0):
        import datetime
        minute = datetime.datetime.now() + datetime.timedelta(seconds=15)
        minute = int(datetime.datetime.strftime(minute, "%M"))
        if minute % x == p:
            return True
        return False
    

    p is the remainder here and has a default value of 0 so no particular need to pass in the second argument.

    So basically, if you want your script to run only every other minute, you use it like this:

    def returnJSONQuestion(id):
    
        if not minuteMod(2):
            return None or ''
    
        # rest of the code
    

    This will stop the request if the current minute is not even. Considering this is not the best way to do things, you can use this function to cache results (depending on if this is allowed). So basically, you would do something like this:

    def returnJSONQuestion(id):
    
        if minuteMod(3): # current minute is a factor of 3
            return jsonFromCache # open a file and output cached contents
        else:
            url = 'http://...'
            storeJSONToFile(url)
            return json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JQuery to make a JSON request to access data on a private
I'm parsing a JSON file that I'm retrieving by accessing an API. Right now,
I've had no trouble accessing the API documentation but now suddenly it shows a
I've the following problem: I'm accessing foursquares Venue API and get a JSON string
I'm implementing an API for a CMS. Clients are accessing the API via a
I am accessing an XML API (flight search comparison) via a PHP Proxy like
I am accessing wikipedia's api and getting information about a topic via ajax. The
I am using Twitterizer API for accessing twitter related functionality. I have one demo
How do these two pieces of code differ when accessing a REST API? $result
Suppose I write: new Meteor.Collection(foos); new Meteor.Collection(bars); Is there an API for accessing those

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.