Skip to main content

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 is only for accessing 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 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 trough 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssr_rts_api-0.0.4.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ssr_rts_api-0.0.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file ssr_rts_api-0.0.4.tar.gz.

File metadata

  • Download URL: ssr_rts_api-0.0.4.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.8

File hashes

Hashes for ssr_rts_api-0.0.4.tar.gz
Algorithm Hash digest
SHA256 0fb11d8e1692de3fa54a286201be35bb0de7f85caa6e7158cb9e79b474852dd9
MD5 e29cad1665e6c09a61c8e9a2500d8272
BLAKE2b-256 9db4c80b834b81fdc829763b8c456a1ba3777deee962dd954cf1fd2163b8cc47

See more details on using hashes here.

File details

Details for the file ssr_rts_api-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: ssr_rts_api-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.8

File hashes

Hashes for ssr_rts_api-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2d4db61612d82d38f8c5b1d9ade0c839cde37a13bba48f7843ad02cfed5c26e2
MD5 53e82f24b9dfa9f1e8a3d9847f6b8b13
BLAKE2b-256 a473acf2249b1dfcd53dd13b4d0f389671d6eb1c55d6eebb6d2872c61477612f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page