diff --git a/app/app.py b/app/app.py index 53f1380..4b0447c 100644 --- a/app/app.py +++ b/app/app.py @@ -150,4 +150,4 @@ def add_quote(): @app.route('/', methods=['GET']) def list_quotes(): - return render_template('quotes.html', quotes = models.Quote.query.all()) + return render_template('quotes.html', quotes = reversed(models.Quote.query.all())) diff --git a/app/models.py b/app/models.py index 99a7808..6971e7a 100644 --- a/app/models.py +++ b/app/models.py @@ -33,12 +33,15 @@ class Quote(db.Model): def __repr__(self): return "".format(self.quoter, self.quote) - def __init__(self, quoter, quote, channel): + def __init__(self, quoter, quote, channel, created_at=None): super() self.quoter = quoter self.quote = quote self.channel = channel - self.created_at = datetime.utcnow() + if created_at is None: + self.created_at = datetime.utcnow() + else: + self.created_at = created_at # Experimentally try to find quoted user quotee_match = Quote.QUOTEE_REGEX.search(quote) self.quotee = quotee_match.group(1) if quotee_match is not None else None diff --git a/import_quotes.py b/import_quotes.py new file mode 100644 index 0000000..aae2e1e --- /dev/null +++ b/import_quotes.py @@ -0,0 +1,20 @@ +from flask import Flask, request, Response, abort, render_template +from flask_sqlalchemy import SQLAlchemy +from flask_migrate import Migrate +from app import models +from datetime import datetime +import config + + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_URL +db = SQLAlchemy(app) + +for line in open('quotes.tsv'): + split = line.split("\t") + assert len(split) == 4, "Too much tabs at line \"{}\", {}".format(line, len(split)) + quoter, channel, quote_text, created_at = split + quote = models.Quote(quoter, quote_text, channel, created_at = datetime.strptime(created_at.strip(), "%Y-%m-%d %H:%M:%S")) + db.session.add(quote) +db.session.commit() +