Created
September 28, 2023 17:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.