예제 #1
0
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"
예제 #2
0
def user_article():
    """

        called user_article because it returns info about the article
        but also the user-specific data relative to the article

        takes url as URL argument
        NOTE: the url should be encoded with quote_plus (Pyton) and encodeURIComponent(Javascript)

        this is not perfectly RESTful, but we're not fundamentalist...
        and currently we want to have the url as the URI for the article
        and for some reason if we put the uri as part of the path,
        apache decodes it before we get it in here.
        so for now, we're just not putting it as part of the path


    :return: json as prepared by content_recommender.mixed_recommender.user_article_info

    """

    url = request.args.get('url', '')
    if not url:
        flask.abort(400)

    article = Article.find_or_create(db_session, url)

    return json_result(
        user_article_info(flask.g.user, article, with_content=True))
예제 #3
0
    def __init__(self, real=False):
        super().__init__()

        if real:
            self.article = Article.find_or_create(ArticleRule.db.session,
                                                  TEST_URL)
        else:
            self.article = self._create_model_object()
            self.save(self.article)
def article_feedback(session, value, extra_data):
    # 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)
    if "not_finished_for_broken" in extra_data:
        article.vote_broken()
        session.add(article)
        session.commit()
def article_liked(session, value, user, like_value):
    # 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)
    ua.liked = like_value
    session.add(ua)
    session.commit()
    log(f"{ua}")
예제 #6
0
def get_user_article_info():
    """

        expects one parameter: url

    :return: json dictionary with info

    """

    url = str(request.form.get('url', ''))

    article = Article.find_or_create(db_session, url)

    return json_result(user_article_info(flask.g.user, article))
예제 #7
0
def add_bookmark(db, user, original_language, original_word,
                 translation_language, translation_word, date, the_context,
                 the_url, the_url_title):
    session = db.session

    url = Url.find_or_create(session, the_url, the_url_title)

    article = Article.find_or_create(session, url.as_string())

    text = Text.find_or_create(session, the_context, translation_language, url,
                               article)

    origin = UserWord.find_or_create(session, original_word, original_language)

    translation = UserWord.find_or_create(session, translation_word,
                                          translation_language)

    b1 = Bookmark(origin, translation, user, text, date)
    db.session.add(b1)
    db.session.commit()

    return b1
    def _find_article_in_value_or_extra_data(self, db_session):
        """
            Finds or creates an article_id

            return: articleID or NONE

            NOTE: When the article cannot be downloaded anymore,
            either because the article is no longer available or the newspaper.parser() fails

        """

        if self.event in ALL_ARTICLE_INTERACTION_ACTIONS:

            if self.value.startswith('http'):
                url = self.value
            else:
                url = self.find_url_in_extra_data()

            if url:
                return Article.find_or_create(db_session,
                                              url,
                                              sleep_a_bit=True).id

        return None
예제 #9
0
visited_url_user_pairs = []

for bookmark in Bookmark.query.all():
    try:

        urlcrop = str(bookmark.text.url).split('articleURL=')[-1]

        url_user_hash = urlcrop + bookmark.user.name

        if url_user_hash in visited_url_user_pairs:
            continue

        visited_url_user_pairs.append(url_user_hash)

        article = Article.find_or_create(session, urlcrop, bookmark.text.language)

        likes = UserActivityData.find(bookmark.user, extra_filter='title', extra_value=str(bookmark.text.url.title), event_filter='UMR - LIKE ARTICLE')
        Nlikes = len(likes)
        #print(sa.url)
        url_end = urlcrop.find("xtor=RSS")
        if url_end < 0:
            url = str(urlcrop)
        else:
            url = str(urlcrop)[:url_end-1]

        last_opened_act = UserActivityData.find(bookmark.user, extra_filter='articleURL', extra_value=url, event_filter='UMR - OPEN ARTICLE', only_latest=True)
        if last_opened_act is None:
            last_opened = None
        else:
            last_opened = last_opened_act.time
예제 #10
0
 def test_load_article_without_language_information(self):
     url = 'https://edition.cnn.com/2018/03/12/asia/kathmandu-plane-crash/index.html'
     art = Article.find_or_create(session, url)
     assert (art)
예제 #11
0
 def test_find_or_create(self):
     self.new_art = Article.find_or_create(session, SOME_ARTICLE_URL)
     assert (self.new_art.fk_difficulty)
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)