Commits

Laurent Bachelier committed 46a0180

Rename module to rtorrentnotify

And some shorter code.

  • Participants
  • Parent commits 1b065f6

Comments (0)

Files changed (5)

 
 Install PyRSS2Gen.
 
-Copy rtorrent2rss to a writeable directory. The files (events.db and rt2rss.xml) will be written there.
+Copy rtorrent-notify to a writeable directory. The files (events.db and rt2rss.xml) will be written there.
 
 Note: you can also edit the additem.py file.
 
 
 Add this to your .rtorrent.rc::
 
-    system.method.set_key = event.download.finished,rtnfy_finished,"execute=~/rtorrent2rss/additem.py,FINISH,$d.get_base_path="
-    system.method.set_key = event.download.inserted_new,rtnfy_inserted,"execute=~/rtorrent2rss/additem.py,INSERT,$d.get_name="
+    system.method.set_key = event.download.finished,rtnfy_finished,"execute=~/rtorrent-notify/additem.py,FINISH,$d.get_base_path="
+    system.method.set_key = event.download.inserted_new,rtnfy_inserted,"execute=~/rtorrent-notify/additem.py,INSERT,$d.get_name="
 
 For older versions of rtorrent (pre 0.8.4)::
 
-    on_finished = rtnfy_finished,"execute=~/rtorrent2rss/additem.py,FINISH,$d.get_base_path="
-    on_start = rtnfy_started,"execute=~/rtorrent2rss/additem.py,START,$d.get_name="
+    on_finished = rtnfy_finished,"execute=~/rtorrent-notify/additem.py,FINISH,$d.get_base_path="
+    on_start = rtnfy_started,"execute=~/rtorrent-notify/additem.py,START,$d.get_name="
 
 
 Yes, it is that unreadable. ``FINISH`` and ``START`` are just strings, you can change them.
 import os
 import locale
 
-import rtorrent2rss
+import rtorrentnotify as rtn
 
 if len(sys.argv) < 3:
     print "Usage: %s TYPE NAME" % sys.argv[0]
     exit(1)
 
-dir = os.path.dirname(__file__)
-if dir:
-    os.chdir(dir)
+os.chdir(os.path.dirname(__file__))
 
 eventname = unicode(sys.argv[1], locale.getpreferredencoding())
 name = unicode(" ".join(sys.argv[2:]), locale.getpreferredencoding())
 
-event = rtorrent2rss.RTorrentEvent(eventname, name)
+event = rtn.RTorrentEvent(eventname, name)
 
-events = rtorrent2rss.RTorrentEventManager()
+events = rtn.RTorrentEventManager()
 events.load_items()
 events.append(event)
 events.save_items()

rtorrent2rss.py

-# -*- coding: UTF-8 -*-
-import datetime
-import PyRSS2Gen as rss2
-import socket
-import getpass
-import hashlib
-import pickle
-
-
-class RTorrentEvent(object):
-    def __init__(self, eventname, name):
-        self.eventname = eventname
-        self.name = name
-        self.datetime = datetime.datetime.utcnow()
-
-    def get_title(self):
-        return u"%s :: %s" % (self.eventname, self.name)
-
-    def get_guid(self):
-        return rss2.Guid("%s@%s:%s_%s" % (getpass.getuser(),
-                         socket.gethostname(),
-                         self.eventname,
-                         hashlib.md5(self.name.encode('utf-8') + str(self.datetime)).hexdigest()),
-                         False
-                         )
-
-    def get_rss_item(self):
-        item = rss2.RSSItem(
-            title=self.get_title(),
-            guid=self.get_guid(),
-            pubDate=self.datetime,
-        )
-        return item
-
-    def __unicode__(self):
-        return u"%s - %s" % (self.get_title(), self.datetime.strftime('%Y-%m-%d %H:%M'))
-
-
-class RTorrentEventManager(object):
-    def __init__(self, filename="events.db", max=20):
-        self._events = []
-        self.filename = filename
-        self.max = max
-
-    def save_items(self):
-        events = self._events[:self.max - 1]
-        pickle.dump(events, open(self.filename, "w+b"), pickle.HIGHEST_PROTOCOL)
-
-    def load_items(self):
-        try:
-            self._events = pickle.load(open(self.filename, "a+b"))
-        except EOFError:
-            # first run
-            self._events = []
-
-    def append(self, event):
-        self._events.insert(0, event)
-
-    def get_rss(self):
-        feed = rss2.RSS2(
-            title="rtorrent events for %s@%s" % (getpass.getuser(), socket.gethostname()),
-            link="http://bitbucket.org/laurentb/rtorrent2rss/",
-            description="rtorrent events",
-            lastBuildDate=datetime.datetime.utcnow(),
-            items=(event.get_rss_item() for event in self._events)
-        )
-        return feed
-
-    def __unicode__(self):
-        return u"\n".join(u"[%d] %s" % (i, event) for i, event in enumerate(self._events))

rtorrentnotify.py

+# -*- coding: UTF-8 -*-
+import datetime
+import PyRSS2Gen as rss2
+import socket
+import getpass
+import hashlib
+import pickle
+
+
+class RTorrentEvent(object):
+    def __init__(self, eventname, name):
+        self.eventname = eventname
+        self.name = name
+        self.datetime = datetime.datetime.utcnow()
+
+    def get_title(self):
+        return u"%s :: %s" % (self.eventname, self.name)
+
+    def get_guid(self):
+        return rss2.Guid("%s@%s:%s_%s" % (getpass.getuser(),
+                         socket.gethostname(),
+                         self.eventname,
+                         hashlib.md5(self.name.encode('utf-8') + str(self.datetime)).hexdigest()),
+                         False
+                         )
+
+    def get_rss_item(self):
+        item = rss2.RSSItem(
+            title=self.get_title(),
+            guid=self.get_guid(),
+            pubDate=self.datetime,
+        )
+        return item
+
+    def __unicode__(self):
+        return u"%s - %s" % (self.get_title(), self.datetime.strftime('%Y-%m-%d %H:%M'))
+
+
+class RTorrentEventManager(object):
+    def __init__(self, filename="events.db", max=20):
+        self._events = []
+        self.filename = filename
+        self.max = max
+
+    def save_items(self):
+        events = self._events[:self.max - 1]
+        pickle.dump(events, open(self.filename, "w+b"), pickle.HIGHEST_PROTOCOL)
+
+    def load_items(self):
+        try:
+            self._events = pickle.load(open(self.filename, "a+b"))
+        except EOFError:
+            # first run
+            self._events = []
+
+    def append(self, event):
+        self._events.insert(0, event)
+
+    def get_rss(self):
+        feed = rss2.RSS2(
+            title="rtorrent events for %s@%s" % (getpass.getuser(), socket.gethostname()),
+            link="https://git.p.engu.in/laurentb/rtorrent-notify/",
+            description="rtorrent events",
+            lastBuildDate=datetime.datetime.utcnow(),
+            items=(event.get_rss_item() for event in self._events)
+        )
+        return feed
+
+    def __unicode__(self):
+        return u"\n".join(u"[%d] %s" % (i, event) for i, event in enumerate(self._events))
 # -*- coding: UTF-8 -*-
 import os
 
-import rtorrent2rss
+import rtorrentnotify as rtn
 
-dir = os.path.dirname(__file__)
-if dir:
-    os.chdir(dir)
+os.chdir(os.path.dirname(__file__))
 
-events = rtorrent2rss.RTorrentEventManager()
+events = rtn.RTorrentEventManager()
 events.load_items()
 
 print unicode(events)