File: example_single.py

package info (click to toggle)
python-ratelimitqueue 0.2.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 180 kB
  • sloc: python: 463; makefile: 15
file content (22 lines) | stat: -rw-r--r-- 438 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Example: Make rate limited API calls in the main thread."""

import ratelimitqueue


def make_call_to_api(url):
    print("Calling:", url)


LIST_OF_URLS = ["https://example.com/{}".format(i) for i in range(25)]

rlq = ratelimitqueue.RateLimitQueue(calls=2, per=1)

# load up the queue
for url in LIST_OF_URLS:
    rlq.put(url)

# make the calls
while rlq.qsize() > 0:
    url = rlq.get()
    make_call_to_api(url)
    rlq.task_done()