Skip to content

Instantly share code, notes, and snippets.

@danker
Last active August 6, 2023 22:13
Show Gist options
  • Save danker/fe45b6a9925cd1e88b6f28f0f1d26263 to your computer and use it in GitHub Desktop.
Save danker/fe45b6a9925cd1e88b6f28f0f1d26263 to your computer and use it in GitHub Desktop.
Otherdeeds Scraper
import requests
import time
import csv
MAX_DEEDS = 1000
BASE_URL = "https://api.otherside.xyz/lands"
SLEEPY_TIME = .5
# --------------------------------------------------------------------------
def printDetails(response, showJSON):
if (showJSON):
print(response)
print("--------- DETAILS ---------")
num_traits = len(response['attributes'])
traits = []
for trait_idx in range(num_traits):
trait_type = response['attributes'][trait_idx]['trait_type']
trait_value = response['attributes'][trait_idx]['value']
print(f"(INDEX {trait_idx}) - {trait_type}:{trait_value}")
# --------------------------------------------------------------------------
with open('otherdeeds.csv', 'w', newline='') as file:
fields = ["Category", "Sediment", "Sediment Tier", "Environment", "Environment Tier", "Eastern Resource",
"Eastern Resource Tier", "Southern Resource", "Southern Resource Tier", "Western Resource",
"Western Resource Tier", "Northern Resource", "Northern Resource Tier", "Plot",
"Obelisk Piece", "Koda", "Artifact"]
writer = csv.DictWriter(file, fields)
writer.writeheader()
for seq in range(MAX_DEEDS):
r = requests.get(f'{BASE_URL}/{seq}')
response = r.json()
print(f"LAND #{seq}")
printDetails(response, False)
num_traits = len(response['attributes'])
traits = {}
# create a dict of all traits to pass into the CSVWriter.writerow
for trait_idx in range(num_traits):
trait_type = response['attributes'][trait_idx]['trait_type']
trait_value = response['attributes'][trait_idx]['value']
traits[trait_type] = trait_value
writer.writerow(traits)
# don't just hammer the API
time.sleep(SLEEPY_TIME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment