def update_news(): recent_news = get_news() authors = [news['author'] for news in recent_news] titles = s.query(News.title).filter(News.author.in_(authors)).subquery() existing_news = s.query(News).filter(News.title.in_(titles)).all() for news in recent_news: if not existing_news or news not in existing_news: fill(news) redirect("/news")
def update_news(): recent_news = get_news() authors = [news['author'] for news in recent_news] titles = s.query(News.title).filter(News.author.in_(authors)).subquery() existing_news = s.query(News).filter(News.title.in_(titles)).all() titles_bd = [i.title for i in existing_news] authors_bd = [i.author for i in existing_news] for news in recent_news: if not existing_news or (news['title'] not in titles_bd and news["author"] not in authors_bd): fill(news) redirect("/news")
def get_categories(model, x_data, row_data): pred = model.predict(x_data) proba = model.predict_proba(x_data) cnt = [0, 0] for i, p in enumerate(pred): indices = np.where(p) clear = True for e in proba[i]: if 0.050 < e < 0.800: clear = False break cats = [0, 0, 0, 0, 0] for idx in indices[0]: cats[int(idx)] = 1 fill(row_data[i], cats[0], cats[1], cats[2], cats[3], cats[4], int(clear)) cnt[int(clear)] += 1 print("Reviews successfully classified with {} clear and {} confusing reviews\n".format(cnt[1], cnt[0]))
def collect(): url = request.forms.get("url") for r in get_reviews(url): fill(r) redirect("/reviews")