Package: s4gpy
S4Gpy a python client library for Stream-for-Good ProjectThis 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, thelinksinformation are automatically converted to functions that can be called from the API.For example with the user APIyou can get a Python version with the following syntax:froms4gpy.s4gpyimportS4GAPI#first register with your vod-prime.space credentialsapi=S4GAPI()#then get a user API objectuser_api=api.get_user_api()#get the users from the APIforuinuser_api.get_users():#for each user, follow the all-thumbnails link by calling the all_thumbnails() function.fortinu.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.0InstallationFrom Pypipipinstalls4gpyFrom source#uninstall firstpipuninstalls4gpy
makebuild
pipinstalldist/*.whlExamplesDirect APIGet the current direct schedule, with metadata from the companion platform-apifroms4gpy.s4gpyimportS4GAPIapi=S4GAPI()forsinapi.get_direct_api().get_direct_schedule():try:imdb_data=s.content().imdb_id()genres="+".join([g["genre"]forginimdb_data.data.genres])exceptAttributeError:#in case platform.vod-prime.space fucks up thingsprint(f"{s.airing_time};{s.video_id};UNKNOWN;UNKNOWN")continueprint(f"{s.airing_time};{s.video_id};{imdb_data.data.title};f{genres}")User APIShow the row/cols of every watched video for each userfroms4gpy.s4gpyimportS4GAPI#create an API entrypointapi=S4GAPI()#get the user_apiuser_api=api.get_user_api()#for each userforuinuser_api.get_users():#get all the video she watchedwatched_videos=[w.video_idforwinu.all_watches().watches]#for all the thumbnailsfortinu.all_thumbnails()["thumbnails"]:#only dump the informations if the user has wached the videoift.video_idinwatched_videos:print(f"{u.user.user_id};{t.row};{t.col};{t.video_id};{t.timestamp}")Direct APIGet the current direct schedule, with metadata from the companion platform-apifroms4gpy.s4gpyimportS4GAPIapi=S4GAPI()forsinapi.get_direct_api().get_direct_schedule():try:imdb_data=s.content().imdb_id()genres="+".join([g["genre"]forginimdb_data.data.genres])exceptAttributeError:#in case platform.vod-prime.space fucks up thingsprint(f"{s.airing_time};{s.video_id};UNKNOWN;UNKNOWN")continueprint(f"{s.airing_time};{s.video_id};{imdb_data.data.title};f{genres}")Credential APIGet some credentials for netflix to run a robot runfroms4gpy.s4gpyimportS4GAPIapi=S4GAPI()login,password=api.get_credentials_api().get_credentials("netflix")Company Mapping APIGet/Set the mappings for content and companyfroms4gpy.s4gpyimportS4GAPIfroms4gpy.api.companyapiimportCompanyAPIfroms4gpy.s4gsessionimportS4GSessionapi=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"])forcompanyinapi.get_company_api().get_companies():print(f"company code{company.company_id}is{company.company().name}")forcontentinapi.get_company_api().get_contents():forcompanyincontent.content().companies():print(f"content{content.content_id}is produced by{company.company_id}")