def user_article_info(user: User, article: Article, with_content=False, with_translations=True): from zeeguu.model import UserArticle prior_info = UserArticle.find(user, article) ua_info = article.article_info(with_content=with_content) if not prior_info: ua_info['starred'] = False ua_info['opened'] = False ua_info['liked'] = False ua_info['translations'] = [] return ua_info ua_info['starred'] = prior_info.starred is not None ua_info['opened'] = prior_info.opened is not None ua_info['liked'] = prior_info.liked if with_translations: translations = Bookmark.find_all_for_user_and_url(user, article.url) ua_info['translations'] = [ each.serializable_dictionary() for each in translations ] return ua_info
def user_article_update(): """ update info about this (user x article) pair in the form data you can provide - liked=True|1|False|0 - starred -ibidem- :return: json as prepared by content_recommender.mixed_recommender.user_article_info """ url = request.form.get('url') starred = request.form.get('starred') liked = request.form.get('liked') article = Article.find_or_create(db_session, url) user_article = UserArticle.find_or_create(db_session, flask.g.user, article) if starred is not None: user_article.set_starred(starred in ["True", "1"]) if liked is not None: user_article.set_liked(liked in ["True", "1"]) db_session.commit() return "OK"
def article_opened(session, value, user): # the url that comes from zeeguu event logger # might be the zeeguu url: which is of the form # https://www.zeeguu.unibe.ch/read/article?articleLanguage=de&articleURL=https://www.nzz.ch/wissenschaft/neandertaler-waren-kuenstler-ld.1358862 # thus we extract only the last part url = value.split('articleURL=')[-1] article = Article.find_or_create(session, url) ua = UserArticle.find(user, article) if not ua: ua = UserArticle.find_or_create(session, user, article, opened=datetime.now()) ua.opened = datetime.now() session.add(ua) session.commit() log(f"{ua}")
print("1. finding urls in activity data...") all_urls = set() all_activity_data = UserActivityData.query.all() 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} data...") all_articles = Article.all_older_than(days=DAYS) print(f" ... article count: {len(all_articles)}") for each in all_articles: 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) dbs.commit()
def user_articles_starred_and_liked(): return json_result(UserArticle.all_starred_and_liked_articles_of_user_info(flask.g.user))
last_starred = None last_starred_act = UserActivityData.find(bookmark.user, extra_filter='title', extra_value=bookmark.text.url.title, event_filter='UMR - STAR ARTICLE') if len(last_starred_act) %2 == 1: last_starred = last_starred_act[0].time # for debugging, in case latest opened data isn't found if last_opened == None and False: print() print(urlcrop) activities = UserActivityData.find(bookmark.user, event_filter='UMR - OPEN ARTICLE') print(activities) for act in activities: print(act.extra_data) print() ua = UserArticle.find_or_create(session, bookmark.user, article, starred=last_starred, liked=Nlikes%2==1, opened=last_opened) if last_opened == None: print(f'-- Could not find latest opened date {last_starred} x {ua.user.name} x {ua.article.title}') session.commit() print(f'SUCCESS: {last_starred} x {ua.user.name} x {ua.article.title}') except Exception as ex: import traceback print(f'-- could not import {urlcrop}') print(traceback.format_exc())
import zeeguu from zeeguu.model import Article, UserArticle from zeeguu.model.starred_article import StarredArticle session = zeeguu.db.session for sa in StarredArticle.query.all(): try: article = Article.find_or_create(session, sa.url.as_string()) ua = UserArticle.find_or_create(session, sa.user, article, starred=sa.starred_date) session.add(ua) session.commit() print(f'{sa.starred_date} x {ua.user.name} x {ua.article.title}') except Exception as ex: print(f'could not import {sa.url.as_string()}') print(ex)