예제 #1
0
def save_item(item):
    if not item or item.get('link') is None:
        return

    time = datetime.datetime.now() + datetime.timedelta(days=-14)
    assert 'title' in item
    assert 'resource' in item
    assert 'link' in item

    if not Item.objects.filter(link=item.get('link'),
                               related_to_date__gt=time).exists():

        _a = Item(
            title=item.get('title'),
            resource=item.get('resource'),
            link=item.get('link'),
            description=item.get('description', ''),
            status=item.get('status', 'autoimport'),
            user_id=settings.BOT_USER_ID,
            section=item.get('section', None),
            additionally=item.get('additionally', None),
            language=item.get('language') if item.get('language') else 'en')

        _a.save()

        if item.get('tags'):
            _a.tags.add(*item.get('tags'))
            _a.save()
        elif item.get('status') == 'active':
            _a.save()
예제 #2
0
def save_item(item):
    assert 'title' in item
    assert 'resource' in item
    assert 'link' in item

    if not Item.objects.filter(title=item.get('title'),
                               link=item.get('link'),
                               description=item.get('description')).exists():
        _a = Item(
            title=item.get('title'),
            resource=item.get('resource'),
            link=item.get('link'),
            description=item.get('description', ''),
            status=item.get('status', 'autoimport'),
            user_id=settings.BOT_USER_ID,
            section=item.get('section', None),
            language=item.get('language') if item.get('language') else 'en')

        _a.save()

        if item.get('tags'):
            _a.tags.add(*item.get('tags'))
            _a.save()
        elif item.get('status') == 'active':
            _a.save()
예제 #3
0
    def test_filter_exists_news(self):
        rss_items = get_items_from_rss(self.res_rss.link)

        Item(title=rss_items[0]['title'],
             link=rss_items[0]['link'],
             section=self.section).save()
        Item(title=rss_items[1]['title'],
             link=rss_items[1]['link'],
             section=self.section).save()
        Item(title=rss_items[2]['title'],
             link=rss_items[2]['link'],
             section=self.section).save()
        Item(title=rss_items[3]['title'],
             link=rss_items[3]['link'],
             section=self.section).save()
        Item(title=rss_items[4]['title'],
             link=rss_items[4]['link'],
             related_to_date=datetime.date(2005, 7, 14),
             section=self.section).save()
        Item(title=rss_items[5]['title'],
             link=rss_items[5]['link'],
             related_to_date=datetime.date(2016, 4, 12),
             section=self.section).save()

        fil = partial(is_not_exists_rss_item,
                      minimum_date=datetime.date(2016, 4, 11))
        self.assertEqual(len(list(filter(fil, rss_items))), 20)
예제 #4
0
    def test_type(self):
        section = Section(title='Статьи')

        object = Item(title='Title1',
                      link='https://pythondigest.ru',
                      section=section)