-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (40 loc) · 1.49 KB
/
main.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
import json
import os
from time import sleep
import requests
OPENSEA_API_KEY = os.environ["OPENSEA_API_KEY"]
BAYC_CONTRACT_ADDRESS = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
def fetch_nft(asset_contract_address: str, token_id: int) -> str:
url = f"https://api.opensea.io/api/v2/chain/ethereum/contract/{asset_contract_address}/nfts/{token_id}"
response = requests.get(
url, headers={"X-API-KEY": OPENSEA_API_KEY},
)
return response.json()["nft"]
def _get_last_stolen_token_id():
if not os.path.exists("stolen.txt"):
return 0
with open("stolen.txt", "r") as stolen_file:
return int(stolen_file.readlines()[-1])
def main():
total_stolen = 0
first_token_id = _get_last_stolen_token_id() + 1
with open("stolen.txt", "a") as stolen_file:
for token_id in range(first_token_id, 10001):
message = "not stolen"
while True:
try:
nft = fetch_nft(BAYC_CONTRACT_ADDRESS, token_id)
break
except Exception:
print("Failed - retrying")
sleep(0.1)
if nft["is_suspicious"] or nft["is_disabled"]:
message = "stolen"
total_stolen += 1
stolen_file.write(f"{token_id}\n")
print(f"{token_id} - {message}")
# rate limit
sleep(0.2)
print(f"Total stolen: {total_stolen}")
if __name__ == "__main__":
main()