Exemplo n.º 1
0
 def insert(article, topic, source):
     db_subscription = Subscription.update_or_create(Subscription.url == source.url,
                                                     url=source.url,
                                                     name=source.name,
                                                     image=source.image_url)
     db_article = Article.update_or_create(Article.url == article.url,
                                           source=db_subscription,
                                           publish_date=article.publish_date,
                                           url=article.url,
                                           author="",
                                           title=article.title,
                                           description=article.description,
                                           body=article.body,
                                           preview_image=article.preview_image_url)
     db_topic = Topic.update_or_create(Topic.source == db_subscription and
                                       Topic.name == topic.name and
                                       Topic.url == topic.url,
                                       source=db_subscription,
                                       name=topic.name,
                                       url=topic.url)
     try:
         ArticleTopic.get(article=db_article, topic=db_topic)
     except ArticleTopic.DoesNotExist:
         ArticleTopic.create(article=db_article, topic=db_topic)
Exemplo n.º 2
0
 def get_topic_last_update(url):
     try:
         db_topic = Topic.get(Topic.url == url)
         return db_topic.updated_at
     except Topic.DoesNotExist:
         return None