Marcin Kasperski avatar Marcin Kasperski committed 5182764

Added example of subscribe_quickadd to sample/feed_mgmt_sample

Fixed bug in subscribe_quickadd (at least in python 2.7
post_params must be a dictionary, not list of tuples):

Traceback (most recent call last):
File "sample/feed_mgmt_sample.py", line 105, in <module>
print reader_client.subscribe_quickadd("http://sport.interia.pl&quot;)
File "/home/marcink/Private/DEV_hg/py_mekk_greader/src/mekk/greader/reader_client.py", line 264, in subscribe_quickadd
return json.loads(self._make_call(url, post_params))
File "/home/marcink/Private/DEV_hg/py_mekk_greader/src/mekk/greader/reader_client.py", line 469, in _make_call
for key, value in post_data.iteritems() ]
AttributeError: 'list' object has no attribute 'iteritems'

Comments (0)

Files changed (2)

sample/feed_mgmt_sample.py

 title("Unsubscribing")
 reader_client.unsubscribe_feed(test_feed)
 
+title("Subscribing via site url")
+feeds_to_clean = []
+for attempt in ['http://sport.pl', 'http://sport.interia.pl']:
+    reply= reader_client.subscribe_quickadd("http://sport.pl")
+    if reply['numResults']:
+        print "Subscribe succesfull"
+        print "Feed id:", reply['streamId']
+        feeds_to_clean.append(reply['streamId'].replace("feed/", "", 1))
+    else:
+        print "Subscribe failed to find a feed"
+
+if feeds_to_clean:
+    title("Unsubscribing just subscribed")
+    for feed in feeds_to_clean:
+        print "  ", feed
+        reader_client.unsubscribe_feed(feed)

src/mekk/greader/reader_client.py

     def subscribe_quickadd(self, site_url):
         """
         Subscribe to given site url.
+
+        Note: site_url is a normal address of website, Google Reader
+        will try to autodetect feed address.
+
+        Method returns a dictionary describing the call results.
+        In succesfull case it may look like:
+
+            {
+             u'numResults': 1,
+             u'query': u'http://sport.pl',
+             u'streamId': u'feed/http://rss.gazeta.pl/pub/rss/sport.xml'
+            }
+
+        In failed case (feed not found) it may look like:
+
+            {
+             u'numResults': 0,
+             u'query': u'http://sport.interia.pl',
+            }
+
         """
         url = SUBSCRIPTION_QUICKADD_URL + "?" \
               + urllib.urlencode({"ck": int(time.mktime(datetime.now().timetuple())),
                                   "client": SOURCE})
-        post_params = [("quickadd", site_url)]
-        post_params.append(("T", self._get_token()))
+        post_params = {
+            "quickadd": site_url,
+            "T": self._get_token(),
+            }
         return json.loads(self._make_call(url, post_params))
 
     def subscribe_feed(self, feed_url, title = None):
         """
-        Subscribe to given feed. Optionally set title
+        Subscribe to given feed. Optionally set title.
+
+        Note: feed should specify RSS/Atom url. See subscribe_quickadd for
+        alternate method.
         """
         return self._change_feed(feed_url, 'subscribe', title = title)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.