Skip to content

Instantly share code, notes, and snippets.

@kyoukaya
Created September 28, 2023 17:33
Show Gist options
  • Save kyoukaya/10a00e5001730c7a98a96db1e23a2775 to your computer and use it in GitHub Desktop.
Save kyoukaya/10a00e5001730c7a98a96db1e23a2775 to your computer and use it in GitHub Desktop.
a simple script to scrape and output a user's PD3 challenges into a csv
import http.client
from urllib.parse import urlencode
from json import loads
import csv
host = "nebula.starbreeze.com"
output_file = "out.csv"
print("username:")
username = input()
print("password:")
password = input()
conn = http.client.HTTPSConnection(host)
conn.request("POST", "/iam/v3/oauth/token?"+urlencode({
"username": username,
"password": password,
"grant_type": "password",
"client_id": "d682bcf949cb4744b3cd4295bbdd9fef",
"extend_exp": "true",
}), headers={
"Authorization": "Basic MGIzYmZkZjVhMjVmNDUyZmJkMzNhMzYxMzNhMmRlYWI6",
"Content-Type": "application/x-www-form-urlencoded"
})
resp = conn.getresponse()
assert resp.getcode() == 200
access_token = loads(resp.read())['access_token']
with open(output_file, "w", newline="") as fout:
writer = csv.DictWriter(fout, fieldnames=["name","description","status","is_active","tags","reward"])
writer.writeheader()
next_url = "/challenge/v1/public/namespaces/pd3/users/me/records?limit=500&offset=0"
while next_url != "":
conn.request("GET", next_url, headers={"Authorization": "Bearer " + access_token})
resp = conn.getresponse()
assert resp.getcode() == 200
body = loads(resp.read())
for data in body['data'] :
writer.writerow({
"name": data['challenge']["name"],
"description": data['challenge']['description'],
"status": data['status'],
"is_active": data['challenge']['isActive'],
"tags": ",".join(data['challenge']['tags']),
"reward": data['challenge']['reward'],
})
next_url = body['paging']['next']
print(f"finished parsing")
@kyoukaya
Copy link
Author

Built with some reference to https://modworkshop.net/mod/44267. I just did not want to download an electron executable to get the data out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment