Remove unneeded files

This commit is contained in:
nukeop 2017-01-02 02:19:54 +01:00
parent ac09c9c8d8
commit d59733533b
3 changed files with 0 additions and 176 deletions

View file

@ -1,57 +0,0 @@
import sqlite3
class Database(object):
"""Interface to a local database that stores data for the website.
"""
def __init__(self, dbname):
self.dbname = dbname
@property
def conn(self):
return sqlite3.connect(self.dbname)
@property
def cursor(self):
return self.conn.cursor()
def select(self, table, fields, condition=None):
cur = self.cursor
if condition is not None:
cur.execute("SELECT {} FROM {} WHERE {}".format(fields, table,
condition))
else:
cur.execute("SELECT {} FROM {}".format(fields, table))
return cur.fetchall()
def create_table(self, table, cols):
conn = self.conn
cur = conn.cursor()
query = "CREATE TABLE {}({})".format(table, cols)
cur.execute(query)
conn.commit()
def insert(self, table, columns, values, params):
conn = self.conn
cur = conn.cursor()
query = "INSERT INTO {}({}) VALUES ({})".format(table, columns, values)
cur.execute(query, params)
conn.commit()
return cur
def delete(self, table, condition):
conn = self.conn
cur = conn.cursor()
query = "DELETE FROM {} WHERE {}".format(table, condition)
cur.execute(query)
conn.commit()

View file

@ -1,66 +0,0 @@
import os
import psycopg2
import urlparse
class DatabasePostgreSQL(object):
"""Interface to the heroku PostgreSQL database plugin.
"""
def __init__(self):
urlparse.uses_netloc.append("postgres")
self.url = urlparse.urlparse(os.environ["DATABASE_URL"])
@property
def conn(self):
return psycopg2.connect(
database=self.url.path[1:],
user=self.url.username,
password=self.url.password,
host=self.url.hostname,
port=self.url.port
)
@property
def cursor(self):
return self.conn.cursor()
def select(self, table, fields, condition=None):
cur = self.cursor
if condition is not None:
cur.execute("SELECT {} FROM {} WHERE {}".format(fields, table,
condition))
else:
cur.execute("SELECT {} FROM {}".format(fields, table))
return cur.fetchall()
def create_table(self, table, cols):
conn = self.conn
cur = conn.cursor()
query = "CREATE TABLE {}({})".format(table, cols)
cur.execute(query)
conn.commit()
def insert(self, table, columns, values, params):
conn = self.conn
cur = conn.cursor()
query = "INSERT INTO {}({}) VALUES ({})".format(table, columns, values)
cur.execute(query, params)
conn.commit()
return cur
def delete(self, table, condition):
conn = self.conn
cur = conn.cursor()
query = "DELETE FROM {} WHERE {}".format(table, condition)
cur.execute(query)
conn.commit()

View file

@ -1,53 +0,0 @@
class Model(object):
#Name of the table to be created
tablename = "abstractmodel"
#Attributes are tuples - attribute name, data type, other requirements
id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT")
class Quote(Model):
tablename = "quotes"
id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT")
rating = ("rating", "INTEGER", "NOT NULL")
content = ("content", "TEXT", "NOT NULL")
approved = ("approved", "BOOLEAN", "NOT NULL")
author_ip = ("author_ip", "TEXT", "NOT NULL")
time = ("time", "TEXT", "NOT NULL")
class Tag(Model):
tablename = "tags"
id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT")
name = ("name", "TEXT", "UNIQUE NOT NULL")
class TagsToQuotes(Model):
tablename = "tagsToQuotes"
id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT")
tag_id = ("tagid", "INTEGER", "NOT NULL")
quote_id = ("quoteid", "INTEGER", "NOT NULL")
def init_models(db):
import logging
logger = logging.getLogger(__name__)
for model in Model.__subclasses__():
columns = [x for x in model.__dict__ if '__' not in x and x !=
'tablename']
try:
db.create_table(
model.tablename,
','.join([' '.join(model.__dict__[x]) for x in columns])
)
logger.info("Created table in the database:"
" {}".format(model.tablename))
except:
#If we can't create a table here, it means it's already in the
#database, so we can skip it
pass