Код: Выделить всё
from telethon import TelegramClient, events
import re
from config import CHAINS
import aiohttp
client = TelegramClient("telegram", api_id, api_hash)
def extract_info(input_string):
# Define regular expressions to extract information
chain_pattern = r'New (.*?) token'
token_name_pattern = r'Basescan: (.*?)\n'
supply_pattern = r'Total supply: (.*?)\n'
symbol_pattern = r'Symbol: (.*?)\n'
contract_pattern = r'Contract: (.*?)\n'
balance_pattern = r'Deployer balance: (.*?)\n'
# Initialize the dictionary to store extracted information
final = {}
# Extract information using regular expressions
final['chain'] = re.search(chain_pattern, input_string).group(1)
final['token_name'] = re.search(token_name_pattern, input_string).group(1)
final['supply'] = re.search(supply_pattern, input_string).group(1)
final['token_symbol'] = re.search(symbol_pattern, input_string).group(1)
final['contract'] = re.search(contract_pattern, input_string).group(1)
final['deployer_balance'] = re.search(balance_pattern, input_string).group(1)
return final
@client.on(events.NewMessage(chats=["basetokencreations"]))
async def handler(event):
msg = event.message
final = extract_info(msg.message)
query_params = {
"module": "contract",
"action": "getsourcecode",
"address": final['contract'],
"apikey": CHAINS[chain]['API_KEY'],
}
async with aiohttp.ClientSession() as session:
async with session.get(CHAINS[chain]["ENDPOINT"], params=query_params) as response:
token_contract_source_code = await response.json()
print(final, token_contract_source_code)
if __name__ == "__main__":
chain="base"
client.start()
client.run_until_disconnected()
Код: Выделить всё
{'status': '1', 'message': 'OK', 'result': [{'SourceCode': '', 'ABI': 'Contract source code not verified', 'ContractName': '', 'CompilerVersion': '', 'OptimizationUsed': '', 'Runs': '', 'ConstructorArguments': '', 'EVMVersion': 'Default', 'Library': '', 'LicenseType': 'Unknown', 'Proxy': '0', 'Implementation': '', 'SwarmSource': ''}]}
Подробнее здесь: https://stackoverflow.com/questions/784 ... ously-in-p