How to use the pypistats.models.download.RecentDownloadCount function in pypistats

To help you get started, we’ve selected a few pypistats examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crflynn / pypistats.org / pypistats / views / general.py View on Github external
def search(package):
    """Render the home page."""
    package = package.replace(".", "-")
    form = MyForm()
    if form.validate_on_submit():
        package = form.name.data
        return redirect(f"/search/{package}")
    results = RecentDownloadCount.query.filter(
        RecentDownloadCount.package.like(f"{package}%"),
        RecentDownloadCount.category == "month").\
        order_by(RecentDownloadCount.package).\
        limit(20).all()
    packages = [r.package for r in results]
    if len(packages) == 1:
        package = packages[0]
        return redirect(f"/packages/{package}")
    return render_template(
        "search.html", search=True, form=form, packages=packages, user=g.user
    )
github crflynn / pypistats.org / migrations / seeds.py View on Github external
logging.info(packages)

# take the last 120 days
end_date = datetime.date.today()
date_list = [end_date - datetime.timedelta(days=x) for x in range(120)][::-1]

baseline = 1000

# build a bunch of seed records with random values
records = []
for package in packages + ["__all__"]:
    print("Seeding: " + package)

    for idx, category in enumerate(["day", "week", "month"]):
        record = RecentDownloadCount(
            package=package, category=category, downloads=baseline * (idx + 1) + random.randint(-100, 100)
        )
        records.append(record)

    for date in date_list:

        for idx, category in enumerate(["with_mirrors", "without_mirrors"]):
            record = OverallDownloadCount(
                date=date,
                package=package,
                category=category,
                downloads=baseline * (idx + 1) + random.randint(-100, 100),
            )
            records.append(record)

        for idx, category in enumerate(["2", "3"]):