Skip to content

Commit

Permalink
Change title parser to use regex (#21)
Browse files Browse the repository at this point in the history
* Change title parser to use regex

* Fix incorrect extraction method

* Fix incorrect regex
  • Loading branch information
AB1908 authored May 6, 2020
1 parent a90fd5f commit 900dc18
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions galaxy_library_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import time
import csv
import re


database_location = "C:\\ProgramData\\GOG.com\\Galaxy\\storage\\galaxy-2.0.db"
Expand Down Expand Up @@ -38,6 +39,7 @@
cursor.execute(owned_game_database)
cursor.execute(owned_game_filtered_data)
cursor.execute(unique_game_data)
title_regex = re.compile(r"""(?<=\{"title":").*(?="})""")
with open("gameDB.csv", "w", encoding='utf-8', newline='') as csvfile:
fieldnames = ['title', 'platformList', 'developers', 'publishers', 'releaseDate', 'genres', 'themes', 'criticsScore', 'gameMins']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
Expand All @@ -49,8 +51,8 @@
# For json.load() to work correctly, all double quotes must be correctly escaped
metadata = json.loads(result[2].replace('"','\"'))
row = metadata
row['title'] = result[1].split('"')[3]
row['title'] = row['title'].replace("\\","")
row['title'] = result[1].replace("\\","")
row['title'] = title_regex.findall(row["title"])[0]
row['platformList'] = []
if any(platform in releaseKey for platform in platforms for releaseKey in result[0].split(",")):
row['platformList'] = set(platforms[platform] for releaseKey in result[0].split(",") for platform in platforms if releaseKey.startswith(platform))
Expand Down

0 comments on commit 900dc18

Please sign in to comment.