Exemple #1
0
def get_news():
    now = datetime.now()
    strnow = now.strftime('%Y-%m-%d %H:%M:%S')
    print(strnow)
    # First next run time
    '''
    period = timedelta(days=day, hours=hour, minutes=min, seconds=second)
    next_time = now + period
    strnext_time = next_time.strftime('%Y-%m-%d %H:%M:%S')
    print(strnext_time)
    '''
    pasttime = now - timedelta(days=1)
    paststr = pasttime.strftime('%Y-%m-%d %H:%M:%S')
    print(paststr)

    df = pro.news(src='sina', start_date=strnow, end_date=paststr)
    print(df)
    for index, row in df.iterrows():

        news = News()
        news.timestamp = index
        news.title = row['title']
        news.body = row['content']
        news.author = 'default'
        db.session.add(news)
        db.session.commit()
    newss = News.query.all()
    for n in newss:
        print(n.id, n.body)
Exemple #2
0
def post_news():
    form = PostNewsForm()
    if form.validate_on_submit():
        news = News()
        news.body = form.body.data
        news.private = form.private.data
        news.title = form.title.data
        news.user_id = current_user.id
        db.session.add(news)
        db.session.commit()
        return redirect(url_for('.all_news'))
    return render_template('main/post_news.html', form=form)
Exemple #3
0
def post_news():
    form = PostNewsForm()
    if form.validate_on_submit():
        print('1')
        new = News()
        new.body = form.body.data
        new.private = form.private.data
        new.title = form.title.data
        new.user_id = current_user.id
        db.session.add(new)
        db.session.commit()
        print('2')
        return redirect(url_for('main.user_info', id=current_user.id))
    return render_template('main/post_news.html', form=form)