aboutsummaryrefslogtreecommitdiff
path: root/xboomx/bin/xboomx_sort.py
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2014-09-02 11:27:50 +0200
committerVictor Häggqvist <[email protected]>2014-09-02 11:27:50 +0200
commitbcbd5bb12b3a1f89948d21a7a9bc0f056db73f38 (patch)
treef95b967cd8dec52fadba96c85cf03a635bb272f3 /xboomx/bin/xboomx_sort.py
--status
Diffstat (limited to 'xboomx/bin/xboomx_sort.py')
-rw-r--r--xboomx/bin/xboomx_sort.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/xboomx/bin/xboomx_sort.py b/xboomx/bin/xboomx_sort.py
new file mode 100644
index 0000000..a30c362
--- /dev/null
+++ b/xboomx/bin/xboomx_sort.py
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+import fileinput
+import sys
+
+import xboomx.db
+
+
+def main():
+
+ # get db type
+ db_type = ''
+ if len(sys.argv) > 1:
+ db_type = sys.argv[1]
+
+ # open shelve
+ db = xboomx.db.open_shelve(db_type)
+
+ # read lines and set weight according to db
+ items = []
+
+ for input_item in fileinput.input([]):
+ input_item = input_item.strip('\n')
+ items.append((db.get(input_item, 0), input_item))
+
+ # sort items
+ items.sort(key=lambda x: x[0], reverse=True)
+
+ # print items
+ for item in items:
+ print item[1]
+
+ # clean up
+ db.close()
+
+
+main()