コード例 #1
0
def topic(topic):
    db = get_db()
    print(topic)
    articles = db.execute(
        'SELECT * FROM article WHERE topic = ? ORDER BY published DESC',
        (topic, )).fetchall()
    print(articles)
    return render_template('topic.html',
                           articles=articles,
                           topic=topic.capitalize())
コード例 #2
0
def me():
    db = get_db()

    topics = request.args.get('topics').split(',')

    query = 'SELECT * FROM article WHERE'
    for topic in topics:
        query += ' topic = \'' + topic + '\' OR'

    query = query[:-3] + 'ORDER BY published DESC'

    articles = db.execute(query).fetchall()
    return render_template('me.html', articles=articles)
コード例 #3
0
 def god():
     if request.method == 'POST':
         from_number = request.form['From']
         body = request.form['Body']
         db = get_db()
         print(body)
         try:
             process_info(body, from_number)
             return Response(status=200)
         except Exception as e:
             print(e)
             return Response(status=500)
     else:
         return Response(status=404)
コード例 #4
0
def update_articles_topic():
    db = get_db()
    topic = request.form['topic']
    articles = parse_news_sources(topic, 5, 50)
    for article in articles:
        if article['author']:
            article['author'] = ', '.join(article['author'].split(','))
        else:
            article['author'] = ''
        db.execute(
            'INSERT INTO article (headline, body, link, topic, published, author, imglink) VALUES (?, ?, ?, ?, ?, ?, ?)',
            (article['headline'], article['body'], article['link'], topic,
             article['published'], article['author'], article['image']))
        db.commit()

    return Response(status=200)
コード例 #5
0
ファイル: user.py プロジェクト: jguo1249/Hack2018
def signup():

    phone = '+1' + request.form['phone']
    topics = []

    for value in request.form.getlist('topics[]'):
        topics.append(value)

    frequency = request.form['frequency']
    firstDelivery = request.form['firstDelivery']
    firstDelivery = datetime.datetime.now()

    print(topics)

    db = get_db()
    error = None

    if not phone:
        error = 'Phone number is required.'
    elif db.execute('SELECT id FROM user WHERE phone = ?',
                    (phone, )).fetchone() is not None:
        error = 'Phone number {} is already registered.'.format(phone)

    if error is None:
        topics_dict = parse_topics(topics)

        db.execute(
            'INSERT INTO user (phone, world, local, sports, science, food, entertainment, politics, technology, context, frequency, firstDelivery) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
            (phone, topics_dict["world"], topics_dict["local"],
             topics_dict["sports"], topics_dict["science"],
             topics_dict["food"], topics_dict["entertainment"],
             topics_dict["politics"], topics_dict["technology"], '', frequency,
             firstDelivery))
        db.commit()
        twilio_signup(phone)
        send_data(
            'http://www.newsdonequick.online{}'.format(
                url_for('news.me',
                        topics=','.join(topics)).replace('%2C', ',')), phone)

        return redirect(
            url_for('news.me', topics=','.join(topics)).replace('%2C', ','))

    flash(error)
    return redirect(url_for('news.index'))
コード例 #6
0
def get_top_news():
    db = get_db()
    headlines = db.execute(
        'SELECT headline FROM article ORDER BY published DESC').fetchone()
    return headlines[0]
コード例 #7
0
def index():
    db = get_db()

    articles = db.execute('SELECT * FROM article ORDER BY published DESC')

    return render_template('index.html', articles=articles)