-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharbiscrape.py
77 lines (62 loc) · 2.94 KB
/
arbiscrape.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import pandas as pd
import requests
from tqdm import tqdm
import time
import os
# Read the CSV file
addresses_df = pd.read_csv('eliminatedSybilAttackers.csv')
addresses = addresses_df['address'].tolist() # Assuming the column name is 'address'
# Base URL for the arbiscan API
base_url = "https://api.arbiscan.io/api"
# List to store all non-normal transactions
all_transactions = []
# Iterate over each address
for address in tqdm(addresses_df['address']):
# Define the parameters for the API call
params = {
"module": "account",
"action": "txlist",
"address": address,
"startblock": 0,
"endblock": 99999999,
"sort": "asc",
"apikey": "YOURAPIKEY" # Replace with your API key
}
MAX_RETRIES = 3 # Define a maximum number of retries to avoid infinite loops
for _ in range(MAX_RETRIES):
# Make the API call
response = requests.get(base_url, params=params)
# Check if the response was successful and is JSON
if response.status_code == 200 and 'application/json' in response.headers['Content-Type']:
try:
data = response.json()
# Check if 'result' is a list and not a string
if isinstance(data['result'], list):
# Filter out normal transactions
non_normal_transactions = [tx for tx in data['result'] if tx['isError'] == '1' or tx['contractAddress'] != '']
all_transactions.extend(non_normal_transactions)
break # Exit the loop if successful
else:
print(f"Unexpected response for address {address}: {data['result']}")
break # Exit the loop if there's an unexpected response
except ValueError:
print(f"Failed to parse JSON response for address {address}. Response content: {response.text}")
break # Exit the loop if there's a JSON parsing error
elif "Just a moment..." in response.text:
time.sleep(1) # Sleep for 1 second
else:
print(f"Unexpected response status or content type for address {address}.")
break # Exit the loop if there's an unexpected response status or content type
if len(all_transactions) > 50:
print("Saving to parquet file")
transactions_df = pd.DataFrame(all_transactions)
if not os.path.isfile('arbi_trx_sybils.parquet'):
transactions_df.to_parquet('arbi_trx_sybils.parquet', engine='fastparquet')
else:
transactions_df.to_parquet('arbi_trx_sybils.parquet', engine='fastparquet', append=True)
print("Saved to parquet file")
all_transactions = []
# Convert the list of transactions to a DataFrame
transactions_df = pd.DataFrame(all_transactions)
# Save the DataFrame to a parquet file
transactions_df.to_parquet('arbi_trx_sybils.parquet', engine='fastparquet', append=True)