diff --git a/.gitignore b/.gitignore index 6a42610..2f74166 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ ### Custom ### *.json secrets -tests - +testrun.py ### Data ### *.csv diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..b986c7d --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,9 @@ +graft analytix +include LICENSE +include pyproject.toml +include README.md +include requirements.txt +include requirements-dev.txt +include requirements-opt.txt +include setup.py +global-exclude *.py[cod] diff --git a/README.md b/README.md index 9cee67d..28875ca 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PyPi version](https://img.shields.io/pypi/v/analytix.svg)](https://pypi.python.org/pypi/analytix/) [![PyPI pyversions](https://img.shields.io/pypi/pyversions/analytix.svg)](https://pypi.python.org/pypi/analytix/) [![License](https://img.shields.io/github/license/parafoxia/analytix.svg)](https://github.com/parafoxia/analytix/blob/main/LICENSE) -A simple yet powerful API wrapper to make getting analytical information from the YouTube Analytics API easier than ever. +A simple yet powerful API wrapper to make getting analytical information from the YouTube Analytics API easier than ever. More services are coming in the future. ## Features @@ -14,7 +14,7 @@ A simple yet powerful API wrapper to make getting analytical information from th ## Installation -**You need Python 3.7.1 or greater to run analytix.** You will also need to have a Google Developers project with the YouTube Analytics API enabled. You can find instructions on how to do that in the [YouTube Analytics API docs](https://developers.google.com/youtube/reporting/v1/code_samples/python#set-up-authorization-credentials/). +**You need Python 3.7.0 or greater to run analytix.** You will also need to have a Google Developers project with the YouTube Analytics API enabled. You can find instructions on how to do that in the [YouTube Analytics API docs](https://developers.google.com/youtube/reporting/v1/code_samples/python#set-up-authorization-credentials/). It is recommended you install analytix in a virtual environment. To do this, run the following: @@ -54,12 +54,14 @@ $ python3.9 -m pip install -U . The following example shows you how easy analytix can be to use. This retrieves day-by-day analytics for the last 28 days using all metrics. ```py -from analytix.youtube import YouTubeAnalytics, YouTubeService +import datetime as dt + +from analytix import YouTubeAnalytics, YouTubeAnalyticsClient -service = YouTubeService("./secrets.json") # Load from secrets file -service.authorise() -analytics = YouTubeAnalytics(service) -report = analytics.retrieve(dimensions=("day",)) +client = YouTubeAnalyticsClient("./secrets.json") # Load from secrets file +analytics = YouTubeAnalytics(client) +start_date = dt.date.today() - dt.timedelta(days=28) +report = analytics.retrieve(start_date, dimensions=("day",)) report.to_csv("./analytics-28d.csv") ``` @@ -70,18 +72,17 @@ import datetime as dt import matplotlib.pyplot as plt import seaborn as sns -from analytix.youtube import YouTubeAnalytics, YouTubeService +from analytix import YouTubeAnalytics, YouTubeAnalyticsClient -service = YouTubeService("./secrets.json") -service.authorise() -analytics = YouTubeAnalytics(service) +client = YouTubeAnalyticsClient("./secrets.json") +analytics = YouTubeAnalytics(client) report = analytics.retrieve( + dt.date(2021, 1, 1), + dt.date(2021, 1, 31), metrics=("views",), dimensions=("day", "deviceType", "subscribedStatus"), filters={"liveOrOnDemand": "LIVE"}, - start_date=dt.date(2021, 1, 1), - end_date=dt.date(2021, 1, 31), sort_by=("views",), ) report.to_csv("./live-device-types.csv") diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..9e7b10c --- /dev/null +++ b/noxfile.py @@ -0,0 +1,7 @@ +import nox + + +@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"], reuse_venv=True) +def tests(session: nox.Session) -> None: + session.run("pip", "install", "-r", "requirements-test.txt") + session.run("pytest", "-s", "--verbose") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..65525d5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" + +[tool.black] +extend-exclude = "analytix/__init__.py" +line-length = 79 diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..3bb56ce --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,8 @@ +-r requirements.txt +black==21.7b0 +# mypy==0.910 +nox==2021.6.12 +pandas<2.0.0,>=1.0.0 +sphinx==4.1.1 +sphinx-rtd-dark-mode==1.2.3 +sphinx-rtd-theme==0.5.2 diff --git a/requirements-opt.txt b/requirements-opt.txt new file mode 100644 index 0000000..94c36cd --- /dev/null +++ b/requirements-opt.txt @@ -0,0 +1,2 @@ +-r requirements.txt +pandas<2.0.0,>=1.0.0 diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..a13cbc4 --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,4 @@ +-r requirements.txt +pytest==6.2.4 +pandas<2.0.0,>=1.0.0 +. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2a813f2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests<3.0.0,>=2.0.0 +requests-oauthlib<2.0.0,>=0.3.1 diff --git a/setup.py b/setup.py index 45fb2d9..483cb2a 100644 --- a/setup.py +++ b/setup.py @@ -1,26 +1,48 @@ import sys -if sys.version_info < (3, 7, 1): - print("analytix requires Python version >= 3.7.1.", file=sys.stderr) +if sys.version_info < (3, 6, 0): + print( + "analytix only supports Python versions 3.6.0 or greater.", + file=sys.stderr, + ) sys.exit(1) import setuptools -import analytix -with open("./README.md", "r", encoding="utf-8") as f: +def parse_requirements(path): + with open(path, mode="r", encoding="utf-8") as f: + deps = (d.strip() for d in f.readlines()) + return [d for d in deps if not d.startswith(("#", "-r"))] + + +with open("analytix/__init__.py", mode="r", encoding="utf-8") as f: + ( + productname, + version, + description, + url, + docs, + author, + license_, + bug_tracker, + ) = [l.split('"')[1] for l in f.readlines()[:8]] + +with open("./README.md", mode="r", encoding="utf-8") as f: long_description = f.read() setuptools.setup( - name=analytix.__productname__, - version=analytix.__version__, - description=analytix.__description__, + name=productname, + version=version, + description=description, long_description=long_description, long_description_content_type="text/markdown", - url=analytix.__url__, - author=analytix.__author__, - license=analytix.__license__, + url=url, + author=author, + license=license_, classifiers=[ + # "Development Status :: 1 - Planning", + # "Development Status :: 2 - Pre-Alpha", # "Development Status :: 3 - Alpha", # "Development Status :: 4 - Beta", "Development Status :: 5 - Production/Stable", @@ -34,21 +56,23 @@ "Operating System :: Unix", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + # "Programming Language :: Python :: 3.10", "Topic :: Utilities", ], project_urls={ - "Documentation": analytix.__docs__, - "Source": analytix.__url__, + "Documentation": docs, + "Source": url, + "Bug Tracker": bug_tracker, }, - install_requires=[ - "google-api-python-client>=1.12.0", - "google-auth-oauthlib>=0.4.2", - "pandas>=1.2.0", - ], - # extras_require={}, - python_requires=">=3.7.1", + install_requires=parse_requirements("./requirements.txt"), + extras_require={ + "dev": parse_requirements("./requirements-dev.txt"), + "opt": parse_requirements("./requirements-opt.txt"), + }, + python_requires=">=3.6.0", packages=setuptools.find_packages(exclude=["tests*"]), )