Debian Codegraph @

bin/mygpo-list-devices

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # gpodder.net API Client
4 # Copyright (C) 2009-2013 Thomas Perl and the gPodder Team
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19
20 from __future__ import print_function
21 import sys
22 import getpass
23
24 import mygpoclient
25
26 from mygpoclient import api
27
28
29 def usage():
30 print("""
31 Usage: python %s {username} [host_or_url]
32 """ % (sys.argv[0],), file=sys.stderr)
33 sys.exit(1)
34
35
36 if __name__ == '__main__':
37 # Use the default url if not specified
38 if len(sys.argv) == 2:
39 sys.argv.append(mygpoclient.ROOT_URL)
40
41 # Check for valid arguments
42 if len(sys.argv) != 3:
43 usage()
44
45 # Split arguments in local variables
46 progname, username, root_url = sys.argv
47
48 # Read password from the terminal
49 password = getpass.getpass("%s@%s's password: " % (username, root_url))
50
51 # Create the client object with username/password/root_url set
52 client = api.MygPodderClient(username, password, root_url)
53
54 for device in client.get_devices():
55 print(device)
56 for podcast in client.get_subscriptions(device):
57 print(' ' + podcast)
58 print('-' * 50)