-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrain.py
More file actions
255 lines (238 loc) · 12.7 KB
/
rain.py
File metadata and controls
255 lines (238 loc) · 12.7 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/usr/bin/env python
"""Gather list of Whitelisted projects from Gridcoin NN, call each project for team member CPIDs,
allow user to send a multi transaction to rain GRC on team members"""
__author__ = "Steven Campbell AKA Scalextrix"
__copyright__ = "Copyright 2017, Steven Campbell"
__license__ = "The Unlicense"
__version__ = "1.2"
import csv
import gc
import getpass
import json
import itertools
import os.path
import requests
import sqlite3
import sys
import time
from urllib2 import urlopen
import xml.etree.ElementTree as ET
user_account = getpass.getuser()
filename = "C:\\Users\\{}\\AppData\\Roaming\\GridcoinResearch\\reports\\DailyNeuralMagnitudeReport.csv".format(user_account)
f = open('C:\\Users\\{}\\AppData\\Roaming\\GridcoinResearch\\gridcoinresearch.conf'.format(user_account), 'rb')
for line in f:
line = line.rstrip()
if line[0:7] == 'rpcuser':
rpc_user = line[line.find('=')+1:]
if line[0:11] == 'rpcpassword':
rpc_pass = line[line.find('=')+1:]
amicable_url = "https://sech.me/boinc/Amicable/team_email_list.php?teamid=1806&xml=1"
asteroids_url = "http://asteroidsathome.net/boinc/team_email_list.php?teamid=2218&xml=1"
atlas_url = "http://atlasathome.cern.ch/team_email_list.php?teamid=1869&account_key=Y&xml=1"
burp_url = "https://burp.renderfarming.net/team_email_list.php?teamid=1285&xml=1"
collatz_url = "http://boinc.thesonntags.com/collatz/team_email_list.php?teamid=3029&xml=1"
cosmology_url = "http://www.cosmologyathome.org/team_email_list.php?teamid=3637&xml=1"
csgrid_url = "http://csgrid.org/csg/team_email_list.php?teamid=154&xml=1"
ddm_url = "http://www.distributeddatamining.org/DistributedDataMining/team_email_list.php?teamid=2176&xml=1"
einstein_url = "https://einsteinathome.org/team_email_list.php?teamid=13630&xml=1"
enigma_url = "http://www.enigmaathome.net/team_email_list.php?teamid=2937&xml=1"
find_url = "http://findah.ucd.ie/team_email_list.php?teamid=2198&xml=1"
gpugrid_url = "https://www.gpugrid.net/team_email_list.php?teamid=3493&xml=1"
gridcoin_finance_url = "finance.gridcoin.us/finance/team_email_list.php?teamid=5&xml=1"
leiden_url = "http://boinc.gorlaeus.net/team_email_list.php?teamid=1629&xml=1"
lhc_url = "http://lhcathomeclassic.cern.ch/sixtrack/team_email_list.php?teamid=8128&xml=1"
malaria_url = "http://www.malariacontrol.net/team_email_list.php?teamid=4059&xml=1"
milkyway_url = "http://milkyway.cs.rpi.edu/milkyway/team_email_list.php?teamid=6566&xml=1"
mindmodel_url = "https://mindmodeling.org/team_email_list.php?teamid=2415&xml=1"
moo_url = "http://moowrap.net/team_email_list.php?teamid=2190&xml=1"
nfs_url = "https://escatter11.fullerton.edu/nfs/team_email_list.php?teamid=2353&xml=1"
numberfields_url = "https://numberfields.asu.edu/NumberFields/team_email_list.php?teamid=2069&xml=1"
poem_url = "http://boinc.fzk.de/poem/team_email_list.php?teamid=3147&xml=1"
pogs_url = "http://pogs.theskynet.org/pogs/team_email_list.php?teamid=2020&xml=1"
primegrid_url = "https://www.primegrid.com/team_email_list.php?teamid=4469&xml=1"
rosetta_url = "https://boinc.bakerlab.org/rosetta/team_email_list.php?teamid=12575&xml=1"
sat_url = "http://sat.isa.ru/pdsat/team_email_list.php?teamid=2059&xml=1"
seti_url = "https://setiathome.berkeley.edu/team_email_list.php?teamid=145340&xml=1"
stzaki_url = "http://szdg.lpds.sztaki.hu/szdg/team_email_list.php?teamid=3502&xml=1"
tngrid_url = "https://gene.disi.unitn.it/test/team_email_list.php?teamid=61&xml=1"
vlhc_url = "http://lhcathome2.cern.ch/vLHCathome/team_email_list.php?teamid=2429&xml=1"
wcg_url = "https://www.worldcommunitygrid.org/boinc/team_email_list.php?teamid=30513&xml=1"
wuprop_url = "http://wuprop.boinc-af.org/team_email_list.php?teamid=2243&xml=1"
yafu_url = "http://yafu.myfirewall.org/yafu/team_email_list.php?teamid=260&xml=1"
yoyo_url = "http://www.rechenkraft.net/yoyo/team_email_list.php?teamid=1475&xml=1"
rain_team = raw_input("Which BOINC project to RAIN on: ").lower()
if rain_team == "amicable" or rain_team == "amicable numbers":
project_url = amicable_url
elif rain_team == "asteroids" or rain_team == "asteroids@home":
project_url = asteroids_url
elif rain_team == "atlas" or rain_team == "atlas@home":
project_url = atlas_url
elif rain_team == "burp":
project_url = burp_url
elif rain_team == "collatz" or rain_team == "collatz conjecture":
project_url = collatz_url
elif rain_team == "cosmology" or rain_team == "cosmology@home":
project_url = cosmology_url
elif rain_team == "csg" or rain_team == "csgrid" or rain_team == "citizen science grid":
project_url = csgrid_url
elif rain_team == "ddm" or rain_team == "distributed data mining":
project_url = ddm_url
elif rain_team == "einstein" or rain_team == "einstein@home":
project_url = einstein_url
elif rain_team == "enigma" or rain_team == "enigma@home":
project_url = enigma_url
elif rain_team == "find" or rain_team == "find@home":
project_url = find_url
elif rain_team == "gpugrid" or rain_team == "gpugrid.net":
project_url = gpugrid_url
elif rain_team == "gridcoin finance":
project_url = gridcoin_finance_url
elif rain_team == "leiden" or rain_team == "leiden@home":
project_url = leiden_url
elif rain_team == "lhc" or rain_team == "lhc@home":
project_url = lhc_url
elif rain_team == "malariacontrol" or rain_team == "malaria control":
project_url = malaria_url
elif rain_team == "milkyway" or rain_team == "milky way" or rain_team == "milkyway@home":
project_url = milkyway_url
elif rain_team == "mindmodeling" or rain_team == "mind modeling" or rain_team == "mindmodeling@home":
project_url = mindmodel_url
elif rain_team == "moo" or rain_team == "moowrap":
project_url = moo_url
elif rain_team == "nfs" or rain_team == "nfs@home":
project_url = nfs_url
elif rain_team == "numberfields" or rain_team == "number fields" or rain_team == "numberfields@home":
project_url = numberfields_url
elif rain_team == "poem" or rain_team == "poem@home":
project_url = poem_url
elif rain_team == "pogs" or rain_team == "skynet" or rain_team == "theskynet pogs":
project_url = pogs_url
elif rain_team == "primegrid" or rain_team == "primegrid@home":
project_url = primegrid_url
elif rain_team == "rosetta" or rain_team == "rosetta@home":
project_url = rosetta_url
elif rain_team == "sat" or rain_team == "sat@home":
project_url = sat_url
elif rain_team == "seti" or rain_team == "seti@home":
project_url = seti_url
elif rain_team == "stzaki":
project_url = stzaki_url
elif rain_team == "tngrid" or rain_team == "tn-grid":
project_url = tngrid_url
elif rain_team == "vlhc" or rain_team == "lhc@home2" or rain_team == "vlhc@home":
project_url = vlhc_url
elif rain_team == "wcg" or rain_team == "world community grid":
project_url = wcg_url
elif rain_team == "wuprop" or rain_team == "wuprop@home":
project_url = wuprop_url
elif rain_team == "yafu" or rain_team == "yafu@home":
project_url = yafu_url
elif rain_team == "yoyo" or rain_team == "yoyo@home":
project_url = yoyo_url
else:
print ("Sorry: BOINC Team not recognised, exiting in 10 seconds")
time.sleep(10)
sys.exit()
def instruct_wallet(method, params):
url = "http://127.0.0.1:9332/"
payload = json.dumps({"method": method, "params": params})
headers = {'content-type': "application/json", 'cache-control': "no-cache"}
try:
response = requests.request("POST", url, data=payload, headers=headers, auth=(rpc_user, rpc_pass))
return json.loads(response.text)
except requests.exceptions.RequestException as e:
print e
except:
print 'No response from Wallet, check Gridcoin is runnig on this machine'
mag_or_rac_rain = raw_input("Would you prefer to rain by RAC or Magnitude :").lower()
print ('WARNING: With small amounts of GRC, the total RAIN amount may slightly exceed your requested total amount due to rounding errors')
grc_amount = float(raw_input("How much GRC to rain on BOINC project: "))
account_label = raw_input("Choose Wallet Account Label from which the GRC should be taken: ")
message = raw_input("Enter if you wish to send an internal note to this transaction: ")
gridcoin_passphrase = getpass.getpass(prompt="What is your Gridcoin Wallet Passphrase: ")
instruct_wallet('walletlock', [])
pass_check = instruct_wallet('walletpassphrase', [gridcoin_passphrase, 9999999, True])
if pass_check['error'] != None:
print 'Incorrect Wallet Passphrase, exiting in 10 seconds'
time.sleep(10)
sys.exit()
# fetch Gridcoin Team Statistics XML from BOINC Project website
root = ET.parse(urlopen(project_url)).getroot()
team_cpids = [el.text for el in root.findall('.//user/cpid')]
team_racs = [el.text for el in root.findall('.//user/expavg_credit')]
team_stats = zip(*[iter(team_cpids),(team_racs)]*1)
print "BOINC project team XML Parsed"
# add Gridcoin Team Statistics to local database
conn = sqlite3.connect("C:\\Users\\%s\\AppData\\Roaming\\GridcoinResearch\\reports\\Rain.db" % user_account)
c = conn.cursor()
c.execute('''DROP TABLE IF EXISTS GRIDCOINTEAM''')
c.execute('''DROP TABLE IF EXISTS NNDATA''')
conn.commit()
conn = sqlite3.connect("C:\\Users\\%s\\AppData\\Roaming\\GridcoinResearch\\reports\\Rain.db" % user_account)
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS GRIDCOINTEAM (cpids TEXT, rac TEXT)''')
c.executemany("INSERT INTO GRIDCOINTEAM VALUES (?,?);", team_stats)
conn.commit()
print "TEAM DB created"
# fetch Nureal Network data from Gridcoin Daily NN Report and write to local database
c.execute('''CREATE TABLE IF NOT EXISTS NNDATA (cpid TEXT, LocalMagnitude TEXT, NeuralMagnitude TEXT, TotalRAC TEXT, Synced Til TEXT, Address TEXT, CPID_Valid TEXT, Witnesses TEXT)''')
filename.encode('utf-8')
with open(filename, 'rb') as NN:
reader = csv.DictReader(NN)
field = [(i['CPID'], i['LocalMagnitude'], i['NeuralMagnitude'], i['TotalRAC'], i['Synced Til'], i['Address'], i['CPID_Valid'], i['Witnesses']) for i in reader]
c.executemany("INSERT INTO NNDATA VALUES (?,?,?,?,?,?,?,?);", field)
conn.commit()
print "CSV DB created"
# fetch total Magnitude or RAC and calculate the amount of GRC to send per unit
if mag_or_rac_rain == "magnitude" or mag_or_rac_rain == "mag":
conn.text_factory = float
mag_pull = float(c.execute('select sum(NeuralMagnitude) from NNDATA where NeuralMagnitude != 0 and NeuralMagnitude is not null and CPID in (select cpids from GRIDCOINTEAM)').fetchone()[0])
conn.close()
mag_contrib = grc_amount / mag_pull
elif mag_or_rac_rain == "rac":
conn.text_factory = float
rac_pull = float(c.execute('select sum(rac) from GRIDCOINTEAM where rac != 0 and rac is not null').fetchone()[0])
conn.close()
rac_contrib = grc_amount / rac_pull
else:
sys.exit("Sorry: You must choose 'mag'/'magnitude' or 'RAC'")
del gridcoin_passphrase
gc.collect()
# get lists of Magnitude or RAC and associated addresses matching the BOINC Project Team Result
conn = sqlite3.connect("C:\\Users\\%s\\AppData\\Roaming\\GridcoinResearch\\reports\\Rain.db" % user_account)
c = conn.cursor()
conn.text_factory = str
address_db = c.execute('select Address from NNDATA where NeuralMagnitude != 0 and NeuralMagnitude is not null and CPID in (select cpids from GRIDCOINTEAM)').fetchall()
conn.text_factory = float
if mag_or_rac_rain == "magnitude" or mag_or_rac_rain == "mag":
racmag_db = c.execute('select NeuralMagnitude from NNDATA where NeuralMagnitude != 0 and NeuralMagnitude is not null and CPID in (select cpids from GRIDCOINTEAM)').fetchall()
elif mag_or_rac_rain == "rac":
racmag_db = c.execute('select rac from GRIDCOINTEAM where rac != 0 and rac is not null').fetchall()
conn.close()
address_list = list(itertools.chain(*address_db))
magnitude_list = list(itertools.chain(*racmag_db))
# make a dictionary of addresses and amounts, ensure no amount is less than the smallest GRC unit (0.00000001)
if mag_or_rac_rain == "magnitude" or mag_or_rac_rain == "mag":
call_amount = [x * mag_contrib for x in magnitude_list]
elif mag_or_rac_rain == "rac":
call_amount = [x * rac_contrib for x in magnitude_list]
call_amount = [float("{:.8f}".format(i)) for i in call_amount]
call_amount = [0.00000001 if x<=0.00000001 else x for x in call_amount]
call_insert = dict(zip(address_list, call_amount))
# unlock wallet and make the sendmany transaction
print "Gridcoin TXID:"
instruct_wallet('walletlock', [])
instruct_wallet('walletpassphrase', [gridcoin_passphrase, 9999999])
result = instruct_wallet('sendmany', [account_label, call_insert, 2, message])
if result['error'] != None:
print result['error']['message']
else:
print result['result']
# set wallet back to staking and quit
instruct_wallet('walletlock', [])
instruct_wallet('walletpassphrase', [gridcoin_passphrase, 9999999, True])
del gridcoin_passphrase
gc.collect()
print('Completed Raining, exit in 10 seconds')
time.sleep(10)
sys.exit()