-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassets_API.py
More file actions
44 lines (32 loc) · 1.17 KB
/
Copy pathassets_API.py
File metadata and controls
44 lines (32 loc) · 1.17 KB
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
import requests
import time
import pandas as pd
def fetch_assets(page, limit, assets):
url = "https://testnets-api.opensea.io/api/v1/assets?order_direction=desc&offset={}&limit={}".format(page*limit, limit)
response = requests.request("GET", url)
for a in response.json()["assets"]:
assets.append(transform(a))
def transform(asset):
out = {}
out['id'] = asset['id']
creator = asset['creator']
if creator is not None and creator['user'] is not None and creator['user']['username'] is not None:
out['creator'] = creator['user']['username']
else:
out['creator'] = 'unknown'
out['artwork_name'] = asset['name']
out['collection'] = asset['collection']['name']
out['nsfw'] = asset['is_nsfw']
return out
def main():
nfts = []
for page in range(0,20):
fetch_assets(page, 200, nfts)
time.sleep(1)
# Create a pandas dataframe out of the list.
opensea_API_df = pd.DataFrame(nfts)
print(opensea_API_df)
# Save the dataframe in Parquet format.
opensea_API_df.to_parquet('parquet-data/opensea_API.parquet', engine='fastparquet')
if __name__ == "__main__":
main()