1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
"""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)
|