aboutsummaryrefslogtreecommitdiff
path: root/xboomx/bin/xboomx_sort.py
blob: a30c3624d75d39529756427a1ca78b1a4738d7bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()