Skip to content

Instantly share code, notes, and snippets.

@book000
Last active December 8, 2022 14:00
Show Gist options
  • Save book000/5592cf3ebe3034f02bc50c3b3dfffc2c to your computer and use it in GitHub Desktop.
Save book000/5592cf3ebe3034f02bc50c3b3dfffc2c to your computer and use it in GitHub Desktop.
import json
def json2csv(username: str):
with open("data/" + username + ".json") as f:
items = json.load(f)
rows = []
for item in items:
for result in item["results"]:
rows.append([item["owner"], item["full_name"], result["path"], result["html_url"]])
with open("data/" + username + ".csv", "w") as f:
f.write("owner,full_name,path,url\n")
for row in rows:
f.write(",".join(row) + "\n")
def merge(*usernames):
rows = []
for username in usernames:
with open("data/" + username + ".csv") as f:
rows.extend(f.readlines()[1:])
with open("data/merged.csv", "w") as f:
f.write("owner,name,path,url\n")
for row in rows:
f.write(row)
def main():
json2csv("book000")
json2csv("tomacheese")
merge("book000", "tomacheese")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment