|
1 | 1 | import csv, os |
2 | 2 | from slugify import slugify |
3 | | -from strsimpy.jaro_winkler import JaroWinkler |
| 3 | +from strsimpy.levenshtein import Levenshtein |
| 4 | +import json |
| 5 | +from shutil import copyfile |
4 | 6 |
|
5 | | -jarowinkler = JaroWinkler() |
| 7 | +levenshtein = Levenshtein() |
6 | 8 |
|
7 | 9 | # Friday 1 October 2021 02:00:00 to unix datestamp epoch |
8 | 10 | date = 1633053600 |
9 | 11 |
|
| 12 | +os.mkdir("exported") |
| 13 | + |
| 14 | +# From the first round of ranking of the gbcompo21 |
| 15 | +# titles must match validation.csv title |
| 16 | +shortlist = [ |
| 17 | + "<corrib75>", |
| 18 | + "Core Machina", |
| 19 | + "Dango Dash", |
| 20 | + "Dawn Will Come", |
| 21 | + "El Dueloroso", |
| 22 | + "Fix My Heart", |
| 23 | + "GB Corp.", |
| 24 | + "GBCspelunky", |
| 25 | + "Glory Hunters", |
| 26 | + "Marla and the Elemental Rings DEMO", |
| 27 | + "Porklike GB", |
| 28 | + "Rebound", |
| 29 | + "Renegade Rush", |
| 30 | + "Sushi Nights", |
| 31 | + "Shock Lobster", |
| 32 | + "Unearthed", |
| 33 | + "Rhythm Land", |
| 34 | + # |
| 35 | + # |
| 36 | + "Zilogized", |
| 37 | + "HELLO WORLD", |
| 38 | +] |
| 39 | + |
| 40 | +shortlisted = 0 |
10 | 41 | with open("gbcompo21.csv", newline="") as csvfile: |
11 | 42 | spamreader = csv.DictReader(csvfile) |
12 | 43 | for row in spamreader: |
13 | | - gameObj = { |
14 | | - "title": row["title"], |
15 | | - "slug": slugify(row["title"]), |
16 | | - "developer": row["user"], |
17 | | - "typetag": "game", |
18 | | - "tags": ["gbcompo21"], |
19 | | - "website": row["game_url"], |
20 | | - "date": date, |
21 | | - } |
22 | | - if len(row["Open Source repository"]) > 1: |
23 | | - gameObj["repository"] = row["Open Source repository"] |
24 | | - gameObj["tags"].append("Open Source") |
25 | | - # if row["title"] in shortlist: |
26 | | - # gameObj["tags"].append("gbcompo21-top20") |
27 | | - |
28 | | - d = 1000000 |
29 | | - for directory in os.listdir("gbcompo21/entries"): |
30 | | - d2 = jarowinkler.distance(directory, row["title"]) |
31 | | - if d2 < d: |
32 | | - d = d2 |
33 | | - matched = directory |
34 | | - print(gameObj["title"]) |
35 | | - print(f"{row['title']} || {matched} || {d} || ") |
| 44 | + with open("validation.csv", newline="") as csvfile: |
| 45 | + validation = csv.DictReader(csvfile) |
| 46 | + for validated in validation: |
| 47 | + if validated["submission_url"] == row["submission_url"]: |
| 48 | + validated_values = validated |
| 49 | + if validated_values["Qualifies?"] == "TRUE": |
| 50 | + problematic = False |
| 51 | + typetag = validated_values["Category"].lower() |
| 52 | + if typetag == "tool": |
| 53 | + typetag = "homebrew" |
| 54 | + gameObj = { |
| 55 | + "title": row["title"], |
| 56 | + "slug": slugify(row["title"]), |
| 57 | + "developer": row["user"], |
| 58 | + "typetag": typetag, |
| 59 | + "tags": ["gbcompo21"], |
| 60 | + "website": row["game_url"], |
| 61 | + "date": date, |
| 62 | + "screenshots": [], |
| 63 | + "files": [], |
| 64 | + } |
| 65 | + if validated_values["Open Source"] == "TRUE": |
| 66 | + gameObj["repository"] = validated_values["Open Source repository"] |
| 67 | + gameObj["tags"].append("Open Source") |
| 68 | + gameObj["license"] = validated_values["OS License"] |
| 69 | + |
| 70 | + if validated_values["title"] in shortlist: |
| 71 | + gameObj["tags"].append("gbcompo21-shortlist") |
| 72 | + shortlisted += 1 |
| 73 | + else: |
| 74 | + continue |
| 75 | + |
| 76 | + # Find the folder in the gbcompo21 repository |
| 77 | + d = 1000000 |
| 78 | + for directory in os.listdir("gbcompo21/entries"): |
| 79 | + d2 = levenshtein.distance(directory, row["title"]) |
| 80 | + if d2 < d: |
| 81 | + d = d2 |
| 82 | + matched = directory |
| 83 | + # print(f"{row['title']} || {matched} || {d} || ") |
| 84 | + |
| 85 | + if d > 2: |
| 86 | + problematic = True |
| 87 | + |
| 88 | + # Create a directory: |
| 89 | + |
| 90 | + ex_gamedir = f'exported/{slugify(row["title"])}' |
| 91 | + os.mkdir(ex_gamedir) |
| 92 | + |
| 93 | + if not problematic: |
| 94 | + gamedir = f"gbcompo21/entries/{matched}" |
| 95 | + files = os.listdir(gamedir) |
| 96 | + |
| 97 | + for file in files: |
| 98 | + # Look for GB and GBC roms |
| 99 | + if file[-3:].lower() == "gbc" or file[-3:].lower() == ".gb": |
| 100 | + copyfile(f"{gamedir}/{file}", f"{ex_gamedir}/{file}") |
| 101 | + fileobj = {"playable": "true", "filename": file} |
| 102 | + gameObj["files"].append(fileobj) |
| 103 | + # Look for screenshots (pics and GIFs) |
| 104 | + if ( |
| 105 | + file[-3:].lower() == "png" |
| 106 | + or file[-3:].lower() == "jpg" |
| 107 | + or file[-3:].lower() == "gif" |
| 108 | + or file[-3:].lower() == "bmp" |
| 109 | + ): |
| 110 | + copyfile(f"{gamedir}/{file}", f"{ex_gamedir}/{file}") |
| 111 | + gameObj["screenshots"].append(file) |
| 112 | + |
| 113 | + if len(gameObj["files"]) == 0: |
| 114 | + print("No ROM files found", row["title"]) |
| 115 | + with open(f"{ex_gamedir}/game.json", "w") as fp: |
| 116 | + js = json.dumps(gameObj, indent=4) |
| 117 | + fp.write(js) |
| 118 | + |
| 119 | + # if not problematic: |
| 120 | + |
| 121 | + # Find GB or GBC files |
| 122 | + |
| 123 | + # Find screenshots |
36 | 124 |
|
37 | 125 | # print(gameObj) |
| 126 | + |
| 127 | +# Check if every shortlisted entry was found |
| 128 | +if len(shortlist) != shortlisted: |
| 129 | + print("Some shortlist tag has not been applied") |
0 commit comments