S4Gpy a python client library for Stream-for-Good Project
This client api can be used to perform analysis of S4G dataset with Python3.
It closely mirros the HATEAOS from the Rest API so that when requesting data, the links information are automatically converted to functions that can be called from the API.
For example with the user API
you can get a Python version with the following syntax:
from s4gpy.s4gpy import S4GAPI
#first register with your vod-prime.space credentials
api=S4GAPI()
#then get a user API object
user_api=api.get_user_api()
#get the users from the API
for u in user_api.get_users():
#for each user, follow the all-thumbnails link by calling the all_thumbnails() function.
for t in u.all_thumbnails()["thumbnails"]:
print(f"{u.user.user_id};{t.row};{t.col};{t.video_id};{t.timestamp}")
this code prints out the users' id, and some metadata on thumbnails that were proposed to her.
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;4;1;81074110;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;4;0;80994082;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;6;0;81277950;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;5;2;80232398;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;5;3;80234304;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;4;3;80095697;1610984583.0
1f52213c-f31d-4dc9-bac5-35464b2ff1b9;5;0;80025678;1610984584.0
Installation
From Pypi
pip install s4gpy
From source
#uninstall first
pip uninstall s4gpy
make build
pip install dist/*.whl
Examples
Direct API
Get the current direct schedule, with metadata from the companion platform-api
from s4gpy.s4gpy import S4GAPI
api=S4GAPI()
for s in api.get_direct_api().get_direct_schedule():
try:
imdb_data=s.content().imdb_id()
genres="+".join([g["genre"] for g in imdb_data.data.genres])
except AttributeError: #in case platform.vod-prime.space fucks up things
print(f"{s.airing_time};{s.video_id};UNKNOWN;UNKNOWN")
continue
print(f"{s.airing_time};{s.video_id};{imdb_data.data.title};f{genres}")
User API
Show the row/cols of every watched video for each user
from s4gpy.s4gpy import S4GAPI
#create an API entrypoint
api=S4GAPI()
#get the user_api
user_api=api.get_user_api()
#for each user
for u in user_api.get_users():
#get all the video she watched
watched_videos=[w.video_id for w in u.all_watches().watches]
#for all the thumbnails
for t in u.all_thumbnails()["thumbnails"]:
#only dump the informations if the user has wached the video
if t.video_id in watched_videos:
print(f"{u.user.user_id};{t.row};{t.col};{t.video_id};{t.timestamp}")
Direct API
Get the current direct schedule, with metadata from the companion platform-api
from s4gpy.s4gpy import S4GAPI
api=S4GAPI()
for s in api.get_direct_api().get_direct_schedule():
try:
imdb_data=s.content().imdb_id()
genres="+".join([g["genre"] for g in imdb_data.data.genres])
except AttributeError: #in case platform.vod-prime.space fucks up things
print(f"{s.airing_time};{s.video_id};UNKNOWN;UNKNOWN")
continue
print(f"{s.airing_time};{s.video_id};{imdb_data.data.title};f{genres}")
Credential API
Get some credentials for netflix to run a robot run
from s4gpy.s4gpy import S4GAPI
api=S4GAPI()
login, password = api.get_credentials_api().get_credentials("netflix")
Company Mapping API
Get/Set the mappings for content and company
from s4gpy.s4gpy import S4GAPI
from s4gpy.api.companyapi import CompanyAPI
from s4gpy.s4gsession import S4GSession
api = S4GAPI()
api.get_company_api().push_company("company1_cc_code",name="company 1 name",link="company 1 link")
api.get_company_api().push_company("company2_cc_code",name="company 2 name",link="company 2 link")
api.get_company_api().push_content("content_code",["company 1 name","company 2 name"])
for company in api.get_company_api().get_companies():
print(f"company code {company.company_id} is {company.company().name}")
for content in api.get_company_api().get_contents():
for company in content.content().companies():
print(f"content {content.content_id} is produced by {company.company_id}")
Metadata
Release files for s4gpy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| s4gpy-0.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for s4gpy-0.1.0-py2.py3-none-any.whl |
Release files / s4gpy-0.1.0-py2.py3-none-any.whl
| Download URL | s4gpy-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a2a4308b15641de1feb02d807bd5589e201850f3e2e259153e99b4089202188f
|
|
BLAKE2b-256 checksum How to use checksums |
ae869338b1cadf7e67b6ac0ac86d0649184b8a9739dcff58420bb5ce12fc0694
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/61.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
|
Security for s4gpy 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.