Пример #1
0
    def update(self, start, end):
        news = News.objects(created_at__gt=end,
                            created_at__lte=start,
                            shares__social_network__ne=self.name).first()

        if not news:
            news = News.objects(created_at__gt=end,
                                created_at__lte=start).order_by('shares__update').first()

        if news:
            count = self.get(news.link)

            try:
                social_network = news.shares.get(social_network=self.name)

                if count > social_network.count:
                    social_network.change = count - social_network.count
                    social_network.count = count
                    social_network.update = datetime.now()
                    social_network.save()

            except db.DoesNotExist:
                news.shares.create(social_network=self.name,
                                   count = count,
                                   update = datetime.now(),
                                   change = count)
                news.save()
Пример #2
0
    def save(self, *args, **kwargs):
        # create record in News
        try:
            news = News(media=self.media,
                        link=kwargs.get("link"),
                        text=kwargs.get("text"),
                        tags=kwargs.get("tags", []))
            news.save()

        except db.NotUniqueError:
            pass
Пример #3
0
def timeline(stamp=None):
    page = int(request.args.get("page", 1))
    search = request.args.get("search", "")

    if not stamp:
        news = News.objects()
    else:
        if page == 1:
            news = News.objects(created_at__gt=datetime.utcfromtimestamp(stamp))
        else:
            news = News.objects(created_at__lte=datetime.utcfromtimestamp(stamp))

    if search:
        news = news.filter(text__icontains=search)

    news = news.paginate(page=page, per_page=app.config["LINKS_PER_PAGE"])
    stamp = time.time()

    if request.is_xhr:
        return jsonify(news=news.items, search=search, stamp=stamp)
    else:
        return render_template("timeline.html", news=news.items, search=search, stamp=stamp)
Пример #4
0
def index(delta=None):
    if delta == "today":
        end_time = datetime.now()
        start_time = end_time.replace(hour=0, minute=0, second=0, microsecond=0)
    elif delta == "yesterday":
        end_time = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
        start_time = end_time - timedelta(days=1)
    elif delta == "week":
        end_time = datetime.now()
        start_time = end_time.replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(days=7)
    else:
        end_time = datetime.now()
        start_time = end_time - timedelta(days=1)

    news = News.objects(created_at__gt=start_time, created_at__lte=end_time)\
               .order_by("-shares__count")[:(app.config["LINKS_PER_PAGE"] * 2)]

    if request.is_xhr:
        return jsonify(news=news, delta=delta)
    else:
        return render_template("lastnews.html", news=news, delta=delta)