def scrap_tokens(self): while self.current_page <= self.last_page: headers = {'User-Agent': self.USER_AGENT} print_section(f'Scrapping page: {self.current_page} / {self.last_page}') response = requests.get(f'https://etherscan.io/tokens?p={self.current_page}', headers=headers) if response.status_code != 200: raise RuntimeError(f'Incorrect status code from etherscan: {response.status_code}') self.html = pq(response.content) self.get_pagination() self.extract_tokens() self.current_page += 1 if self.ignored: print_error(f'Ignored {len(self.ignored)} tokens.')
def extract_tokens(self): links = [l for l in self.html.find('#ContentPlaceHolder1_divresult tbody tr h5 a')] for l in links: address = l.attrib['href'].replace('/token/', '') name, symbol = l.text[:-1].split(' (') decimals = self.get_token_precision(address) if not decimals: print_error(f'Cannot define the number of decimal places for {name} ({symbol}). Ignoring.') self.ignored.append(name) continue token = Token(name, symbol, Web3.toChecksumAddress(address), decimals) if symbol in self.symbols: print_error(f'Duplicate symbol {symbol} for token {name}. Ignoring.') self.ignored.append(token) continue elif name in self.names: print_error(f'Duplicate name {name} for token {symbol}. Ignoring.') self.ignored.append(token) continue self.tokens.append(token) self.symbols.add(symbol) self.names.add(name) print_section(f'Tokens counter: {len(self.tokens)}.')
args = parser.parse_args() network = get_network_by_symbol(args.network) wallet = network.get_wallet(private_key=args.private_key) tx_hex = get_transaction_from_address(args.initial_network, args.transaction) print_section('Found transaction:', tx_hex) print_section('Transaction audit...') contract = network.audit_contract(args.contract, tx_hex) pprint(contract.show_details()) utxo = network.get_utxo(wallet.address, args.amount) if not utxo: print_error('UTXO not found') exit(1) print_section(f'Found {len(utxo)} UTXO\'s') pprint(utxo) participate_transaction = contract.participate( args.network.replace('_TESTNET', '').lower(), wallet.address, args.recipient, args.amount, utxo) print_section('Adding fee and signing...') participate_transaction.add_fee_and_sign(wallet) print_section('Transaction ready to be published') details = participate_transaction.show_details() pprint(details)