예제 #1
0
def create_db():
    """Create the Wiki database if there is none."""

    con = None
    con = connect(user='******')

    dbname = "wiki"

    con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
    cur = con.cursor()
    cur.execute('CREATE DATABASE ' + dbname)
    cur.close()
    con.close()

    connection = postgres.Connection('postgres', 'wiki')

    connection.non_query('CREATE TABLE article ('
                         '   name TEXT PRIMARY KEY,'
                         '   last_crawled TIMESTAMP,'
                         '   assigned_crawler_id UUID,'
                         '   assigned_crawler_time TIMESTAMP'
                         ');')

    connection.non_query(
        'CREATE UNIQUE INDEX name_id ON article (lower(name));')

    connection.non_query(
        'CREATE TABLE link ('
        '   from_article TEXT REFERENCES article (name),'
        '   to_article TEXT,'
        '   CONSTRAINT u_constraint UNIQUE (from_article, to_article)'
        ');')

    connection.non_query('INSERT INTO article (name) VALUES (\'Foobar\');')
def main():

    logging.basicConfig()
    db = postgres.Connection()
    tc = tweets.Classifier()
    model = joblib.load('./models/price_pipeline.pkl')

    start_scheduler(db, tc, model)
def main():

    logging.basicConfig()
    db = postgres.Connection()
    tc = tweets.Classifier()
    start_scheduler(db, tc)
예제 #4
0
"""The Flask server responsible with the database connection and data transmission.
"""

import json
import collections
from flask import Flask, render_template
from flask_cors import CORS
import postgres

APP = Flask(__name__)

CONNECTION = postgres.Connection('postgres', 'wiki')

CORS(APP)


@APP.route('/', methods=['GET', 'OPTIONS'])
def index():
    """The main function that renders the index page.
    """

    return render_template('index.html')


@APP.route('/api/links/<article_title>', methods=['GET'])
def get_links(article_title):
    """The API link that returns a list of the giver article's links.
    """

    link_rows = CONNECTION.query(
        'SELECT to_article FROM link WHERE lower(from_article)=%s',