emerge-lastsync.py: convert lastsync.pl to Python
authorW. Trevor King <wking@tremily.us>
Thu, 6 Dec 2012 17:45:19 +0000 (12:45 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 6 Dec 2012 17:48:59 +0000 (12:48 -0500)
I don't always have Perl installed.

posts/conky/emerge-lastsync.py [new file with mode: 0755]
posts/conky/lastsync.pl [deleted file]

diff --git a/posts/conky/emerge-lastsync.py b/posts/conky/emerge-lastsync.py
new file mode 100755 (executable)
index 0000000..577977b
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/python
+#
+# Based on
+# http://conky.sourceforge.net/lastsync.pl
+
+import time
+
+syncs = []
+for line in file('/var/log/emerge.log', 'r'):
+    if not 'Sync completed' in line:
+        continue
+    sync_time = int(line[:10])
+    syncs.append(sync_time)
+
+print(time.strftime('%a, %b %e', time.localtime(syncs[-1])))
diff --git a/posts/conky/lastsync.pl b/posts/conky/lastsync.pl
deleted file mode 100755 (executable)
index 37bef03..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/perl
-use Date::Manip;
-
-$date = `grep "Sync completed" /var/log/emerge.log | tail -n1 | cut -c-10`;
-$date = &DateCalc("Jan 1, 1970  00:00:00 GMT",$date);
-$date = UnixDate("$date","%A %H:%M");
-print "$date";