File size: 1,087 Bytes
6116805
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# utils/scrap_influencers_balance.py
import requests
import pandas as pd
import json
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()
API_KEY = os.getenv('API_KEY_ETHERSCAN')
URL_ETHERSCAN = "https://api.etherscan.io/api"

def fetch_ether_balance(addresses):
    params = {
        'module': 'account',
        'action': 'balancemulti',
        'address': ','.join(addresses),
        'tag': 'latest',
        'apikey': API_KEY
    }
    response = requests.get(URL_ETHERSCAN, params=params)
    return response.json()

def main():
    # Load influencers
    with open("ressources/dict_influencers_addr.json", "r") as file:
        influencers = json.load(file)

    addresses = list(influencers.values())
    response = fetch_ether_balance(addresses)

    if response["status"] == "1":
        df_balances = pd.DataFrame(response["result"])
        df_balances.to_csv("output/influencers_balances.csv", index=False)
    else:
        print("Failed to fetch balances:", response.get("message", "Unknown error"))

if __name__ == "__main__":
    main()