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 * * * * (cd ~/gitstuff/neo-infcoin-utils/vowi_awards; ./infcoin_process_changes.py) &> /tmp/infcoin_process_changes.py.log
9 # awards infcoins to vowi-contributions.
25 def process_recent_mw_changes(mws):
27 with open('data/infcoin_process_changes-'+mws.host+'.json') as file_handle:
28 changes = json.load(file_handle)
31 if 'delme' in changes:
34 if 'revid' not in changes:
35 changes['revid'] = 138500
37 if 'infcoin_addr' not in changes:
38 changes['infcoin_addr'] = dict()
40 max_revid = mws.recentchanges().next()['revid']
41 print("revid:"+str(changes['revid'])+", max_revid:"+str(max_revid))
43 # Iterate over all revisions since the last run and find wallet addresses.
44 for i in range(changes['revid'], max_revid):
45 revision = mws.revisions([i])
48 revision = revision[0]
49 changes['revid'] = revision['revid']
51 if len(revision['comment'].strip()) < 34 or "minor" in revision or "bot" in revision:
54 infcoin_addr = revision['comment'].strip().split()
55 infcoin_addr = infcoin_addr[len(infcoin_addr)-1]
56 if not (len(infcoin_addr) == 34 and infcoin_addr.isalnum() and infcoin_addr.isascii()):
59 if infcoin_addr in changes['infcoin_addr']:
60 changes['infcoin_addr'][infcoin_addr].add(revision['revid'])
62 changes['infcoin_addr'][infcoin_addr] = set([revision['revid']])
65 # request coins for all changes
66 for addr,revs in changes['infcoin_addr'].copy().items():
67 print("processing:"+addr)
69 requests.get(config.infcoin_req_url, {"auth_name":config.infcoin_req_user, "auth_secret":config.infcoin_req_pw, "addr":addr, "amount":config.infcoin_req_amount, "reason_uniq":"wiki-"+mws.host+", revid="+str(rev)})
71 del changes['infcoin_addr'][addr]
72 with open('data/infcoin_process_changes-'+mws.host+'.json', 'w') as file_handle:
73 json.dump(changes, file_handle)
76 # warn if not all were processed.
77 if len(changes['infcoin_addr']) != 0:
78 print('Some requests failed!')
79 pprint.pprint(changes)
83 if __name__ == '__main__':
84 def signal_handler(signal, frame):
85 print('SIG received. exitting!')
87 signal.signal(signal.SIGINT, signal_handler)
89 mws = mwclient.Site(config.mw_name, path='/', retry_timeout=120)
90 mws.login(config.mw_user, config.mw_user_pw)
92 process_recent_mw_changes(mws)