diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e58e5a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.idea diff --git a/inventory_data.sql b/inventory_data.sql new file mode 100644 index 0000000..5d891cc --- /dev/null +++ b/inventory_data.sql @@ -0,0 +1,27 @@ +DROP DATABASE inventory_data; + +CREATE DATABASE inventory_data; + +USE inventory_data; + +CREATE TABLE inventory( + beerID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(500), + containers_per_pack INT, + container_size VARCHAR(200), + container_type VARCHAR(100), + category VARCHAR(200), + packs_per_case INT; +) + +CREATE TABLE purchasing_details( + dt DATETIME DEFAULT CURRENT_TIMESTAMP, + quantity_available FLOAT, + retail_price FLOAT, + case_retail_price FLOAT, + id INT NOT NULL FOREIGN KEY REFERENCES Inventory(beerID); +) + +-- Rename fields +CREATE INDEX DATETIME_INDEX +ON Inventory_availability(dt); diff --git a/src/beerapi.py b/src/beerapi.py new file mode 100644 index 0000000..0a80783 --- /dev/null +++ b/src/beerapi.py @@ -0,0 +1,48 @@ +import requests +import datetime +import time +import logging + +def write_beer_inventory(): + """ + Retrieves inventory data from Tanczos and writes to file locally + + Input: + Parameterless + + Output: + Returns void + """ + beer_inventory = requests.get('http://www.tanczos.com/tanczos.com/beerinventory/webexport.csv') + filename = str(datetime.datetime.now()).replace(' ', '_') + '.csv' + with open(filename, "w+") as beer_inventory_file: + beer_inventory_file.write(beer_inventory.text) + +def run(): + """ + Runs write_beer_inventory every 20 minutes + + Input: + Parameterless + + Output: + Returns void + + Raises: + Exception + When unable to fetch file, logs error and passes + """ + + while True: + try: + write_beer_inventory() + logging.info('The data was fetched successfully!') + + except: + logging.exception('Failed to fetch file:') + pass + time.sleep(1200) + +if __name__ == "__main__": + logging.basicConfig(filename='test.log', level=logging.INFO, format='%(asctime)s:%(message)s') + run() \ No newline at end of file diff --git a/src/inventory_data.sql b/src/inventory_data.sql new file mode 100644 index 0000000..2286452 --- /dev/null +++ b/src/inventory_data.sql @@ -0,0 +1,27 @@ +DROP DATABASE inventory_data; + +CREATE DATABASE inventory_data; + +USE inventory_data; + +CREATE TABLE inventory( + beerID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(500), + containers_per_pack INT, + container_size VARCHAR(200), + container_type VARCHAR(100), + category VARCHAR(200), + packs_per_case INT; +) + +CREATE TABLE purchasing_details( + dt DATETIME DEFAULT, + quantity_available FLOAT, + retail_price FLOAT, + case_retail_price FLOAT, + id INT NOT NULL FOREIGN KEY REFERENCES Inventory(beerID); +) + +-- Rename fields +CREATE INDEX DATETIME_INDEX +ON Inventory_availability(dt);