How to use the pypistats.recent 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 hugovk / pypistats / tests / test_pypistats.py View on Github external
def test_valid_json(self):
        # Arrange
        package = "pip"
        mocked_url = "https://pypistats.org/api/packages/pip/recent?&period=day"
        mocked_response = """
        {"data": {"last_day": 1956060}, "package": "pip", "type": "recent_downloads"}
        """

        # Act
        with requests_mock.Mocker() as m:
            m.get(mocked_url, text=mocked_response)
            output = pypistats.recent(package, period="day", format="json")

        # Assert
        # Should not raise any errors eg. TypeError
        json.loads(output)
        self.assertEqual(json.loads(output), json.loads(mocked_response))
github hugovk / pypistats / tests / test_pypistats.py View on Github external
mocked_url = "https://pypistats.org/api/packages/pip/recent"
        mocked_response = """{
            "data":
                {"last_day": 2295765, "last_month": 67759913, "last_week": 15706750},
            "package": "pip", "type": "recent_downloads"
        }"""
        expected_output = """
| last_day  | last_month | last_week  |
|----------:|-----------:|-----------:|
| 2,295,765 | 67,759,913 | 15,706,750 |
"""

        # Act
        with requests_mock.Mocker() as m:
            m.get(mocked_url, text=mocked_response)
            output = pypistats.recent(package)

        # Assert
        self.assertEqual(output.strip(), expected_output.strip())
github hugovk / pypistats / example / example.py View on Github external
import argparse
from pprint import pprint  # noqa: F401

import pypistats

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Example use of pypistats",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    args = parser.parse_args()

    # Example use

    # Call the API
    print(pypistats.recent("pillow"))
    # print(pypistats.recent("pillow", "day", format="markdown"))
github hugovk / pypistats / src / pypistats / cli.py View on Github external
def recent(args):  # pragma: no cover
    print(
        pypistats.recent(
            args.package, period=args.period, format=args.format, verbose=args.verbose
        )