2 # Someone's FSInf-coin utils.
3 # Copyright (c) 2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
4 # published under MIT-License
7 # 40 12 * * * (cd ~/neo-infcoin-utils/mattermost_awards; ./main.py) &> /tmp/infcoin_awards.log
9 # awards infcoins to mm-posts.
15 import psycopg2.extras
17 from inspect import cleandoc
23 def award_infcoins(user_id, amount, reason_part):
24 infcoin_wallet = json.loads(_load_wallet(config.infcoin_wallet_uid_mappingsdir+"wallet-"+user_id+".json"))
25 if infcoin_wallet["wallet"] != "":
26 r = requests.get(config.infcoin_req_url, {"auth_name":config.infcoin_req_user, "auth_secret":config.infcoin_req_pw, "addr":infcoin_wallet["wallet"], "amount":amount, "reason_uniq":"mm-"+reason_part+", uid="+user_id})
32 def _load_wallet(path, default='{"wallet":""}'):
34 if os.path.isfile(path):
35 with open(path, "r") as f:
42 dbconn = psycopg2.connect(config.dbconnstring)
43 dbconn.set_session(autocommit=False)
47 # process awarded coins - TODO.
48 cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
49 cur.execute(""" SELECT id AS postid, userid FROM posts WHERE deleteat = 0 AND props::jsonb->>'infcoin' = '1' """)
51 for post in cur.fetchall():
52 print("awarding: "+post["userid"]+"for post: "+post["postid"])
53 award_infcoins(post["userid"], config.infcoin_req_amount, "post, pid="+post["postid"])
57 # TODO: remove old tags?