diff --git a/.gitignore b/.gitignore index 7356d8a..5d4fca2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ env/ /dist/ /warren/__pycache__/ /.tox/ +*.db diff --git a/warren/__init__.py b/warren/__init__.py new file mode 100644 index 0000000..df33f45 --- /dev/null +++ b/warren/__init__.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +"""Part of the Weir project. +This will listen on two endpoints, and when data is +posted to the proper one, matching a particular format, +it will save that data to a local sqlite3 db.""" + +import logging +import warren +from flask import Flask, redirect, url_for, request + +__version__ = "0.1.0" + +logging.basicConfig(level=logging.DEBUG) +dbpath = "warren.db" +app = Flask(__name__) + +@app.route('/') +def test(): + return 'the website is up you little bitch' + + +@app.route('/weir',methods = ['POST']) +def weir(): + """""" + try: + python_dict = request.get_json() + warren.write_to_db(python_dict, "warren.db") + return "OK" + except: + return "Error.", 400 + + +if __name__ == '__main__': + app.run(debug = True) diff --git a/warren.py b/warren/warren.py similarity index 70% rename from warren.py rename to warren/warren.py index 565b665..139bce1 100644 --- a/warren.py +++ b/warren/warren.py @@ -1,28 +1,18 @@ #!/usr/bin/env python -"""Part of the Weir project. -This will listen on two endpoints, and when data is -posted to the proper one, matching a particular format, -it will save that data to a local sqlite3 db.""" +"""Part of the Weir project.""" -__version__ = "0.1.0" - -from datetime import datetime import logging +from datetime import datetime import os from pathlib import Path -from flask import Flask, redirect, url_for, request + import json import sqlite3 import pdb -logging.basicConfig(level=logging.DEBUG) -dbpath = "warren.db" -app = Flask(__name__) - - def parse_incoming_post(body): """given a body of a request, convert it from json to pydict""" json_dict = json.loads(body) @@ -76,27 +66,6 @@ def write_to_db(data, dbpath): sql_inputs = [(right_now, data['hostname'], data['metadata'])] cur.executemany("INSERT INTO weir VALUES (?,?,?)", sql_inputs) conn.commit() - logging.INFO(cur.lastrowid) # always make sure to close db connection after you're done conn.close() - - -@app.route('/') -def test(): - return 'the website is up you little bitch' - - -@app.route('/weir',methods = ['POST']) -def weir(): - """""" - try: - python_dict = request.get_json() - write_to_db(python_dict, "warren.db") - return "OK" - except: - return "Error.", 400 - - -if __name__ == '__main__': - app.run(debug = True)