-
Notifications
You must be signed in to change notification settings - Fork 3
/
nmcautoupdate.py
78 lines (65 loc) · 2.17 KB
/
nmcautoupdate.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
#!/usr/bin/env python
"""
nmcautoupdate v0.2
phelix / 2012 / nx.bit
MIT License - no guarantees
"""
randomDelayMax = 10 # make it a little more difficult to recognize the domains are from one wallet
updateAll = False # update all or only soon expiring
soonDays = 62
import pynamecoin as pnc
import time
import random
info = pnc.getinfo()
for k in info:
print ("%s: " % k) + str(info[k])
print
print "Getting list of own domains. May take a while."
nameDictList = pnc.name_list()
print "Total number of own domains in wallet: ", len(nameDictList)
earliest = 999999
earliestNd = {}
for nd in nameDictList:
if nd["expires_in"] < earliest:
earliest = nd["expires_in"]
earliestNd = nd
print "next expiry in %d blocks, %.2f days (1 block ~~~10min)" % (earliest, earliest * 10.0 / 60.0 / 24.0)
print "(" + earliestNd["name"] + " and maybe others)"
print
# Names expiring soon
soonBlocks = soonDays * 24.0 * 60.0 / 10.0
soonCount = 0
nameDictListSoon = []
for nd in nameDictList:
if nd["expires_in"] < soonBlocks:
soonCount += 1
nameDictListSoon.append(nd)
print "Number of names expiring within %d days: %d" % (soonDays, soonCount)
if not updateAll:
nameDictList = nameDictListSoon
updateCost = len(nameDictList) * 0.005
print "Updating will cost at most %.6f namecoins" % updateCost
if info["balance"] < updateCost:
print "Balance too low to update all domains. Quitting."
raise Exception("Balance too low.")
print "random delay between updates: %d seconds" % randomDelayMax
print "press enter to proceed; ctrl-c to stop"
try:
raw_input()
except KeyboardInterrupt:
raise SystemExit("manual interruption")
print "updating..."
for nd in nameDictList:
print nd["name"], pnc.escape(nd["value"])
try:
r = pnc.name_update(nd["name"], pnc.quote(pnc.escape(nd["value"])))
except pynamecoin.BitcoinError as e:
message = e.args[0]
if "pending operations" in message:
print "Pending operations on %s - skipping." % nd["name"]
pass
raise
print r
print
time.sleep(random.randint(0, randomDelayMax))
print "done. remember it will take 1 block until the update will be reflected."