Exemplo n.º 1
0
def news_theft():  # Обновление новостей
    session = db_session.create_session()
    NewsFeed = feedparser.parse("https://news.yandex.ru/games.rss")
    nowosty = NewsFeed["entries"]
    for new in nowosty:
        title = new["title"]
        content = new["summary"]
        old_news = session.query(news.News)
        coincidence = False
        for old_new in old_news:
            if old_new.rus_content == content:
                coincidence = True
        if not coincidence:
            new_new = news.News(
                title=translater.translate(title),
                rus_title=title,
                rus_content=content,
                content=translater.translate(content)
            )
            session.add(new_new)
    session.commit()
    nowosty = session.query(news.News).order_by(news.News.created_date.desc())
    count = 0
    for new in nowosty:
        if count > 50:
            session.delete(new)
        count += 1
    session.commit()
Exemplo n.º 2
0
def add_new():
    form = NewsForm()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            sessions = db_session.create_session()
            new = news.News(title=form.title.data,
                            content=form.content.data,
                            user_id=1)
            sessions.add(new)
            sessions.commit()
            return redirect('/newfood')
        return redirect('/login')
    return render_template('news.html', form=form, kol=1)
Exemplo n.º 3
0
def add_news():
    form = NewsForm()
    if form.validate_on_submit():
        sessions = db_session.create_session()
        new = news.News()
        new.title = form.title.data
        new.content = form.content.data
        new.is_private = form.is_private.data
        current_user.news.append(new)
        sessions.merge(current_user)
        sessions.commit()
        return redirect('/')
    return render_template("news.html", title='Добавление новости', form=form)
Exemplo n.º 4
0
def create_news():
    if not request.json:
        return jsonify({"error": "Empty request"})
    elif not all(key in request.json
                 for key in ["title", "content", "user_id", "is_private"]):
        return jsonify({"error": "Bad request"})
    session = db_session.create_session()
    new = news.News(title=request.json['title'],
                    content=request.json["content"],
                    user_id=request.json["user_id"],
                    is_private=request.json["is_private"])
    session.add(new)
    session.commit()
    return jsonify({"success": "OK"})
Exemplo n.º 5
0
def create_news():
    if not request.json:
        return jsonify({'error': 'Empty request'})
    elif not all(key in request.json
                 for key in ['title', 'content', 'user_id', 'is_private']):
        return jsonify({'error': 'Bad request'})
    session = db_session.create_session()
    new = news.News(title=request.json['title'],
                    content=request.json['content'],
                    user_id=request.json['user_id'],
                    is_private=request.json['is_private'])
    session.add(new)
    session.commit()
    return jsonify({'success': 'OK'})
Exemplo n.º 6
0
def add_news():
    form = news_form.NewsForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        new = news.News()
        new.title = form.title.data
        new.content = form.content.data
        new.language = form.language.data
        current_user.news.append(new)
        session.merge(current_user)
        session.commit()
        return redirect('/Stories')
    return render_template('news.html', title='Add story',
                           form=form)
Exemplo n.º 7
0
 def add_news(self, content, time, title, tofmal_id, is_notice):
     if is_notice:
         new = self.session.query(news_notice.News).filter(
             news_notice.News.time == time).first()
         if new is not None:
             new.title = title
             new.content = content
             new.time = time
             new.tofmal_id = tofmal_id
             new.is_notice = is_notice
             self.session.commit()
             return
         new = news_notice.News()
         new.title = title
         new.content = content
         new.time = time
         new.tofmal_id = tofmal_id
         new.is_notice = is_notice
         self.session.add(new)
         self.session.commit()
     else:
         if datetime.fromisoformat(time) > datetime.now():
             return
         new = self.session.query(
             news.News).filter(news.News.time == time).first()
         if new is not None:
             new.title = title
             new.content = content
             new.time = time
             new.tofmal_id = tofmal_id
             new.is_notice = is_notice
             self.session.commit()
             return
         new = news.News()
         new.title = title
         new.content = content
         new.time = time
         new.tofmal_id = tofmal_id
         new.is_notice = is_notice
         self.session.add(new)
         self.session.commit()