forked from miracle2k/linuxutils
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-google-reader-subscriptions.py
More file actions
Latest commit
executable file
·87 lines (64 loc) · 2.37 KB
/
Copy pathexport-google-reader-subscriptions.py
File metadata and controls
executable file
·87 lines (64 loc) · 2.37 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# coding: utf8
"""Export your Google Reader subscriptions to OPML format.
2011 by Michael Elsdörfer. Consider this public domain.
This script depends on the libgreader library:
https://github.com/askedrelic/libgreader/
Which be installed via:
$ easy_install libgreader
Usage:
$ export-google-reader-subscriptions username password
If the password is not given, it is queried via stdin. The final
OPML is written to stdout.
"""
importsys
importxml.etree.ElementTreeasET
try:
importlibgreader
exceptImportError:
print"libgreader not installed. Use easy_install libgreader"
else:
fromlibgreaderimportGoogleReader, ClientAuthMethod
defmain():
iflen(sys.argv) <=1orlen(sys.argv) >3:
print("Usage: %s username [password]"% (sys.argv[0]))
return1
username=sys.argv[1]
iflen(sys.argv) ==2:
sys.stderr.write('Password for %s: '%username)
password=raw_input()
else:
password=sys.argv[2]
auth=ClientAuthMethod(username, password)
reader=GoogleReader(auth)
root=ET.Element('opml')
head=ET.SubElement(root, 'head')
ET.SubElement(head, 'title').text= \
'%s subscriptions in Google Reader'%username
body=ET.SubElement(root, 'body')
category_els= {}
reader.buildSubscriptionList()
forfeedinreader.getSubscriptionList():
iffeed.getCategories():
forcategoryinfeed.getCategories():
# Create category element
ifnotcategory.idincategory_els:
category_el=ET.SubElement(body, 'outline')
category_el.set('text', category.label)
category_el.set('title', category.label)
category_els[category.id] =category_el
make_feed_el(feed, category_els[category.id])
else:
make_feed_el(feed, body)
tree=ET.ElementTree(root)
tree.write(sys.stdout, xml_declaration=True)
defmake_feed_el(feed, parent):
feed_el=ET.SubElement(parent, 'outline')
feed_el.set('text', feed.title)
feed_el.set('title', feed.title)
feed_el.set('type', 'rss')
feed_el.set('xmlUrl', feed.feedUrl)
# seems to be always empty; possible a bug in libgreader?
feed_el.set('htmlUrl', feed.siteUrlor'')
if__name__=='__main__':
sys.exit(main() or0)