-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgene_server_dump.py
103 lines (81 loc) · 2.61 KB
/
gene_server_dump.py
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
"""
gene_server_dump v0.01
gene server dump
Copyright 2011 Brian Monkaba
This file is part of ga-bitbot.
ga-bitbot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ga-bitbot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ga-bitbot. If not, see <http://www.gnu.org/licenses/>.
"""
#
# Dumps the stored gene data from the server to a local file
#
__appversion__ = "0.01a"
print "Genetic Bitcoin Gene Server Dump v%s"%__appversion__
# connect to the xml server
#
import gene_server_config
import xmlrpclib
import json
import time
__server__ = gene_server_config.__server__
__port__ = str(gene_server_config.__port__)
#make sure the port number matches the server.
server = xmlrpclib.Server('http://' + __server__ + ":" + __port__)
print "Connected to",__server__,":",__port__
def ppdict(d):
#pretty print a dict
print "-"*40
try:
for key in d.keys():
print key,':',d[key]
except:
print d
return d
def pwdict(d,filename):
#pretty write a dict
f = open(filename,'w')
try:
for key in d.keys():
f.write(key + " : " + str(d[key]) + "\n")
except:
pass
f.write('\n' + '-'*80 + '\n')
f.write(str(d))
f.close()
return d
for quartile in [1,2,3,4]:
try:
print "-"*80
print "Quartile:",quartile
ag = json.loads(server.get(60*360,quartile))
#ppdict(ag)
print "gene last updated",time.time() - ag['time'],"seconds ago.", "SCORE:",ag['score']
pwdict(ag,'./test_data/gene_high_score_' + str(quartile))
except:
pass
print "-"*80
print "PID STATUS:"
pid_status = json.loads(server.get_pids())
#ppdict(pid_status)
pwdict(pid_status,'./test_data/pid_status')
print "-"*80
print "PID Watchdog Check (90 sec): "
for pid in pid_status.keys():
print pid,server.pid_check(pid,90)
#save all genes
for quartile in [1,2,3,4]:
gd = {'bobs':[],'high_scores':[]}
gd['high_scores'] = json.loads(server.get_all(quartile))
gd['bobs'] = json.loads(server.get_bobs(quartile))
f = open('./config/gene_server_db_backup_quartile' + str(quartile) + '.json','w')
f.write(json.dumps(gd))
f.close()
#print server.shutdown()