This commit is contained in:
Ultra Desu
2018-10-27 16:11:48 +03:00
commit 8404b990b0
4 changed files with 87 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
main.db

34
database.py Normal file
View File

@ -0,0 +1,34 @@
class DataBase:
def __init__(self, basefile):
import sqlite3
import datetime as dt
import logging
self.log = logging.getLogger("pycrm." + __name__)
try:
self.conn = sqlite3.connect(
basefile,
check_same_thread=False)
except:
self.log.info('Could not connect to DataBase.')
return None
def execute(self, sql):
cursor = self.conn.cursor()
cursor.execute(sql)
self.conn.commit()
return cursor.fetchall()
def save_word(self, word):
sql = "INSERT OR IGNORE INTO word('word') \
VALUES ('%s')" % word
self.execute(sql)
sql = "SELECT id FROM word WHERE word = '%s'" % word
return(self.execute(sql)[0][0])
def get_memes(self, offset=0):
sql = "SELECT * FROM `meme` ORDER BY rowid DESC "
return(self.execute(sql))
def close(self):
self.conn.close()

43
index.py Normal file
View File

@ -0,0 +1,43 @@
import passlib
#import sqlite3
import logging
from flask import Flask, request, send_from_directory
from flask import render_template
from database import DataBase
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
log = logging.getLogger("pycrm." + __name__)
try:
from settings import *
except:
log.warning("You should have to create settings.py \
file. Look into settings.py-example")
import sys
sys.exit(1)
app = Flask(__name__, static_url_path='')
db = DataBase(db_location)
# serve memes
#@app.route('/meme/<path:path>')
#def send_meme(path):
# return send_from_directory('meme', path)
# serve static
@app.route('/static/<path:path>')
def serve_static(path):
return send_from_directory('static', path)
@app.route('/')
def index():
return render_template('index.html')
def main():
app.run(host=flask_host, port=flask_port)
if __name__ == '__main__':
main()

8
settings.py Normal file
View File

@ -0,0 +1,8 @@
# database confs
db_location = './main.db'
#db_scheme = './misc/pypadla.db.sql'
# flask config
flask_host = '0.0.0.0'
flask_port = 8080