Split out program into init, module files.

I'm REALLY not sure this is how its supposed to be done.
Trying some stuff to get the supporting cast of tooling to work.
master
josiah 3 years ago
parent 0c37276d11
commit 20f44c8a8f

1
.gitignore vendored

@ -2,3 +2,4 @@ env/
/dist/
/warren/__pycache__/
/.tox/
*.db

@ -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)

@ -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)