2 # -*- coding: utf-8 -*-
3 # my.gpodder.org API Client
4 # Copyright (C) 2009 Thomas Perl
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.
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.
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/>.
25 from mygpoclient
import simple
28 print >>sys
.stderr
, """
29 Usage: python %s {get|put} {username} {device_id} [host]
33 if __name__
== '__main__':
34 # Use the default host if not specified
35 if len(sys
.argv
) == 4:
36 sys
.argv
.append(mygpoclient
.HOST
)
38 # Check for valid arguments
39 if len(sys
.argv
) != 5:
42 # Split arguments in local variables
43 progname
, subcommand
, username
, device_id
, host
= sys
.argv
45 # Check for valid subcommand
46 if subcommand
not in ('get', 'put'):
49 # Read password from the terminal
50 password
= getpass
.getpass("%s@%s's password: " % (username
, host
))
52 # Create the client object with username/password/host set
53 client
= simple
.SimpleClient(username
, password
, host
)
55 if subcommand
== 'get':
56 # Get the URL list and print it, one per line
57 print '\n'.join(client
.get_subscriptions(device_id
))
58 elif subcommand
== 'put':
59 # Read the URL list from standard input and upload it
60 print >>sys
.stderr
, 'Enter podcast URLs, one per line.'
61 urls
= sys
.stdin
.read().splitlines()
62 if client
.put_subscriptions(device_id
, urls
):
63 print >>sys
.stderr
, 'Upload successful.'
65 print >>sys
.stderr
, 'Could not upload list.'