import requests
from decimal import Decimal
import certifi
from collections import defaultdict


def get_transactions_by_address(address, numbers_transactions):
    url = "https://api.etherscan.io/api?module=account&action=txlist&address=" + address + \
          "&startblock=0&endblock=99999999&page=1&offset=" + str(
            numbers_transactions) + "&sort=desc&apikey=YourApiKeyToken"

    response = requests.get(url, verify=certifi.where())
    address_content = response.json()
    result = address_content.get("result")

    data = defaultdict(dict)
    for n, transaction in enumerate(result):
        hash = transaction.get("hash")
        tx_from = transaction.get("from")
        tx_to = transaction.get("to")
        value = transaction.get("value")
        confirmations = transaction.get("confirmations")
        if tx_from == address:
            out = True
        else:
            out = False

        eth_value = Decimal(value) / Decimal("1000000000000000000")
        if int(confirmations) >= 16:
            confirmed = True
        else:
            confirmed = False

        data[n]["hash"] = hash
        data[n]["tx_from"] = tx_from
        data[n]["tx_to"] = tx_to
        data[n]["eth_value"] = eth_value
        data[n]["out"] = out
        data[n]["cofirmed"] = confirmed
    return data



address1 = get_transactions_by_address("0x0110dd918f679bf94373bf03202eb0fcccba6495", 25)
print(address1)

address2 = get_transactions_by_address("0x88ee279af2e5ea4389ef88eebc4f8e1ad3001238", 500)
print(address2)