aboutsummaryrefslogtreecommitdiffstats
path: root/titlebot/commands/up
blob: 7aff59443c5d8d4ee1f510e2f703b5f387f45ad2 (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
#!/usr/bin/env python3
import json
from os import environ
import sys
import os
# krebs polling
import poll

f = 'suggestions.json'
db = poll.load_db(f)
votes = []
votes = sys.argv[1:]
if not votes:
    print("""usage: up number (...)
    upvotes one or more entries based on .list""")
    sys.exit(1)

voter = environ['_prefix'].split("@")[1]
voter_name =environ['_from']
for vote in votes:
    try:
        vote = int(vote)
        if vote < 0:
            raise Exception()
        if voter in db[vote]['votes']:
            print("%s, you already have voted for '%s'"%(voter_name,db[vote]['title']) )
        else:
            db[vote]['votes'][voter] = 1
            print("%s voted for '%s'"%(voter_name,db[vote]['title']))
    except:
        print("%s, voting for #%s failed" %(voter_name,vote))

poll.save_db(f,db)