bcns-gameDistributionSystem/readnfo.py
odecif 603bd11668 Added class object and tester, not finished.
The class object is to later be replacing the current nfo-file parser
and making custom class objects instead. Just about done with CPU in
SystemSpecs, next up is GPU and then later recommendedspecs.

Also a seed-script update.
2026-02-17 02:35:39 +01:00

80 lines
2.8 KiB
Python

import json
import sys
import gameobject as go
import pprint
nfofilearg = sys.argv[1]
content = ""
with open(nfofilearg, "r") as file:
content = file.read()
# TODO Better validation
try:
content = json.loads(content)
except:
print("couldn't load json, aborting")
exit
print(content)
c = content["game"]
g1 = go.Game()
keys = ["title", "originaltitle", "year", "plot", "genre", "playermodes" ,"cdkey" ,"linuxinstructions", "systemrequirements", "recommendedspecs", "recommendedspecs", "collab", "developer", "credit", "rating"]
for key in keys:
try:
assert key in c
except AssertionError:
print("###key " + key + " not in nfo-file, skipping")
keys.remove(key)
else:
sskeys = ["os", "ramsize", "cpu", "opticaldrive", "gpu", "hddpsace", "nic"]
cpukeys =["frequency", "unit", "model"]
if key == "title":
g1.title = c["title"]
if key == "originaltitle":
g1.originaltitle = c["originaltitle"]
if key == "year":
g1.year = c["year"]
if key == "plot":
g1.plot = c["plot"]
if key == "genre":
g1.genre = c["genre"]
if key == "playermodes":
g1.playermodes = c["playermodes"]
if key == "cdkey":
g1.cdkey = c["cdkey"]
if key == "linuxinstructions":
g1.linuxinstructions = c["linuxinstructions"]
if key == "systemrequirements":
sr1 = go.SystemSpecs()
csr = c["systemrequirements"]
for srkey in sskeys:
try:
assert srkey in c["systemrequirements"]
except AssertionError:
print("###key " + srkey + " not in nfo-file, skipping")
else:
if srkey == "os":
sr1.os = csr["os"]
if srkey == "ramsize":
sr1.ramsize = csr["ramsize"]
if srkey == "cpu":
cpu1 = go.SystemSpecs().CPU()
ccpu = csr["cpu"]
for cpukey in cpukeys:
try:
assert cpukey in ccpu
except AssertionError:
print("###key " + cpukey + " not in nfo-file, skipping")
else:
if cpukey == "frequency":
cpu1.frequency = ccpu["frequency"]
if cpukey == "unit":
cpu1.unit = ccpu["unit"]
if cpukey == "model":
cpu1.model = ccpu["model"]
# g1.systemrequirements = c["systemrequirements"]
# g1.recommendedspcs = c["recommendedspecs"]
pprint.pp(g1.to_dict())