def parse_rss():

    url = 'https://allmychanges.com/rss/03afbe621916b2f2145f111075db0759/'

    today = datetime.date.today()
    week_before = today - datetime.timedelta(weeks=1)
    try:
        packages = {
            x.get('name').strip(): x
            for x in list(Package.objects.all()
                          .values('name', 'description', 'link'))
        }
        _start_week, _end_week = get_start_end_of_week(today)
        _ = Issue.objects.filter(date_from=_start_week, date_to=_end_week)

        assert _.count() <= 1, 'Many ISSUE on week'
        _ = None if _.count() == 0 else _[0]
        news = Item.objects.filter(issue=_,
                                   status='active') if _ is not None else []

        section = Section.objects.get(title='Релизы')
        resource = Resource.objects.get(link='http://allmychanges.com/')
    except Exception as e:
        print(e)
        return

    saved_packages = []
    for n in feedparser.parse(url).entries:
        package_name, package_version = n.title.split()
        package_name = package_name.replace('python/', '')

        ct = len(Item.objects.filter(link=n.link, status='active')[0:1])
        if ct or not ('python' in n.title):
            saved_packages.append(package_name)
            continue

        time_struct = getattr(n, 'published_parsed', None)
        if time_struct:
            _timestamp = mktime(time_struct)
            dt = datetime.datetime.fromtimestamp(_timestamp)
            if dt.date() < week_before:
                continue

        try:
            if not (package_name in
                    packages.keys()) or package_name in saved_packages:
                continue

            if news and check_previous_news_of_package(news, packages.get(
                    package_name)):
                off_other_release_news(news, packages.get(package_name))

            item_data = _generate_release_item(package_version,
                                               n.link, resource, section,
                                               packages.get(package_name))
            saved_packages.append(package_name)
            save_item(item_data)
        except Exception as e:
            print(e)
            continue
Example #2
0
def parse_rss():
    url = 'https://allmychanges.com/rss/03afbe621916b2f2145f111075db0759/'

    today = datetime.date.today()
    week_before = today - datetime.timedelta(weeks=1)
    try:
        packages = {
            x.get('name').strip(): x
            for x in list(Package.objects.all().values('name', 'description',
                                                       'link'))
        }
        _start_week, _end_week = get_start_end_of_week(today)
        _ = Issue.objects.filter(date_from=_start_week, date_to=_end_week)

        assert _.count() <= 1, 'Many ISSUE on week'
        _ = None if _.count() == 0 else _[0]
        news = Item.objects.filter(issue=_,
                                   status='active') if _ is not None else []

        section = Section.objects.get(title='Релизы')
        resource = Resource.objects.get(link='http://allmychanges.com/')
    except Exception as e:
        print(e)
        return

    saved_packages = []
    for n in feedparser.parse(url).entries:
        package_name, package_version = n.title.split()
        package_name = package_name.replace('python/', '')

        ct = len(Item.objects.filter(link=n.link, status='active')[0:1])
        if ct or not ('python' in n.title):
            saved_packages.append(package_name)
            continue

        time_struct = getattr(n, 'published_parsed', None)
        if time_struct:
            _timestamp = mktime(time_struct)
            dt = datetime.datetime.fromtimestamp(_timestamp)
            if dt.date() < week_before:
                continue

        try:
            if not (package_name in packages.keys()) \
                or package_name in saved_packages:
                continue

            if news \
                and check_previous_news_of_package(
                    news, packages.get(package_name)):
                off_other_release_news(news, packages.get(package_name))

            item_data = _generate_release_item(package_version, n.link,
                                               resource, section,
                                               packages.get(package_name))
            saved_packages.append(package_name)
            save_item(item_data)
        except Exception as e:
            print(e)
            continue
Example #3
0
 def make_moderated(self, request, queryset):
     try:
         item = queryset.latest('pk')
         _start_week, _end_week = get_start_end_of_week(item.related_to_date)
         issue = Issue.objects.filter(date_from=_start_week, date_to=_end_week)
         assert len(issue) == 1
         issue.update(last_item=item.pk)
     except Exception:
         raise
Example #4
0
 def _action_make_moderated(self, request, queryset):
     try:
         item = queryset.latest('pk')
         _start_week, _end_week = get_start_end_of_week(
             item.related_to_date)
         issue = Issue.objects.filter(date_from=_start_week,
                                      date_to=_end_week)
         assert len(issue) == 1
         issue.update(last_item=item.pk)
     except Exception:
         raise
Example #5
0
    def get_queryset(self, request):

        # todo
        # потом переписать на логику:
        # ищем связку выпусков
        # неактивный, а перед ним активный
        # если такая есть, то публикуем новости у которых время в периоде
        # неактивного
        # если нету, то  отдаем все

        # сейчас логика такая:
        # берем выпуск за текущую неделю
        # если перед ним активный, то показываем новость за текущую неделю
        # если нет, то все новости показываем
        try:
            start_week, end_week = get_start_end_of_week(datetime.now().date())
            before_issue = Issue.objects.filter(date_to=end_week -
                                                timedelta(days=7))
            assert len(before_issue) == 1
            if before_issue[0].status == 'active':
                current_issue = Issue.objects.filter(date_to=end_week,
                                                     date_from=start_week)
                assert len(current_issue) == 1
                current_issue = current_issue[0]
            else:
                current_issue = before_issue[0]

            result = self.model.objects.filter(
                status__in=['pending', 'moderated', 'active', 'autoimport'],
                related_to_date__range=[
                    current_issue.date_from, current_issue.date_to
                ])

            if current_issue.last_item is not None:
                result = result.filter(pk__gt=current_issue.last_item, )
        except AssertionError:
            result = super(ItemModeratorAdmin, self).get_queryset(request)
        return result
Example #6
0
    def get_queryset(self, request):

        # todo
        # потом переписать на логику:
        # ищем связку выпусков
        # неактивный, а перед ним активный
        # если такая есть, то публикуем новости у которых время в периоде
        # неактивного
        # если нету, то  отдаем все

        # сейчас логика такая:
        # берем выпуск за текущую неделю
        # если перед ним активный, то показываем новость за текущую неделю
        # если нет, то все новости показываем
        try:
            start_week, end_week = get_start_end_of_week(datetime.now().date())
            before_issue = Issue.objects.filter(date_to=end_week - timedelta(days=7))
            assert len(before_issue) == 1
            if before_issue[0].status == 'active':
                current_issue = Issue.objects.filter(date_to=end_week, date_from=start_week)
                assert len(current_issue) == 1
                current_issue = current_issue[0]
            else:
                current_issue = before_issue[0]

            result = self.model.objects.filter(
                status__in=['pending', 'moderated', 'active', 'autoimport'],
                related_to_date__range=[current_issue.date_from, current_issue.date_to]
            )

            if current_issue.last_item is not None:
                result = result.filter(
                    pk__gt=current_issue.last_item,
                )
        except AssertionError:
            result = super(ItemModeratorAdmin, self).get_queryset(request)
        return result