To got it working I had to install Qpython or Qpython3 and change '/storage/sdcard0/mybanknodes.txt' to '/storage/emulated/0/mybanknodes.txt'
I'm on Sammy Note4 Android 5.0.1 and what i read sdcard/emulated/0/ must be used in any android 4.2 => versions.
I'm still using my old Galaxy S2.
New version checks for stuff in current working directory, it should tell you where to put your mybanknodes.txt if it doesn't find it:
#!/usr/bin/python
import sys, os, urllib, time, datetime, urllib2, re
def felch():
#set up paths
cwd = os.getcwd()
logpath = os.path.join(cwd, "mybanknodes.log")
mybanknodespath = os.path.join(cwd, "mybanknodes.txt")
#check if mybanknodes.txt exists, if not abort
if not os.path.isfile("mybanknodes.txt"):
print 'No mybanknodes.txt file found!'
print 'Please create one here: ' + mybanknodespath
print 'Place one BCR address on each line.'
sys.exit()
#check if mybanknodes.log exists, if not create it and stick a timestamp in it
if not os.path.isfile("mybanknodes.log"):
nowtime = datetime.datetime.now()
with open(logpath, "w") as myfile:
myfile.write(str(nowtime) + "\n")
#build list of previous balances
prevbalancelist = []
floatlistold = []
with open(logpath, mode="r") as f:
#skip 1st line, instead store it as timestamp so we can compute the temporal delta - sounds fancy, eh?
timestampold = f.readline().rstrip('\n')
try:
thentime = datetime.datetime.strptime(timestampold, "%Y-%m-%d %H:%M:%S.%f")
#print 'Timestamp in mybanknodes.log: ' + str(thentime)
except:
print "Couldn't parse timestamp in mybanknodes.log!"
#carry on
a = [line.strip() for line in f]
for line in a:
#strip off 1st 17 chars, should leave us with just the numbers
prevbalancelist.append(line[17:])
#convert prevbalancelist to floats
floatlistold = [float(i) for i in prevbalancelist]
#get time for mybanknodes.log timestamp
nowtime = datetime.datetime.now()
print nowtime
#write timestamp to mybanknodes.log in writemode, incidentally erases previous file contents, making life simpler and preventing logfileaphantitis
with open(logpath, "w") as myfile:
myfile.write(str(nowtime) + "\n")
#open mybanknknodes file
print 'Felching Banknode balances...'
print 'Querying ' + mybanknodespath
#loop through lines in file and query chainz for each address
with open(mybanknodespath, mode="r") as f:
a = [line.strip() for line in f]
itemindex = 0
delta = "0"
floatdelta = 0
deltatotal = 0
total = 0
print 'Address:\tBalance:\tChange:'
for line in a:
address = line[0:34]
######################################################### need to fool cloudflare!
site = ("http://chainz.cryptoid.info/bcr/api.dws?q=getbalance&a=" + address)
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
######################################################### cloudflare hoodwinked!
req = urllib2.Request(site, headers=hdr)
try:
page = urllib2.urlopen(req)
except urllib2.HTTPError, e:
print e.fp.read()
data = page.read()
#compare data (balance we just felched) with previous balance stored in floatlistold
floatdata = float(data)
try:
old = floatlistold[itemindex]
floatdelta = floatdata - old
delta = str(floatdelta)
#print ("prevbal: " + str(old) + " - currentbal: " + str(floatdata) + " - delta: " + delta)
except IndexError:
print "Note: empty logfile as 1st run, can't compare past results."
#truncate address string to save space and print result of our little exercise
print(address[:3] + ' ... ' + address[-3:] + '\t' + data + "\t(+ " + delta + ")")
#append result for each line to mybanknodes.log
with open(logpath, "a") as myfile:
myfile.write(address[:3] + ' ... ' + address[-3:] + '\t Bal: ' + data + "\n")
#update running total
b = float(re.sub("[^0-9.]", " ", (data)))
total = total + b
#sync list item with file line
itemindex = itemindex + 1
deltatotal = deltatotal + floatdelta
#compute temporal delta!
try:
thentime = datetime.datetime.strptime(timestampold, "%Y-%m-%d %H:%M:%S.%f")
except:
print "Couldn't parse timestamp in mybanknodes.log!"
try:
delta = nowtime - thentime
#print 'Your Banknodes have earned ' + str(deltatotal) + ' BCR in ' + str(delta)
print 'Your have earned ' + str(deltatotal) + ' BCR since'
print 'last check @ ' + timestampold
print '(' + str(delta) + ' ago.)'
except:
print "Couldn't compute temporal delta!"
#print total
print "Total: " + str(total) + " BCR"
#exit
sys.exit()
#shindig!
felch()