Commits

Frederic De Groef committed df98c10

draft: queue error rss feed

Comments (0)

Files changed (4)

feeds/__init__.py

+  

feeds/queueerrorsfeed.py

+from django.contrib.syndication.views import Feed
+import os.path
+import csxj.db as csxjdb
+
+
+STATIC_DATA_PATH = os.path.join(os.path.dirname(__file__), '../static_data')
+
+
+def flatten_error_dict(all_errors):
+    flattened_list = list()
+
+    for name, error_dict in all_errors:
+        for date, errors in error_dict.items():
+            for hour, trace in errors.items():
+                flattened_list.append((date, hour, name, trace))
+
+    def comp_error_items(e1, e2):
+        # wtf is that shit?!
+        if e1[0] < e2[0]:
+            return -1
+        elif e1[0] == e2[0]:
+            if e1[1] == e2[1]: return -1
+            elif e1[1] == e2[1]: return 0
+            else: return 1
+        else:
+            return 1
+
+    flattened_list.sort(cmp=comp_error_items)
+
+    return flattened_list
+
+
+
+class LatestEntriesFeed(Feed):
+    title = "csxj crawler queue errors feed"
+    link = "/queue_errors_feed"
+    description = ""
+
+    def items(self):
+        return flatten_error_dict(csxjdb.get_queue_errors_for_all_sources(STATIC_DATA_PATH))
+
+
+    def item_title(self, item):
+        return "[On {0} at {1}] New queue error for {2}".format(item)
+
+
+    def item_description(self, item):
+        return item[3]
+
+
+    def item_link(self, item):
+        return "/source/{0}/queue".format(item[2])
+
+
+
+
+#if __name__=="__main__":
+#    from pprint import pprint
+#    all_errors = csxjdb.get_queue_errors_for_all_sources(STATIC_DATA_PATH)
+#
+##    pprint(all_errors)
+#
+#
+#    for err in flatten_error_dict(all_errors):
+#        print "\t", err
-from django.conf.urls.defaults import patterns, url
+from django.conf.urls import patterns, url
 
 urlpatterns = patterns(
     '',
-from django.conf.urls.defaults import patterns, include, url
+from django.conf.urls import patterns, include, url
+from feeds.queueerrorsfeed import LatestEntriesFeed
 
 # Uncomment the next two lines to enable the admin:
 #from django.contrib import admin
 urlpatterns = patterns('',
 
     url(r'^source/', include('provider.urls')),
+    url(r'^feed/queueerrors/$', LatestEntriesFeed),
     url(r'^$', 'summary.views.index'),
+
 )