fully modularise quotesbot code for public consumption

This commit is contained in:
Camille Frantz 2024-03-20 10:30:21 -05:00
parent 7a9a41ccc9
commit 934c698f3f
Signed by: fyrfli
SSH Key Fingerprint: SHA256:cyNGncrLxKXAgYC96dYNROnQKikLInzrpiMraZdqyhY
3 changed files with 14 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.venv

View File

@ -3,8 +3,10 @@ from dotenv import load_dotenv
from os import getenv
from random import randint
from requests import get, post
from sys import argv
def load_env():
load_dotenv()
api_key = getenv('QUOTES_ACCESS_TOKEN')
quotes_library = getenv('QUOTES_LIBRARY')
if quotes_library.startswith('https',0):
@ -40,6 +42,10 @@ def make_post(headers, payload):
print('An error occurred: ', e)
if __name__ == '__main__':
if len(argv) > 0:
choice = int(argv[1])
else:
choice = int(0)
api_key, quote_file = load_env()
headers, payload = build_post(api_key, quote_file)
headers, payload = build_post(api_key, quote_file, choice)
make_post(headers, payload)

6
requirements.txt Normal file
View File

@ -0,0 +1,6 @@
certifi==2024.2.2
charset-normalizer==3.3.2
idna==3.6
python-dotenv==1.0.1
requests==2.31.0
urllib3==2.2.1