Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
.idea
27 changes: 27 additions & 0 deletions inventory_data.sql
Original file line number Diff line number Diff line change
@@ -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);
48 changes: 48 additions & 0 deletions src/beerapi.py
Original file line number Diff line number Diff line change
@@ -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()
27 changes: 27 additions & 0 deletions src/inventory_data.sql
Original file line number Diff line number Diff line change
@@ -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);