-2

I'm writing a web app that requires an objective source of time "atomic clock or otherwise" to deal with API rate limits that reset every 15 minutes.

Is there a python library out there for this task or should I try scraping a webpage or what?

EDIT: I'm sorry for not being philosophically clear about "objective." I just meant a website that offers a reasonably accurate source of time, instead of my computer or otherwise, that's accurate within a minute or two.

Josh Usre
  • 674
  • 1
  • 12
  • 35
  • 1
    What is "objective" time and how much accuracy do you need? – NPE Feb 12 '15 at 19:17
  • Einstein said that there is no such thing as objective time. You probably need high resolution time, but it is very hard to achieve (and not a task for Python of course). Advise: instead of buying atomic clock, use GPS receivers (all GPS satellites have own atomic clock). – myaut Feb 12 '15 at 19:18
  • 1
    You don't need atomic time for some event that repeats every couple of minutes. Do you need real time (wall clock but can drift eg. due to DST) or monotonic time (increases steadily but has no relation to wall clock)? – StenSoft Feb 12 '15 at 19:20
  • Wall time. The API resets once every 15 minutes. Within ~15 seconds accuracy but I'm flexible. – Josh Usre Feb 12 '15 at 19:49

2 Answers2

1

What makes you think that the site you are scraping also uses "objective time"?

I suggest you slow your request rate to something like 5% below the stated limit.

That should give enough leeway that a low-resolution "non-objective" timer will keep you out of trouble.

Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
  • Relatively objective time. Sorry for not being completely clear. I get from the down votes that my plan is a "bad idea" and will try out your suggestion. Thanks. – Josh Usre Feb 12 '15 at 19:44
1

Wall time. The API resets once every 15 minutes. Within ~15 seconds accuracy but I'm flexible.

You could use time.monotonic():

Return the value (in fractional seconds) of a monotonic clock, i.e. a clock that cannot go backwards. The clock is not affected by system clock updates. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.

You could call start = time.monotonic() every 15 minutes. The difference time.monotonic() - start is the elapsed time measured well within 15 seconds tolerance.

PEP 418: Add monotonic time, performance counter, and process time functions mentions what hardware clocks are typically available and the properties of the corresponding OS time functions.

You could implement time.monotonic() on Python 2.7 if necessary.

Community
  • 1
  • 1
jfs
  • 399,953
  • 195
  • 994
  • 1,670