Commit 7ab27fd9 authored by Rien's avatar Rien

Add quote import script

parent 8f5a6a63
......@@ -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()))
......@@ -33,12 +33,15 @@ class Quote(db.Model):
def __repr__(self):
return "<Quote {} \"{}\">".format(self.quoter, self.quote)
def __init__(self, quoter, quote, channel):
def __init__(self, quoter, quote, channel, created_at=None):
self.quoter = quoter
self.quote = quote = channel
self.created_at = datetime.utcnow()
if created_at is None:
self.created_at = datetime.utcnow()
self.created_at = created_at
# Experimentally try to find quoted user
quotee_match =
self.quotee = if quotee_match is not None else None
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__)
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"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment