Created
November 29, 2018 07:27
-
-
Save syang-ng/980d2156c1e086abc1374ae272f0e735 to your computer and use it in GitHub Desktop.
money of contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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