Connect with ease to the public rts/ssr public API.
Project description
ssr_rts_api
Connect with ease to the rts/ssr channel public API.
The package can only access the "RTS Archives v3" (broadcast) endpoint
Enjoy exploring RTS (radio télévision suisse romande) channel broadcast open data 📺 !
Get it
$ pip install ssr_rts_api
How it works
Connect to the RTS archives public api can be a little bit confusing. ssr_rts_api is aimed to resolve that issue.
Go to : https://developer.srgssr.ch/apis/rts-archives-v3
Create your app
Get your consumer key and consumer secret
Remember, the package is only for accessing the "RTS Archives v3" (broadcast) API
from ssr_rts_api import Client as Cl
Pass an object with your credentials for generating a token and instantiate a client access to the API
- username = consumer key
- password = consumer secret
obj = {"username": "your_consumer_key",
"password": "yout_consumer_secret"}
cl = Cl.Client(obj)
Get your token through the Client.token parameter
print(cl.token)
Pass an object with the desired request inside the Client.request() method
querystring = {
"query": "'id'='103'",
"rows": 0,
"start": 25, # be careful, RTS api returns no more than 25 documents per request
"minPublicationDate": 1960,
"maxPublicationDate": 2020,
"sort": "publicationDate"
}
results = cl.request(querystring)
data = results.json()
Results can be a little bit "too" generous. Refine the results with the Client.filter() method
filtered = cl.filter_data(data, ['program', 'id'], 103) # program id : 103 = Temps Présent
Use the to_pop argument to pop out fields of the data set.
filtered = cl.filter_data(data, ['isOnline'], 'true', 'sequences') # pop "sequence" field
Save the result with the Client.save() method. Pass a data array and a mongodb collection in parameters
res = cl.save_data(data, collection)
Last note
Be kind, don't over request the server : use time.sleep()
import time
time.sleep(3) #zzZZZ
Credit
Renato Diaz (rerouj) renatojour@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ssr_rts_api-0.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d2c577ae9ce3bee55af5b0d35093508a1b5b76bb96ec55cf2411671899ad62c |
|
MD5 | 8aeda50f3367d871337d5ebce4ef71b6 |
|
BLAKE2b-256 | 36f2bcb97398c4a85b39d9bded6a5484121f9dd90e1c6c7c61d7d61abe151938 |