def is_the_article_referenced(article, print_reference_info): info = UserArticle.find_by_article(article) interaction_data = UserActivityData.query.filter_by( article_id=article.id).all() reading_session_info = UserReadingSession.query.filter_by( article_id=article.id).all() belongs_to_a_cohort = CohortArticleMap.query.filter_by( article_id=article.id).all() referenced = info or interaction_data or reading_session_info or belongs_to_a_cohort if print_reference_info and referenced: print(f"WON'T DELETE ID:{article.id} -- {article.title}") for ainfo in info: print(ainfo.user_info_as_string()) if interaction_data: print("interaction data: (e.g. " + str(interaction_data[0])) if reading_session_info: print("reading session info: (e.g. " + str(reading_session_info[0])) if belongs_to_a_cohort: print("referenced by a cohort: (e.g. " + str(belongs_to_a_cohort[0])) return referenced
for each in all_activity_data: url = each.find_url_in_extra_data() if url: all_urls.add(url) print(f" ... url count: {len(all_urls)}") # print(f"2. finding articles older than {DAYS} days...") all_articles = Article.all_older_than(days=DAYS) print(f" ... article count: {len(all_articles)}") i = 0 for each in all_articles: i += 1 info = UserArticle.find_by_article(each) url_found = each.url.as_string() in all_urls if info or url_found: if info: print(f"WON'T DELETE info! {each.id} {each.title}") for ainfo in info: print(ainfo.user_info_as_string()) if url_found: print(f"WON'T DELETE url_found! {each.id} {each.title}") else: deleted.append(each.id) dbs.delete(each) if i == 1000: dbs.commit()