The JokeBorrower as the name suggests steals cough I mean sources
for jokes from other APIs to be used by my jokesAPI by storing them to my heroku postgres database instance.
$ git clone https://github.com/DanNduati/Jokes_borrower.git
If you have pipenv installed you can just run pipenv automatically creates a virtual environment for you:
$ pipenv install
Otherwise you can use the good ol' requirements.txt file:
# create virtualenvironment and activate it
$ python -m venv venv
$ source venv/bin/activate
# install dependencies
$ pip install -r requirements.txt
Run source.sh bash script
$ ./source.sh
Borrowing initiated
started borrowing at id 0
62 jokes borrowed successfully in 1.219724178314209 seconds
started borrowing at id 100
81 jokes borrowed successfully in 2.874145269393921 seconds
started borrowing at id 200
76 jokes borrowed successfully in 1.8248345851898193 seconds
All done
$ sudo chmod +x source.sh
$ ./source.sh
Borrowing initiated
started borrowing at id 0
62 jokes borrowed successfully in 34.831594467163086 seconds
started borrowing at id 100
81 jokes borrowed successfully in 43.83061122894287 seconds
started borrowing at id 200
76 jokes borrowed successfully in 41.592899322509766 seconds
All done
For obvious reasons writing to the local sqlite database is significantly faster that writing to the free tier postgres database instance
- aiohttp - an asynchronous HTTP Client/Server
- Tortoise orm - an asyncio ORM
JokesBorrower sources it jokes from this API created by Sven Fehler
- Throttle requests to avoid exceeding the request budget for rate limited APIs
- Add other joke sources/Apis