Force add/edit plugins to explicitly return tag lists
authorJack Miller <jack@codezen.org>
Wed, 22 Jul 2015 08:11:21 +0000 (03:11 -0500)
committerJack Miller <jack@codezen.org>
Wed, 22 Jul 2015 08:11:21 +0000 (03:11 -0500)
My missing item fix inadvertently broke because these plugins require
everything to be done in place (so we don't overwrite our reference).
That's a shitty gotcha to have, so instead of changing my fix to operate
in place, just make it so these lists are explicitly passed and
returned.

canto_next/feed.py
plugins/reddit.py
plugins/sync-inoreader.py

index 9bf55ad..a597a85 100644 (file)
@@ -421,10 +421,7 @@ class CantoFeed(PluginHandler):
 
             try:
                 a = getattr(self, attr)
-                a(feed = self, newcontent = update_contents,
-                        tags_to_add = tags_to_add,
-                        tags_to_remove = tags_to_remove,
-                        remove_items = remove_items)
+                tags_to_add, tags_to_remove, remove_items = a(self, update_contents, tags_to_add, tags_to_remove, remove_items)
             except:
                 log.error("Error running feed item adding plugin")
                 log.error(traceback.format_exc())
@@ -438,10 +435,7 @@ class CantoFeed(PluginHandler):
 
             try:
                 a = getattr(self, attr)
-                a(feed = self, newcontent = update_contents,
-                        tags_to_add = tags_to_add,
-                        tags_to_remove = tags_to_remove,
-                        remove_items = remove_items)
+                tags_to_add, tags_to_remove, remove_items = a(self, update_contents, tags_to_add, tags_to_remove, remove_items)
             except:
                 log.error("Error running feed editing plugin")
                 log.error(traceback.format_exc())
index 6a8289f..d681974 100644 (file)
@@ -133,8 +133,8 @@ class RedditAnnotate(DaemonFeedPlugin):
                 "edit_reddit" : self.edit_reddit,
         }
 
-    def edit_reddit(self, **kwargs):
-        for entry in kwargs["newcontent"]["entries"]:
+    def edit_reddit(self, feed, newcontent, tags_to_add, tags_to_remove, remove_items):
+        for entry in newcontent["entries"]:
             if "reddit-json" not in entry:
                 debug("NO JSON, bailing")
                 continue
@@ -159,4 +159,6 @@ class RedditAnnotate(DaemonFeedPlugin):
                 entry["title"] =\
                         ("%d " % entry["reddit-score"]) + entry["title"]
 
+        return (tags_to_add, tags_to_remove, remove_items)
+
 transform_locals["reddit_score_sort"] = RedditScoreSort()
index 14c6167..e15433d 100644 (file)
@@ -293,12 +293,8 @@ class CantoFeedInoReader(DaemonFeedPlugin):
     def add_state(self, item, state):
         self._list_add(item, "canto-state", state)
 
-    def additems_inoreader(self, **kwargs):
-        feed = kwargs["feed"]
-        newcontent = kwargs["newcontent"]
-        tags_to_add = kwargs["tags_to_add"]
-        tags_to_remove = kwargs["tags_to_remove"]
-        remove_items = kwargs["remove_items"]
+    def additems_inoreader(self, feed, newcontent, tags_to_add, tags_to_remove, remove_items):
+        log.debug("PRE ADD: %s" % "\n".join([x[0]["id"] for x in tags_to_add]))
 
         stream_id = quote("feed/" + feed.URL, [])
 
@@ -365,11 +361,9 @@ class CantoFeedInoReader(DaemonFeedPlugin):
                 newcontent["entries"].append(ino_entry)
                 tags_to_add.append((ino_entry, "maintag:" + feed.name ))
 
-    def edit_inoreader_sync(self, **kwargs):
-        feed = kwargs["feed"]
-        newcontent = kwargs["newcontent"]
-        tags_to_add = kwargs["tags_to_add"]
-        tags_to_remove = kwargs["tags_to_remove"]
+        return (tags_to_add, tags_to_remove, remove_items)
+
+    def edit_inoreader_sync(self, feed, newcontent, tags_to_add, tags_to_remove, remove_items):
 
         # Add inoreader_id/categories information to the items
 
@@ -439,6 +433,7 @@ class CantoFeedInoReader(DaemonFeedPlugin):
                     tags_to_remove.append((entry, tag))
 
         api.flush_changes()
+        return (tags_to_add, tags_to_remove, remove_items)
 
 # For canto communicating to Inoreader, we tap into the relevant hooks to
 # pickup state / tag changes, and convert that into Inoreader API calls.