Created
December 25, 2020 02:44
-
-
Save traverseda/38f3d980b94067e1231295ddf623f5a7 to your computer and use it in GitHub Desktop.
This file contains 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
"""Generate books from a list of urls in tabletop simulator | |
""" | |
import sys, json, os, copy | |
bookBag={"SaveName":"","GameMode":"","Date":"","Gravity":0.5,"PlayArea":0.5,"GameType":"","GameComplexity":"","Tags":[],"Table":"","Sky":"","Note":"","Rules":"","TabStates":{},"ObjectStates":[{"Name":"Bag","Transform":{"posX":57.0064,"posY":1.26014686,"posZ":-2.550843,"rotX":1.26331825e-05,"rotY":-2.48861652e-05,"rotZ":6.62508e-06,"scaleX":1,"scaleY":1,"scaleZ":1},"Nickname":"Book Bag","Description":"","GMNotes":"","ColorDiffuse":{"r":0.7058823,"g":0.366520882,"b":0},"Locked":False,"Grid":True,"Snap":True,"IgnoreFoW":False,"MeasureMovement":False,"DragSelectable":True,"Autoraise":True,"Sticky":True,"Tooltip":True,"GridProjection":False,"HideWhenFaceDown":False,"Hands":False,"MaterialIndex":-1,"MeshIndex":-1,"LuaScript":"","LuaScriptState":"","XmlUI":"","ContainedObjects":[]}],"LuaScript":"","LuaScriptState":"","XmlUI":"","VersionNumber":""} | |
books=bookBag["ObjectStates"][0]["ContainedObjects"] | |
bookBase = { | |
"Name": "Custom_PDF", | |
"Transform": { | |
"scaleX": 1.0, | |
"scaleY": 1.0, | |
"scaleZ": 1.0 | |
}, | |
"Nickname": "", | |
"Description": "", | |
"GMNotes": "", | |
"ColorDiffuse": { | |
"r": 1.0, | |
"g": 1.0, | |
"b": 1.0 | |
}, | |
"Locked": False, | |
"Grid": True, | |
"Snap": True, | |
"IgnoreFoW": False, | |
"MeasureMovement": False, | |
"DragSelectable": True, | |
"Autoraise": True, | |
"Sticky": True, | |
"Tooltip": True, | |
"GridProjection": False, | |
"HideWhenFaceDown": False, | |
"Hands": False, | |
"CustomPDF": { | |
"PDFUrl": "", | |
"PDFPassword": "", | |
"PDFPage": 0, | |
"PDFPageOffset": 0 | |
}, | |
} | |
from urllib.parse import unquote | |
def getName(s): | |
import os | |
base=os.path.basename(s) | |
return os.path.splitext(base)[0] | |
bookBag["ObjectStates"][0]["Nickname"]=getName(sys.argv[1]) | |
data = open(sys.argv[1],"r").readlines() | |
for line in data: | |
line=line.strip() | |
line = unquote(line) | |
book=copy.deepcopy(bookBase) | |
book["Nickname"]=getName(line) | |
book["CustomPDF"]["PDFUrl"]=line | |
books.append(book) | |
out = json.dumps(bookBag, indent=2) | |
open(sys.argv[1]+".json","w+").write(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment