-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.getfromgooglesheets.ttslua
43 lines (40 loc) · 1.49 KB
/
Global.getfromgooglesheets.ttslua
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
-- works on script button press. Proof of concept.
local playerData = {}
function onScriptingButtonUp(index, player_color)
print("downloading data")
url = "https://spreadsheets.google.com/feeds/cells/[YOURSPREADSHEETIDHERE]/1/public/full?alt=json"
WebRequest.get(
url,
function(a)
json = JSON.decode(a.text)
processSS(json)
end
)
end
function processSS(json)
local data = json.feed["entry"]
local character = ""
local keyMap = {}
print("data download complete")
print("processing data")
for k,v in pairs(data) do
if(tonumber(v["gs$cell"].row) == 1) then -- creat keymapping
if(tonumber(v["gs$cell"].col) != 1) then -- first col is characters, we dont store that key as its a table
map = tonumber(v["gs$cell"].col)
key = v["gs$cell"]["$t"]:gsub('%s+', ''):lower()
keyMap[map] = key
end
else
if(tonumber(v["gs$cell"].col) == 1) then -- first col is characters, we dont store that key as its a table
character = v["gs$cell"]["$t"]:gsub('%s+', ''):lower()
playerData[character] = {}
else
index = tonumber(v["gs$cell"].col)
local thiskey = keyMap[index]
playerData[character][thiskey] = v["gs$cell"]["$t"]:gsub('%s+', ''):lower()
end
end
end
print("processing complete")
print(playerData.sulime["1handededged"])
end