Spaces:
Sleeping
Sleeping
# 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() | |