Beispiel #1
0
#!/usr/bin/env python
import txtr
import sys

if __name__ == "__main__":

    Txtr = txtr.txtr(auth_from="auth.txt")
    Txtr.login()
    token = Txtr.token

    try:

        lost_ids = txtr.WSDocMgmt.getUnlistedDocumentIDs(token)
        if len(lost_ids) > 0:
            print "The following document IDs are not in any list, appending to INBOX:"
            print "\t" + ("\t\n".join(lost_ids))
            Txtr.add_documents_to_list(lost_ids, append_to="INBOX")
        else:
            print "No lost documents found"

    finally:
        try:
            Txtr.logout()
        except:
            print >> sys.stderr, "Error during logout, the session token may not have been released"
Beispiel #2
0
 def do_login(self):
     ## Set up API and log in
     if hasattr(self, "txtr"): return
     
     if not (self.preferences.username and self.preferences.password):
         self.status(message=_("Please set login data in preferences"))
         return
     
     self.txtr = txtr.txtr(username=self.preferences.username, password=self.preferences.password)
     self.txtr_dirty = False
     if not DRY_RUN:
         self.status(message=None, pump_events=False) # Clear default context
         self.status("login", _("Login to txtr.com API ..."))
         result = self.txtr.login()
         self.status("login")
         
         if not result:
             self.status(message=_("Login not ok, please check username and password"))
             del self.txtr
             return
         
         self.status(message=_("Login ok"))
     
     ## Retrieve lists and set up drop-down menu
     self.status("lists", _("Retrieving user's lists ..."))
     if not DRY_RUN:
         lists, views = self.txtr.get_lists_and_views()
         inbox_id = self.txtr.get_special_list("INBOX").get("ID", None)
         trash_id = self.txtr.get_special_list("TRASH").get("ID", None)
     else:
         views = [{"name": "My Texts", "ID": "foo", "children_lists": ("bar",)}]
         lists = [{"name": "Private Texts", "ID": "bar"}, {"name": "INBOX", "ID":"baz"}]
         inbox_id = None
         trash_id = None
     
     inbox_iter = None
     for view in views:
         if view["name"] is None: continue
         
         if len(view["children_lists"]) > 0:
             last_view = self.available_lists.append(None, (view["name"], None) )
             # FIXME: Prevent the user from selecting these entries
         
         for child in view["children_lists"]:
             list = [l for l in lists if l["ID"] == child]
             if len(list) == 0: continue
             list = list[0]
             list["consumed"] = True
             
             if list["ID"] == inbox_id: list["name"] = _("Inbox")
             if list["ID"] == trash_id: list["name"] = _("Trash")
             
             if list["ID"] == inbox_id and inbox_iter is None:
                 inbox_iter = self.available_lists.prepend(last_view, (list["name"], list["ID"]) )
             else:
                 self.available_lists.append(last_view, (list["name"], list["ID"]) )
     
     for list in lists: # The remaining lists (not in any view set)
         if list.has_key("consumed") and list["consumed"]: continue
         
         if list["ID"] == inbox_id: list["name"] = _("Inbox")
         if list["ID"] == trash_id: list["name"] = _("Trash")
         
         if list["ID"] == inbox_id and inbox_iter is None:
             inbox_iter = self.available_lists.prepend(None, (list["name"], list["ID"]) )
         else:
             self.available_lists.append(None, (list["name"], list["ID"]) )
     
     if inbox_iter is not None:
         self.target.set_active_iter(inbox_iter)
     self.status("lists")
     
     lostfound = Lostfound_Dialog(parent=self, gconf_client=self.gconf_client, parent_window=self.main_window)
     if not DRY_RUN:
         lostfound.run_conditionally()