Skip to content

Commit

Permalink
Update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
parafoxia committed Jul 23, 2021
1 parent 7ad57ba commit b4a74b5
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
### Custom ###
*.json
secrets
tests

testrun.py

### Data ###
*.csv
Expand Down
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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]
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:

Expand Down Expand Up @@ -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")
```

Expand All @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -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")
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions requirements-opt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r requirements.txt
pandas<2.0.0,>=1.0.0
4 changes: 4 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r requirements.txt
pytest==6.2.4
pandas<2.0.0,>=1.0.0
.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests<3.0.0,>=2.0.0
requests-oauthlib<2.0.0,>=0.3.1
62 changes: 43 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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*"]),
)

0 comments on commit b4a74b5

Please sign in to comment.