Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

51
LINES

< > BotCompany Repo | #531 // Process questionnaire

Lua code

1  
get("#515") -- splitLines
2  
serpent = grab("#158")
3  
get("#532") -- getBridgeMap
4  
get("#533") -- replaceSnippetIDs
5  
6  
text = getSnippet("#2000291")
7  
lines = splitLines(text)
8  
9  
function tableToLine(snippet)
10  
  return serpent.line(snippet, {comment=0})
11  
end
12  
13  
for i=1, #lines do
14  
  line = lines[i]
15  
  
16  
  local _, _, _needBridgeID, _sourceID, _masterBridgeID = line:find("^(#%d+) %- Need bridge from (#%d+) following master bridge (#%d+)")
17  
  if _needBridgeID then
18  
    needBridgeID, sourceID, masterBridgeID = _needBridgeID, _sourceID, _masterBridgeID
19  
    masterBridgeTitle = getSnippetTitle(masterBridgeID)
20  
    idmap = getBridgeMap(masterBridgeID)
21  
    print("-- id map for master bridge "..masterBridgeID..": "..tableToLine(idmap))
22  
  end
23  
  
24  
  local _, _, verdict = line:find("^ *Your verdict: *(.*)")
25  
  if verdict then
26  
    print("-- "..needBridgeID.." / "..sourceID..": "..verdict)
27  
    
28  
    hasBridge = hasNTTitle("Bridge from "..sourceID.." to % following master bridge "..masterBridgeID)
29  
    if hasBridge then
30  
      print("-- has bridge, skipping")
31  
    elseif verdict == 'skip' or verdict == 'invalidated' then
32  
      -- Invalidate the "Need bridge" snippet
33  
      
34  
      snippet = {type='nt', title='Invalidate '..needBridgeID, text='Verdict was: '..verdict}
35  
      print("lua [[ ")
36  
      print(" create "..tableToLine(snippet))
37  
      print("]]")
38  
    elseif verdict == 'copy verbatim' then
39  
      -- assume source type is nt
40  
      sourceTitle = getSnippetTitle(sourceID)
41  
      sourceText = getSnippet(sourceID)
42  
      destTitle = replaceSnippetIDs(sourceTitle, idmap)
43  
      destText = replaceSnippetIDs(sourceText, idmap)
44  
      snippet = {type='nt', title=destTitle, text=destText}
45  
      print("lua [[ ")
46  
      print("  destID = create "..tableToLine(snippet))
47  
      print("  create {type='nt', title='Bridge from "..sourceID.." to '..destID..' following master bridge "..masterBridgeID.."', text=''}")
48  
      print("]]")
49  
    end
50  
  end
51  
end

Author comment

Began life as a copy of #2000292

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #531
Snippet name: Process questionnaire
Eternal ID of this version: #531/1
Text MD5: 70b8b3b33316433de7ce7ed6373db903
Author: stefan
Category:
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-15 03:46:07
Source code size: 1969 bytes / 51 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 699 / 161
Referenced in: [show references]