flask config untested, likely not working

This commit is contained in:
printfuck 2020-04-16 10:33:46 +02:00
parent 889ea50657
commit 7dd22d74af
2 changed files with 112 additions and 11 deletions

67
main.py
View file

@ -13,6 +13,8 @@ from cssselect import HTMLTranslator, SelectorError
import requests as req import requests as req
from io import StringIO from io import StringIO
import web
DB_HOST = "127.0.0.1" DB_HOST = "127.0.0.1"
DB_USER = "dbuser" DB_USER = "dbuser"
DB_PASSWD = "dbpasswd" DB_PASSWD = "dbpasswd"
@ -193,15 +195,15 @@ class lf:
def init_from_db(self): def init_from_db(self):
# Assumes it works # Assumes it works
self.url = self.query_db(self.db, "url") self.url = self.query_db("url")
self.password = self.query_db(self.db, "password") self.password = self.query_db("password")
self.username = self.query_db(self.db, "username") self.username = self.query_db("username")
self.selector = self.query_db(self.db, "selector") self.selector = self.query_db("selector")
self.selector_login_user = self.query_db(self.db, "selector_login_user") self.selector_login_user = self.query_db("selector_login_user")
self.selector_login_pass = self.query_db(self.db, "selector_login_pass") self.selector_login_pass = self.query_db("selector_login_pass")
self.selector_login_verify = self.query_db(self.db, "selector_login_verify") self.selector_login_verify = self.query_db("selector_login_verify")
self.selector_login_url = self.query_db(self.db, "selector_login_url") self.selector_login_url = self.query_db("selector_login_url")
self.selector_login_verify_url = self.query_db(self.db, "selector_login_verify_url") self.selector_login_verify_url = self.query_db("selector_login_verify_url")
def init_from_scratch( def init_from_scratch(
self, self,
@ -226,8 +228,8 @@ class lf:
self.selector_login_url = selector_login_url self.selector_login_url = selector_login_url
self.selector_login_verify_url = selector_login_verify_url self.selector_login_verify_url = selector_login_verify_url
def query_db(self, db, string): def query_db(self, string):
cursor = db.cursor() cursor = self.db.cursor()
cursor.execute(""" cursor.execute("""
SELECT {} FROM feeds SELECT {} FROM feeds
WHERE name = '{}' WHERE name = '{}'
@ -240,6 +242,49 @@ class lf:
else: else:
return "" return ""
def query_db(self, string, value):
cursor = self.db.cursor()
cursor.execute("""
UPDATE SET {}='{}' FROM feeds
WHERE name = '{}'
""".format(string,value,self.name)
)
cursor.close()
def write_db(self):
cursor = self.db.cursor()
cursor.execute("SELECT id FROM feeds WHERE name = '{}'".format(self.name))
if cursor.fetchone() is None:
cursor.execute("""
INSERT INTO {} (name, url, password, username,
selector, selector_login_user,selector_login_pass,
selector_login_verify,selector_login_url,
selector_login_verify_url)
VALUES ({},{},{},{},{},{},{},{},{},{},{})
""".format(
"feeds",self.name,self.url,self.password,
self.username,self.selector,
self.selector_login_user,self.selector_login_pass,
self.selector_login_verify,self.selector_login_url
self.selector_login_verify_url)
)
else:
cursor.execute("""
UPDATE feeds SET url = '{}', password = '{}', username = '{}',
selector = '{}', selector_login_user = '{}',selector_login_pass = '{}',
selector_login_verify = '{}',selector_login_url = '{}',
selector_login_verify_url = '{}')
VALUES ({},{},{},{},{},{},{},{},{})
""".format(
self.url,self.password,
self.username,self.selector,
self.selector_login_user,self.selector_login_pass,
self.selector_login_verify,self.selector_login_url
self.selector_login_verify_url)
)

56
web.py Normal file
View file

@ -0,0 +1,56 @@
#!/usr/bin/python
#
import main
from flask import Flask,request
app = Flask(__name__)
def run_flask(host,port)
app.run(host=host, port=port)
def getFeeds(db):
db = getDb()
cursor = db.cursor()
cusror.execute('''
SELECT name FROM feeds
''')
feeds = cursor.fetchall()
cursor.close()
return feeds
@app.route('/')
def list()
feeds = getFeeds()
a = "<html><body><p>Header</p><br><table><tr><td>Feeds</td></tr>"
for i in feeds:
a+= "<tr><td><a href='/configure?feed={}'>{}</a></td></tr>".format(i,i)
a+= "</table></body></html>"
return a
@app.route('/configure', methods = ['GET','POST'])
def configure(feed_name):
db = getDb()
feed = lf(db, feed_name)
if request.method == 'POST':
for k,v in request.form.items():
feed.query_db(k,v)
config_list = (
"url",
"password",
"username",
"selector",
"selector_login_user",
"selector_login_pass",
"selector_login_verify",
"selector_login_verify_url",
"selector_login_url")
a = '<html><body><form>'
for i in config_list:
a += '''
<label for="{}">{}</label><br>
<input type="text" value="{}" id="{}">
'''.format(i,i,feed.query_db(i),i)
a += "</form></body></html>