mirror of
https://github.com/twisterarmy/twister-data-guard.git
synced 2025-03-13 05:51:30 +00:00
initial commit
This commit is contained in:
parent
a6c6ab15f4
commit
13997eafc1
55
follower.py
55
follower.py
@ -1 +1,56 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Auto-following/reading bot written in Python 2 that has a mission to safe distributed data shared in the twister network
|
||||
# (https://github.com/twisterarmy/twister-data-guard)
|
||||
# This script based on the official usernameCrawler
|
||||
# (https://github.com/miguelfreitas/twister-core/blob/master/contrib/usernameCrawler.py)
|
||||
#
|
||||
# Downloaded data is cached in a python pickle file, so it may be executed
|
||||
# again and it won't need to get everything all over again (you may run it
|
||||
# from cron scripts, for example)
|
||||
|
||||
import sys, cPickle
|
||||
|
||||
dbFileName = "twisterDataGuard.pickle"
|
||||
nodeUserName = "twisterdataguard"
|
||||
|
||||
try:
|
||||
from bitcoinrpc.authproxy import AuthServiceProxy
|
||||
except ImportError as exc:
|
||||
sys.stderr.write("Error: install python-bitcoinrpc (https://github.com/jgarzik/python-bitcoinrpc)\n")
|
||||
exit(-1)
|
||||
|
||||
serverUrl = "http://user:pwd@127.0.0.1:28332"
|
||||
if len(sys.argv) > 1:
|
||||
serverUrl = sys.argv[1]
|
||||
|
||||
twister = AuthServiceProxy(serverUrl)
|
||||
|
||||
class MyDb:
|
||||
lastBlockHash = 0
|
||||
|
||||
try:
|
||||
db = cPickle.load(open(dbFileName))
|
||||
nextHash = db.lastBlockHash
|
||||
except:
|
||||
db = MyDb()
|
||||
nextHash = twister.getblockhash(0)
|
||||
|
||||
print "blockchain reading..."
|
||||
|
||||
while True:
|
||||
block = twister.getblock(nextHash)
|
||||
db.lastBlockHash = block["hash"]
|
||||
print "block", str(block["height"]) + "\r",
|
||||
usernames = block["usernames"]
|
||||
for u in usernames:
|
||||
print "follow", u
|
||||
twister.follow(nodeUserName, [u])
|
||||
if block.has_key("nextblockhash"):
|
||||
nextHash = block["nextblockhash"]
|
||||
else:
|
||||
break
|
||||
|
||||
cPickle.dump(db,open(dbFileName, "w"))
|
||||
|
||||
print "task completed."
|
||||
|
Loading…
x
Reference in New Issue
Block a user