Commits

Boris Buegling  committed 656509c

Added API for querying the show database and adding shows to your list.

  • Participants
  • Parent commits 72d4f97

Comments (0)

Files changed (2)

             watched = WatchedLi(watchedLiUser, watchedLiPass)
             for show in watched.shows():
                 handle_show(show, listOfShows, targetDir)
-        except:
+        except Exception, e:
+            #print e
             print 'Available shows:'
             for show in listOfShows:
                 print '\t%s' % show.keys()[0]

File watchedli.py

 ##
 
 import cookielib
+import json
 import mechanize
 import urllib
 import urllib2
 
 from BeautifulSoup import BeautifulSoup as soup
 
-BASE_URL    = 'http://watched.li/index.php'
-MARK_URL    = 'http://watched.li/following/markEpisode'
-SHOW_URL    = 'http://watched.li/show/view/'
-UNMARK_URL  = 'http://watched.li/following/unmarkEpisode'
+ADDSHOW_URL         = 'http://watched.li/following/add'
+AUTOCOMPLETE_URL    = 'http://watched.li/show/autoComplete?term=%s'
+BASE_URL            = 'http://watched.li/index.php'
+MARK_URL            = 'http://watched.li/following/markEpisode'
+SHOW_URL            = 'http://watched.li/show/view/'
+UNMARK_URL          = 'http://watched.li/following/unmarkEpisode'
 
 
 class WatchedLi:
         self.browser.form['User[pass0]'] = password
         self.browser.submit()
 
+    def addShow(self, show_id):
+        self.post_request(ADDSHOW_URL, {'show_id': show_id})
+        return True
+
+    def autocompleteShow(self, term):
+        self.browser.open(AUTOCOMPLETE_URL % term)
+
+        jsonData = '\n'.join(self.browser.response().readlines())
+        return json.loads(jsonData)
+
     def episode_action(self, url, episode_id):
         if type(episode_id) == dict:
             episode_id = episode_id['wid']