From 934c698f3ff5b004906224546c738b1e429c4f53 Mon Sep 17 00:00:00 2001 From: Camille Frantz Date: Wed, 20 Mar 2024 10:30:21 -0500 Subject: [PATCH] fully modularise quotesbot code for public consumption --- .gitignore | 1 + random_quotes.py | 8 +++++++- requirements.txt | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d17dae --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv diff --git a/random_quotes.py b/random_quotes.py index 147bafb..6f980c6 100644 --- a/random_quotes.py +++ b/random_quotes.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6fdb977 --- /dev/null +++ b/requirements.txt @@ -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