Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
money of contract
import requests
from bs4 import BeautifulSoup
import os
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def formatAddress(address):
if len(address) == 42:
return address
else:
return "0x" + "0"*(42 - len(address)) + address[2::]
def getContractMoney(address):
address = formatAddress(address)
url = "https://etherscan.io/address/{}#code"
response = requests.get(url.format(address))
text = response.text
soup = BeautifulSoup(text, "lxml")
tds = soup.find_all('td')
if tds[3].text.strip() != u"$0":
return tds[3].text.strip()
else:
return None
def logRead(filename):
with open(filename) as f:
log = f.read()
address = log[log.find("Address=") + len("Address="):log.find("******")]
address = format(address)
value = getContractMoney(address)
if value != None:
print(address)
print(value)
return True
else:
return False
def main():
if len(sys.argv) < 2:
return
src = sys.argv[1]
if not os.path.exists(src):
return
files = os.listdir(src)
for one in files:
try:
if logRead('{}/{}'.format(src, one)):
print(one)
except Exception as e:
print("err: {}".format(one))
print(e)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment