-
Notifications
You must be signed in to change notification settings - Fork 0
/
list-channels.py
36 lines (27 loc) · 1.21 KB
/
list-channels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Use the Switch Tube web service API to list channels you can contribute to.
Assuming the access token `Hbmqqdc8x49Qjk1L3BKBAec`, list the channels you
can contribute to:
$ python3 list-channels.py Hbmqqdc8x49Qjk1L3BKBAec
This script is intended to illustrate usage of the Switch Tube web service API
and is provided “as is”. Please see https://tube.switch.ch/api.html for more
information.
It depends on the Requests HTTP library. On most systems, this can be installed
using `python3 -m pip install requests`.
In case of a "SSLCertVerificationError", run `pip install --upgrade certifi` to
update the CA bundle.
"""
import argparse
import requests
ORIGIN = 'https://tube.switch.ch'
# Define and parse command line arguments.
parser = argparse.ArgumentParser(
description='List the channels you own on Switch Tube.')
parser.add_argument('token', help='access token from your Switch Tube profile')
arguments = parser.parse_args()
# Get channels and show their id and title.
response = requests.get(
ORIGIN + '/api/v1/channels?role=contributor',
headers={'Authorization': 'Token ' + arguments.token}
)
for channel in response.json():
print("{id}: {name}".format(id=channel['id'], name=channel['name']))