Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' this is still a work in progress, there's features which I want to implement
- ' like the ability to use iNet to download individual cards, and convert individual cards
- ' currently, you can use this to download the board's .json file
- ' and create a recent activity HTM file which will lump all activity in decending order together
- ' note, right click the Export JSON menu item and save the file
- #PBFORMS CREATED V1.51
- '------------------------------------------------------------------------------
- ' The first line in this file is a PB/Forms metastatement.
- ' It should ALWAYS be the first line of the file. Other
- ' PB/Forms metastatements are placed at the beginning and
- ' end of "Named Blocks" of code that should be edited
- ' with PBForms only. Do not manually edit or delete these
- ' metastatements or PB/Forms will not be able to reread
- ' the file correctly. See the PB/Forms documentation for
- ' more information.
- ' Named blocks begin like this: #PBFORMS BEGIN ...
- ' Named blocks end like this: #PBFORMS END ...
- ' Other PB/Forms metastatements such as:
- ' #PBFORMS DECLARATIONS
- ' are used by PB/Forms to insert additional code.
- ' Feel free to make changes anywhere else in the file.
- '------------------------------------------------------------------------------
- #COMPILE EXE
- #DIM ALL
- '------------------------------------------------------------------------------
- ' ** Includes **
- '------------------------------------------------------------------------------
- #PBFORMS BEGIN INCLUDES
- %USEMACROS = 1
- #IF NOT %DEF(%WINAPI)
- #INCLUDE "WIN32API.INC"
- #ENDIF
- #IF NOT %DEF(%COMMCTRL_INC)
- #INCLUDE "COMMCTRL.INC"
- #ENDIF
- #INCLUDE "PBForms.INC"
- #PBFORMS END INCLUDES
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- ' ** Constants **
- '------------------------------------------------------------------------------
- #PBFORMS BEGIN CONSTANTS
- %IDD_CONVERTJSON = 101
- %IDLB_CARDS = 1002
- %IDM_FILE_CONVERTJSON = 1003
- %IDM_FILE_RECENTACTS = 1004
- %IDM_FILE_ANALYZE = 1005
- %IDM_FILE_EXIT = 1006
- %IDR_ACCELERATOR1 = 103
- %IDR_MENU1 = 102
- %IDSB_STATUS = 1001
- #PBFORMS END CONSTANTS
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- ' ** Declarations **
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- ' ** Main Application Entry Point **
- '------------------------------------------------------------------------------
- FUNCTION PBMAIN()
- PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
- %ICC_INTERNET_CLASSES)
- ShowConverJson %HWND_DESKTOP
- END FUNCTION
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- ' ** CallBacks **
- '------------------------------------------------------------------------------
- CALLBACK FUNCTION ShowConverJsonProc()
- LOCAL FileName, FileFilter AS STRING
- LOCAL Work AS STRING
- LOCAL FileInfo AS DIRDATA
- LOCAL FileDate AS FILETIME
- LOCAL SysTime AS SYSTEMTIME
- LOCAL jFile, tFile AS QUAD
- SELECT CASE AS LONG CB.MSG
- CASE %WM_INITDIALOG
- ' Initialization handler
- CASE %WM_SIZE
- ' Dialog has been resized
- LOCAL DX, DY, SX, SY AS LONG
- CONTROL SEND CB.HNDL, %IDSB_STATUS, CB.MSG, CB.WPARAM, CB.LPARAM
- DIALOG GET CLIENT CB.HNDL TO DX, DY
- CONTROL GET SIZE CB.HNDL, %IDSB_STATUS TO SX, SY
- DY = DY - SY
- CONTROL SET LOC CB.HNDL, %IDLB_CARDS, 0, 0
- CONTROL SET SIZE CB.HNDL, %IDLB_CARDS, DX, DY
- CASE %WM_NCACTIVATE
- STATIC hWndSaveFocus AS DWORD
- IF ISFALSE CB.WPARAM THEN
- ' Save control focus
- hWndSaveFocus = GetFocus()
- ELSEIF hWndSaveFocus THEN
- ' Restore control focus
- SetFocus(hWndSaveFocus)
- hWndSaveFocus = 0
- END IF
- CASE %WM_COMMAND
- ' Process control notifications
- SELECT CASE AS LONG CB.CTL
- CASE %IDM_FILE_CONVERTJSON, %IDM_FILE_RECENTACTS
- FileFilter = CHR$("JSON Files", 0, "*.json", 0)
- DISPLAY OPENFILE CB.HNDL, , , "Select JSON File", EXE.PATH$, _
- FileFilter, "", "", _
- %OFN_ENABLESIZING OR %OFN_FILEMUSTEXIST _
- TO FileName
- IF (LEN(FileName) > 0) THEN
- Work = DIR$(FileName, TO FileInfo)
- jFile = FileInfo.LastWriteTime
- DIR$ CLOSE
- REPLACE ".json" WITH ".txt" IN Work
- Work = DIR$(Work, TO FileInfo)
- IF (LEN(Work) = 0) THEN
- tFile = jFile
- ELSE
- tFile = FileInfo.LastWriteTime
- END IF
- DIR$ CLOSE
- IF (tFile < jFile) THEN
- ConvertJson CB.HNDL, FileName
- SplitJson CB.HNDL, FileName
- END IF
- SELECT CASE AS LONG CB.CTL
- CASE %IDM_FILE_CONVERTJSON
- CreateCards CB.HNDL, FileName, "actions.mbox", %TRUE
- CreateCards CB.HNDL, FileName, "cards.mbox", %FALSE
- END SELECT
- ExtractRecentActions CB.HNDL, FileName
- END IF
- CASE %IDM_FILE_ANALYZE
- FileFilter = CHR$("JSON Files", 0, "*.json", 0)
- DISPLAY OPENFILE CB.HNDL, , , "Select JSON File", EXE.PATH$, _
- FileFilter, "", "", _
- %OFN_ENABLESIZING OR %OFN_FILEMUSTEXIST _
- TO FileName
- IF (LEN(FileName) > 0) THEN
- Work = DIR$(FileName, TO FileInfo)
- jFile = FileInfo.LastWriteTime
- DIR$ CLOSE
- REPLACE ".json" WITH ".txt" IN Work
- Work = DIR$(Work, TO FileInfo)
- IF (LEN(Work) = 0) THEN
- tFile = jFile
- ELSE
- tFile = FileInfo.LastWriteTime
- END IF
- DIR$ CLOSE
- IF (tFile < jFile) THEN
- ConvertJson CB.HNDL, FileName
- SplitJson CB.HNDL, FileName
- END IF
- AnalyzeActions CB.HNDL, FileName
- END IF
- CASE %IDM_FILE_EXIT
- DIALOG END CB.HNDL
- END SELECT
- END SELECT
- END FUNCTION
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- ' ** Dialogs **
- '------------------------------------------------------------------------------
- FUNCTION ShowConverJson(BYVAL hParent AS DWORD) AS LONG
- LOCAL lRslt AS LONG
- #PBFORMS BEGIN DIALOG %IDD_CONVERTJSON->%IDR_MENU1->%IDR_ACCELERATOR1
- LOCAL hDlg AS DWORD
- DIALOG NEW PIXELS, hParent, "Convert Json", 598, 310, 376, 343, %WS_POPUP _
- OR %WS_BORDER OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
- %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR _
- %WS_CLIPCHILDREN OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
- %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
- OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
- CONTROL ADD STATUSBAR, hDlg, %IDSB_STATUS, "Status", 0, 306, _
- 376, 19, %WS_CHILD OR %WS_VISIBLE, %WS_EX_TRANSPARENT OR %WS_EX_LEFT _
- OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
- CONTROL ADD LISTBOX, hDlg, %IDLB_CARDS, , 38, 89, 277, 147
- AttachMENU1 hDlg
- AttachACCELERATOR1 hDlg
- #PBFORMS END DIALOG
- DIALOG SHOW MODAL hDlg, CALL ShowConverJsonProc TO lRslt
- #PBFORMS BEGIN CLEANUP %IDD_CONVERTJSON
- #PBFORMS END CLEANUP
- FUNCTION = lRslt
- END FUNCTION
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- ' ** Menus **
- '------------------------------------------------------------------------------
- FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
- #PBFORMS BEGIN MENU %IDR_MENU1->%IDD_CONVERTJSON
- LOCAL hMenu AS DWORD
- LOCAL hPopUp1 AS DWORD
- MENU NEW BAR TO hMenu
- MENU NEW POPUP TO hPopUp1
- MENU ADD POPUP, hMenu, "File", hPopUp1, %MF_ENABLED
- MENU ADD STRING, hPopUp1, "Convert Json", %IDM_FILE_CONVERTJSON, %MF_ENABLED
- MENU ADD STRING, hPopUp1, "Extract Recent", %IDM_FILE_RECENTACTS, %MF_ENABLED
- MENU ADD STRING, hPopUp1, "Analyze Actions", %IDM_FILE_ANALYZE, %MF_ENABLED
- MENU ADD STRING, hPopUp1, "-", 0, 0
- MENU ADD STRING, hPopUp1, "Exit" + $TAB + "Alt+F4", %IDM_FILE_EXIT, %MF_ENABLED
- MENU ATTACH hMenu, hDlg
- #PBFORMS END MENU
- FUNCTION = hMenu
- END FUNCTION
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- ' ** Accelerators **
- '------------------------------------------------------------------------------
- #PBFORMS BEGIN ASSIGNACCEL
- FUNCTION ASSIGNACCEL(tAccel AS ACCELAPI, BYVAL wKey AS WORD, BYVAL wCmd AS _
- WORD, BYVAL byFVirt AS BYTE) AS LONG
- tAccel.fVirt = byFVirt
- tAccel.key = wKey
- tAccel.cmd = wCmd
- END FUNCTION
- #PBFORMS END ASSIGNACCEL
- '------------------------------------------------------------------------------
- '------------------------------------------------------------------------------
- FUNCTION AttachACCELERATOR1(BYVAL hDlg AS DWORD) AS DWORD
- #PBFORMS BEGIN ACCEL %IDR_ACCELERATOR1->%IDD_CONVERTJSON
- LOCAL hAccel AS DWORD
- LOCAL tAccel() AS ACCELAPI
- DIM tAccel(1 TO 1) AS ACCELAPI
- ASSIGNACCEL tAccel(1), %VK_F4, %IDM_FILE_EXIT, %FVIRTKEY OR %FALT OR %FNOINVERT
- ACCEL ATTACH hDlg, tAccel() TO hAccel
- #PBFORMS END ACCEL
- FUNCTION = hAccel
- END FUNCTION
- '------------------------------------------------------------------------------
- SUB ConvertJson(hDlg AS LONG, JsonFile AS STRING)
- LOCAL Chunk, Buffer, Work, FileName, Char, sMsg AS STRING
- LOCAL FileIn, FileOut, InQuote, Depth, CiDx, Level AS LONG
- FileName = JsonFile
- FileIn = FREEFILE
- OPEN FileName FOR BINARY AS FileIn
- REPLACE ".json" WITH ".txt" IN FileName
- FileOut = FREEFILE
- OPEN FileName FOR OUTPUT AS FileOut
- Level = 1
- Buffer = ""
- InQuote = %FALSE
- CiDx = 1
- DO
- IF (CiDx > LEN(Buffer)) THEN
- Depth = SEEK(FileIn)
- IF (Depth > LOF(FileIn)) THEN EXIT DO
- sMsg = "Converting Block "& FORMAT$(Depth) &" of "& FORMAT$(LOF(FileIn))
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, sMsg
- DIALOG DOEVENTS
- ' If (Depth > 32000) Then Exit Do
- Chunk = STRING$(4096, $TAB)
- GET #FileIn, , Chunk
- Buffer = Buffer & Chunk
- REPLACE $TAB WITH "" IN Buffer
- CiDx = 1
- END IF
- Char = MID$(Buffer, CiDx, 1)
- MID$(Buffer, CiDx, 1) = $TAB
- IF (Char <> $TAB) THEN
- IF (InQuote) THEN
- Work = Work & Char
- IF (Char = "\") THEN
- IF (CiDx = LEN(Buffer)) THEN
- ' fetch one more
- Chunk = " "
- GET #FileIn, , Chunk
- Buffer = Buffer & Chunk
- END IF
- Work = Work & MID$(Buffer, CiDx + 1, 1)
- MID$(Buffer, CiDx + 1, 1) = $TAB
- Char = $TAB
- END IF
- IF (Char = CHR$(34)) THEN
- InQuote = %FALSE
- END IF
- ELSE
- IF (Char = "{") THEN
- IF (CiDx = LEN(Buffer)) THEN
- ' fetch one more
- Chunk = " "
- GET #FileIn, , Chunk
- Buffer = Buffer & Chunk
- END IF
- IF (MID$(Buffer, CiDx + 1, 1) = "}") THEN
- Work = Work & "{}"
- MID$(Buffer, CiDx + 1, 1) = $TAB
- ELSE
- IF (LEN(Work) > 0) THEN
- DumpOutput FileOut, Level, Work
- Work = ""
- END IF
- DumpOutput FileOut, Level, "{"
- Level = Level + 1
- END IF
- ELSEIF (Char = "}") THEN
- IF (CiDx = LEN(Buffer)) THEN
- ' fetch one more
- Chunk = " "
- GET #FileIn, , Chunk
- Buffer = Buffer & Chunk
- END IF
- IF (LEN(Work) > 0) THEN
- DumpOutput FileOut, Level, Work
- Work = ""
- END IF
- Level = Level - 1
- IF (MID$(Buffer, CiDx + 1, 1) = ",") THEN
- DumpOutput FileOut, Level, "},"
- MID$(Buffer, CiDx + 1, 1) = $TAB
- ELSE
- DumpOutput FileOut, Level, "}"
- END IF
- ELSEIF (Char = ",") THEN
- Work = Work & Char
- IF (LEN(Work) > 0) THEN
- DumpOutput FileOut, Level, Work
- Work = ""
- END IF
- ELSE
- Work = Work & Char
- IF (Char = CHR$(34)) THEN
- InQuote = %TRUE
- END IF
- IF (Char = "[") THEN
- Level = Level + 1
- END IF
- IF (Char = "]") THEN
- Level = Level - 1
- END IF
- END IF ' big chain
- END IF ' InQuote
- END IF ' Char <> $TAB
- CiDx = CiDx + 1
- LOOP
- CLOSE
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
- END SUB
- SUB DumpOutput(FileOut AS LONG, Level AS LONG, Work AS STRING)
- ' this is easier to do than over testing in the above subroutine
- IF (RIGHT$(Work, 1) = "[") THEN
- PRINT #FileOut, FORMAT$(Level - 1) & STRING$((Level - 1) * 2, 32) & Work
- ELSE
- PRINT #FileOut, FORMAT$(Level) & STRING$(Level * 2, 32) & Work
- END IF
- END SUB
- SUB SplitJson(hDlg AS LONG, JsonFile AS STRING)
- LOCAL FileIn, FileOut, Depth AS LONG
- LOCAL LineCount AS LONG
- LOCAL Work, FileName AS STRING
- LOCAL SectionPath, SectionName AS STRING
- LOCAL StatusText AS STRING
- LOCAL Exported AS LONG ' boolean value
- SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
- IF (ISTRUE ISFOLDER(SectionPath)) THEN
- IF (DIR$(SectionPath &"\*.mbox") <> "") THEN
- KILL SectionPath &"\*.mbox"
- END IF
- DIR$ CLOSE
- ELSE
- MKDIR SectionPath
- END IF
- FileIn = FREEFILE
- FileName = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile) &".txt"
- OPEN FileName FOR INPUT AS FileIn
- ' global text comes first, dispose of first line and open global
- LINE INPUT #FileIn, Work
- FileOut = FREEFILE
- OPEN SectionPath & "\globals.mbox" FOR APPEND AS FileOut
- SectionName = "globals"
- LineCount = 0
- DO
- LINE INPUT #FileIn, Work
- Depth = VAL(Work)
- IF (Depth = 1) THEN EXIT DO
- IF (Depth = 3) THEN
- INCR LineCount
- StatusText = "Extracting "& SectionName &" "& FORMAT$(LineCount)
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
- DIALOG DOEVENTS
- END IF
- Exported = %FALSE
- IF ((Depth = 2) AND (INSTR(Work, "[") > 0)) THEN
- ' new section, close current, open new based on section name
- CLOSE FileOut
- SectionName = PARSE$(TRIM$(MID$(Work, 2)), ":", 1)
- REPLACE CHR$(34) WITH "" IN SectionName
- FileOut = FREEFILE
- OPEN SectionPath & "\" & SectionName & ".mbox" FOR APPEND AS FileOut
- PRINT #FileOut, Work
- Exported = %TRUE
- LineCount = 0
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, SectionName
- DIALOG DOEVENTS
- END IF
- IF ((Depth = 2) AND (INSTR(Work, "]") > 0)) THEN
- ' close current and reopen global
- IF (ISFALSE Exported) THEN
- PRINT #FileOut, Work
- END IF
- CLOSE FileOut
- FileOut = FREEFILE
- OPEN SectionPath & "\globals.mbox" FOR APPEND AS FileOut
- Exported = %TRUE
- END IF
- IF (ISFALSE Exported) THEN
- PRINT #FileOut, Work
- END IF
- LOOP
- CLOSE FileIn
- CLOSE FileOut
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
- END SUB
- SUB CreateCards(hDlg AS LONG, JsonFile AS STRING, SectionName AS STRING, kJson AS LONG)
- LOCAL FileIn, FileOut, Depth AS LONG
- LOCAL LineCount, wIndex AS LONG
- LOCAL idShort AS LONG
- LOCAL Work, FileName AS STRING
- LOCAL rFix, nFix AS STRING
- LOCAL SectionPath, CardName AS STRING
- LOCAL Char, Opener, Prefix AS STRING
- LOCAL StatusText, Card AS STRING
- LOCAL Exported AS LONG ' boolean value
- SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
- IF (ISTRUE kJson) THEN
- IF (DIR$(SectionPath &"\*.json") <> "") THEN
- KILL SectionPath &"\*.json"
- END IF
- DIR$ CLOSE
- END IF
- FileIn = FREEFILE
- OPEN SectionPath &"\"& SectionName FOR INPUT AS FileIn
- ' dispose of first item, do until depth=2
- LINE INPUT #FileIn, Work
- DO
- LINE INPUT #FileIn, Work
- Depth = VAL(Work)
- IF (Depth = 2) THEN EXIT DO
- Work = TRIM$(MID$(Work, 2))
- REPLACE CHR$(34) WITH "|" IN Work
- nFix = PARSE$(Work, "|", 2)
- REPLACE "|"& nFix WITH "|"& Prefix & nFix IN Work
- Char = RIGHT$(Work, 1)
- IF ((Char = ":") OR (Char = "[")) THEN
- Prefix = Prefix & nFix & "."
- Opener = Opener & Char
- END IF
- Char = LEFT$(Work, 1)
- IF ((Char = "]") AND (RIGHT$(Opener, 1) = "[") AND (Depth > 3)) THEN
- IF (LEN(Prefix) > 0) THEN
- wIndex = PARSECOUNT(Prefix, ".")
- Char = PARSE$(Prefix, ".", wIndex - 1) &"."
- REPLACE Char WITH "" IN Prefix
- Opener = LEFT$(Opener, LEN(Opener) - 1)
- END IF
- END IF
- IF ((Char = "}") AND (RIGHT$(Opener, 1) = ":") AND (Depth > 3)) THEN
- IF (LEN(Prefix) > 0) THEN
- wIndex = PARSECOUNT(Prefix, ".")
- Char = PARSE$(Prefix, ".", wIndex - 1) &"."
- REPLACE Char WITH "" IN Prefix
- Opener = LEFT$(Opener, LEN(Opener) - 1)
- END IF
- END IF
- Card = Card & $TAB & Work
- IF ((Depth = 3) AND (INSTR(Work, "}") > 0)) THEN
- ' we are only interested in closing brackets
- IF (ISTRUE kJson) THEN
- idShort = VAL(ExtractItemValue("data.card.idShort", Card))
- ELSE
- idShort = VAL(ExtractItemValue("idShort", Card))
- END IF
- StatusText = "Updating Card "& FORMAT$(idShort)
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
- DIALOG DOEVENTS
- FileName = SectionPath & "\card-" & FORMAT$(idShort, "000") & ".json"
- FileOut = FREEFILE
- OPEN FileName FOR APPEND AS FileOut
- PRINT #FileOut, Card
- CLOSE FileOut
- Card = ""
- END IF
- LOOP
- CLOSE FileIn
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
- END SUB
- FUNCTION ExtractItemValue(Hunter AS STRING, CardItem AS STRING) AS STRING
- LOCAL TiDx AS LONG
- LOCAL Results AS STRING
- Results = CardItem
- TiDx = INSTR(Results, "|"& Hunter &"|")
- IF (TiDx = 0) THEN
- ExtractItemValue = ""
- EXIT FUNCTION
- END IF
- Results = MID$(Results, TiDx)
- Results = PARSE$(Results, $TAB, 1)
- TiDx = INSTR(Results, ":")
- Results = MID$(Results, TiDx + 1)
- IF (RIGHT$(Results, 1) = ",") THEN
- Results = LEFT$(Results, LEN(Results) - 1)
- END IF
- ExtractItemValue = Results
- END FUNCTION
- FUNCTION ExtractDataBlock(Hunter AS STRING, CardItem AS STRING) AS STRING
- LOCAL TiDx AS LONG
- LOCAL Results AS STRING
- Results = CardItem
- TiDx = INSTR(Results, "|"& Hunter &"|")
- IF (TiDx = 0) THEN
- ExtractDataBlock = ""
- EXIT FUNCTION
- END IF
- Results = MID$(Results, TiDx)
- TiDx = INSTR(Results, "]")
- IF (TiDx = 0) THEN
- ExtractDataBlock = ""
- EXIT FUNCTION
- END IF
- Results = LEFT$(Results, TiDx)
- ExtractDataBlock = Results
- END FUNCTION
- SUB ExtractRecentActions(hDlg AS LONG, JsonFile AS STRING)
- LOCAL FileIn, FileOut, Depth AS LONG
- LOCAL LineCount, cIndex, cCount AS LONG
- LOCAL ActionIndex, CardIndex AS LONG
- LOCAL ActionCount, CheckIndex AS LONG
- LOCAL idShort, ThisID AS LONG
- LOCAL Cards(), Actions() AS STRING
- LOCAL CheckLists() AS STRING
- LOCAL Work, FileName AS STRING
- LOCAL rFix, nFix, shortUrl AS STRING
- LOCAL SectionPath AS STRING
- LOCAL Char, Opener, Prefix AS STRING
- LOCAL StatusText, Card AS STRING
- LOCAL Extraction AS LONG ' boolean value
- LOCAL CardType, CardText, CardUser AS STRING
- LOCAL CardDate, ListBefore, ListAfter AS STRING
- LOCAL CardDesc, CardName, CardData AS STRING
- LOCAL CardAttachment, CardAttachmentURL AS STRING
- LOCAL CardChecklist, CardCheckID AS STRING
- LOCAL CardLabels, DataBlock, CardColor AS STRING
- SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
- ActionIndex = 0
- REDIM Actions(ActionIndex)
- FetchDataSet hDlg, JsonFile, "\actions.mbox", Actions()
- IF (UBOUND(Actions) = 0) THEN
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Failed Action Extraction"
- EXIT SUB
- END IF
- FOR ActionIndex = 0 TO UBOUND(Actions)
- idShort = VAL(ExtractItemValue("idShort", Actions(ActionIndex)))
- Actions(ActionIndex) = ExtractItemValue("date", Actions(ActionIndex)) & Actions(ActionIndex)
- NEXT ActionIndex
- ARRAY SORT Actions(), DESCEND
- CardIndex = 0
- REDIM Cards(CardIndex)
- FetchDataSet hDlg, JsonFile, "\cards.mbox", Cards()
- IF (UBOUND(Cards) = 0) THEN
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Failed Card Extraction"
- EXIT SUB
- END IF
- FOR CardIndex = 0 TO UBOUND(Cards)
- idShort = VAL(ExtractItemValue("idShort", Cards(CardIndex)))
- Cards(CardIndex) = FORMAT$(idShort, "000") & Cards(CardIndex)
- NEXT CardIndex
- ARRAY SORT Cards(), ASCEND
- REDIM CheckLists(0)
- FetchDataSet hDlg, JsonFile, "\checklists.mbox", CheckLists()
- FileOut = FREEFILE
- FileName = PATHNAME$(PATH, JsonFile) &"actions.txt"
- OPEN FileName FOR OUTPUT AS FileOut
- PRINT #FileOut, Actions()
- CLOSE FileOut
- FileOut = FREEFILE
- FileName = PATHNAME$(PATH, JsonFile) &"cards.txt"
- OPEN FileName FOR OUTPUT AS FileOut
- PRINT #FileOut, Cards()
- CLOSE FileOut
- FileOut = FREEFILE
- FileName = PATHNAME$(PATH, JsonFile) &"checklists.txt"
- OPEN FileName FOR OUTPUT AS FileOut
- PRINT #FileOut, CheckLists()
- CLOSE FileOut
- ActionCount = 0
- FileOut = FREEFILE
- FileName = JsonFile
- REPLACE ".json" WITH ".htm" IN FileName
- OPEN FileName FOR OUTPUT AS FileOut
- PRINT #FileOut, "<head>"
- PRINT #FileOut, "<title>Recent Activity</title>"
- PRINT #FileOut, "<style>"
- PRINT #FileOut, "<!--"
- PRINT #FileOut, ".green-label { background-color: #34B27D; width: 100% }"
- PRINT #FileOut, ".yellow-label { background-color: #DBDB57; width: 100% }"
- PRINT #FileOut, ".orange-label { background-color: #E09952; width: 100% }"
- PRINT #FileOut, ".red-label { background-color: #CB4D4D; width: 100% }"
- PRINT #FileOut, ".purple-label { background-color: #9933CC; width: 100% }"
- PRINT #FileOut, ".blue-label { background-color: #4D77CB; width: 100% }"
- PRINT #FileOut, "-->"
- PRINT #FileOut, "</style>"
- PRINT #FileOut, "</head>"
- PRINT #FileOut, "<body>"
- PRINT #FileOut, FormatHtml("<table border=|1| width=|100%|>")
- DO
- Extraction = %TRUE
- ThisID = 0
- FOR ActionIndex = 0 TO UBOUND(Actions)
- IF (LEN(Actions(ActionIndex)) > 0) THEN
- CardType = ExtractItemValue("type", Actions(ActionIndex))
- idShort = VAL(ExtractItemValue("data.card.idShort", Actions(ActionIndex)))
- IF ((ThisID = 0) OR (ThisID = idShort)) THEN
- IF (ThisId = 0) THEN
- PRINT #FileOut, "</table>"
- PRINT #FileOut, "<hr />"
- PRINT #FileOut, FormatHtml("<table border=|1| width=|100%|>")
- FOR CardIndex = 0 TO UBOUND(Cards)
- ThisId = VAL(ExtractItemValue("idShort", Cards(CardIndex)))
- IF (ThisID = idShort) THEN
- shortUrl = Simple(ExtractItemValue("shortUrl", Cards(CardIndex)))
- CardName = PrintPretty(Simple(ExtractItemValue("name", Cards(CardIndex))))
- CardDesc = PrintPretty(ExtractItemValue("desc", Cards(CardIndex)))
- CardDate = WindowsTime(Simple(ExtractItemValue("dateLastActivity", Cards(CardIndex))))
- CardName = "<a href=|" & shortUrl & "| target=|trello|>" & CardName & "</a>"
- IF (ExtractItemValue("labels", Cards(CardIndex)) = "[") THEN
- DataBlock = ExtractDataBlock("labels", Cards(CardIndex))
- CardLabels = "<br />"
- cIndex = 1 ' we break on the closing curly bracket
- DO
- Work = PARSE$(DataBlock, "}", cIndex)
- CardColor = Simple(ExtractItemValue("labels.color", Work))
- IF (LEN(CardColor) = 0) THEN EXIT DO
- CardLabels = CardLabels _
- &"<div class=|"& CardColor &"-label|>" _
- & Simple(ExtractItemValue("labels.name", Work)) &"</div>"
- INCR cIndex
- LOOP
- END IF
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & CardLabels & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName & "<br>")
- IF (LEN(CardDesc) > 0) THEN
- PRINT #FileOut, FormatHtml("Desc: " & CardDesc & "</td>")
- PRINT #FileOut, "</tr>"
- ELSE
- PRINT #FileOut, "</td>"
- PRINT #FileOut, "</tr>"
- END IF
- Cards(CardIndex) = ""
- ActionCount = 0
- EXIT FOR
- END IF
- NEXT CardIndex
- END IF
- INCR ActionCount
- StatusText = "Printing Card "& FORMAT$(idShort) &"."& FORMAT$(ActionCount)
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
- DIALOG DOEVENTS
- ThisID = idShort
- Extraction = %FALSE
- CardType = ExtractItemValue("type", Actions(ActionIndex))
- CardUser = Simple(ExtractItemValue("memberCreator.fullName", Actions(ActionIndex)))
- CardName = PrintPretty(Simple(ExtractItemValue("data.card.name", Actions(ActionIndex))))
- CardDate = WindowsTime(Simple(ExtractItemValue("date", Actions(ActionIndex))))
- SELECT CASE CardType
- CASE "|addAttachmentToCard|"
- CardAttachmentUrl = Simple(ExtractItemValue("data.attachment.url", Actions(ActionIndex)))
- CardAttachment = Simple(ExtractItemValue("data.attachment.name", Actions(ActionIndex)))
- Work = "<a href=|" & CardAttachmentUrl & "| target=|trello|>" & CardAttachment & "</a>"
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- IF (LEN(CardAttachmentUrl) > 0) THEN
- PRINT #FileOut, FormatHtml("<br>" & CardUser & " attached " & Work & "</td>")
- ELSE
- PRINT #FileOut, FormatHtml("<br>" & CardUser & " attached <strike>" & CardAttachment & "</strike></td>")
- END IF
- PRINT #FileOut, "</tr>"
- CASE "|addChecklistToCard|"
- CardData = ExtractItemValue("data.checklist.name", Actions(ActionIndex))
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- PRINT #FileOut, FormatHtml("<br>" & CardUser & " Added Checklist "& CardData)
- CardCheckID = ExtractItemValue("data.checklist.id", Actions(ActionIndex))
- FOR CheckIndex = 0 TO UBOUND(CheckLists)
- IF (ExtractItemValue("id", CheckLists(CheckIndex)) = CardCheckID) THEN
- PRINT #FileOut, "<ul>"
- cCount = PARSECOUNT(CheckLists(CheckIndex), $TAB)
- FOR cIndex = 1 TO cCount
- CardCheckList = PARSE$(CheckLists(CheckIndex), $TAB, cIndex)
- Work = Simple(ExtractItemValue("checkItems.name", CardCheckList))
- IF (LEN(Work) > 0) THEN
- PRINT #FileOut, "<li>"& Work
- END IF
- NEXT cIndex
- PRINT #FileOut, "</ul>"
- EXIT FOR
- END IF
- NEXT CheckIndex
- IF (CheckIndex > UBOUND(CheckLists)) THEN
- PRINT #FileOut, "<ul>"
- PRINT #FileOut, "<li>Check List NOT Found"
- PRINT #FileOut, "</ul>"
- END IF
- PRINT #FileOut, "</td>"
- PRINT #FileOut, "</tr>"
- CASE "|addMemberToBoard|"
- ' this should not be found
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- PRINT #FileOut, FormatHtml("<br>" & CardUser & " Added Member To Board</td>")
- CASE "|addMemberToCard|"
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- PRINT #FileOut, FormatHtml("<br>" & CardUser & " joined Card</td>")
- PRINT #FileOut, "</tr>"
- CASE "|commentCard|"
- CardText = PrintPretty(ExtractItemValue("data.text", Actions(ActionIndex)))
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName & "<br>")
- PRINT #FileOut, FormatHtml("Comment: " & CardUser)
- PRINT #FileOut, FormatHtml("<p>" & CardText & "</p>")
- PRINT #FileOut, "</td>"
- PRINT #FileOut, "</tr>"
- CASE "|createCard|"
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- PRINT #FileOut, FormatHtml("<br>" & CardUser & " Created Card</td>")
- PRINT #FileOut, "</tr>"
- CASE "|deleteAttachmentFromCard|"
- CardAttachment = Simple(ExtractItemValue("data.attachment.name", Actions(ActionIndex)))
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- PRINT #FileOut, FormatHtml("<br>" & CardUser & " deleted " & CardAttachment & "</td>")
- PRINT #FileOut, "</tr>"
- CASE "|updateCard|"
- ListAfter = Simple(ExtractItemValue("data.listAfter.name", Actions(ActionIndex)))
- IF (LEN(ListAfter) > 0) THEN
- ListBefore = Simple(ExtractItemValue("data.listBefore.name", Actions(ActionIndex)))
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- PRINT #FileOut, FormatHtml("<br>--- " & CardUser & " Moved Card To " & ListAfter & "</td>")
- PRINT #FileOut, "</tr>"
- END IF
- Work = Simple(ExtractItemValue("data.card.closed", Actions(ActionIndex)))
- IF (Work = "true") THEN
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- PRINT #FileOut, FormatHtml("<br>--- " & CardUser & " Closed this card.</td>")
- PRINT #FileOut, "</tr>"
- END IF
- CASE "|updateCheckItemStateOnCard|"
- ' we are not going to parse this?
- CASE "|updateChecklist|"
- CardData = ExtractItemValue("data.checklist.name", Actions(ActionIndex))
- PRINT #FileOut, "<tr>"
- PRINT #FileOut, FormatHtml("<td width=|10%| valign=|top|>Card: " & FORMAT$(idShort) & "</td>")
- PRINT #FileOut, FormatHtml("<td width=|90%| valign=|top|>" & CardDate & " - " & CardName)
- PRINT #FileOut, FormatHtml("<br>" & CardUser & " Updated Checklist "& CardData &"</td>")
- PRINT #FileOut, "</tr>"
- END SELECT
- Actions(ActionIndex) = ""
- END IF
- END IF
- NEXT ActionIndex
- IF (ISTRUE Extraction) THEN EXIT DO
- LOOP
- PRINT #FileOut, "</table>"
- PRINT #FileOut, "</body>"
- CLOSE FileOut
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
- END SUB
- FUNCTION FormatHtml(Work AS STRING) AS STRING
- DIM Results AS STRING
- Results = Work
- REPLACE CHR$(34) WITH """ IN Results
- REPLACE "|" WITH CHR$(34) IN Results
- REPLACE $CRLF WITH "<br />"& $CRLF IN Results
- REPLACE "<p></p>" WITH ""& $CRLF IN Results
- FormatHtml = Results
- END FUNCTION
- FUNCTION Simple(CardItem AS STRING) AS STRING
- LOCAL Results AS STRING
- Results = CardItem
- REPLACE "<" WITH "<" IN Results
- REPLACE ">" WITH ">" IN Results
- REPLACE "|" WITH "" IN Results
- Simple = Results
- END FUNCTION
- FUNCTION PrintPretty(CardItem AS STRING) AS STRING
- ' this is where all the parsing and making pretty happen for those cards that need it
- LOCAL Results AS STRING
- ' strip trailing comma
- Results = CardItem
- IF (RIGHT$(Results, 1) = ",") THEN
- Results = LEFT$(Results, LEN(Results) - 1)
- END IF
- ' convert escaped elements
- IF (INSTR(Results, "\") > 0) THEN
- REPLACE "\n" WITH $CRLF IN Results
- REPLACE "\|" WITH CHR$(34) IN Results
- REPLACE "\\`" WITH "`" IN Results
- REPLACE "\\@" WITH "@" IN Results
- REPLACE "\\#" WITH "#" IN Results
- REPLACE "\\*" WITH "*" IN Results
- REPLACE "\\" WITH "\" IN Results
- END IF
- PrintPretty = Simple(Results)
- END FUNCTION
- FUNCTION WindowsTime(CardItem AS STRING) AS STRING
- LOCAL DateString, TimeString AS STRING
- DateString = PARSE$(CardItem, "T", 1)
- TimeString = PARSE$(CardItem, "T", 2)
- TimeString = PARSE$(TimeString, ".", 1)
- WindowsTime = DateString &" "& TimeString
- END FUNCTION
- FUNCTION EnumerateItemNames(Hunter AS STRING, CardItem AS STRING, PriorHunter AS STRING) AS STRING
- LOCAL Work AS STRING
- LOCAL TiDx AS LONG
- Work = CardItem
- IF (LEN(PriorHunter) > 0) THEN
- TiDx = INSTR(Work, PriorHunter)
- Work = MID$(Work, TiDx + LEN(PriorHunter))
- END IF
- TiDx = INSTR(Work, "|"& Hunter)
- IF (TiDx = 0) THEN
- EnumerateItemNames = ""
- EXIT FUNCTION
- END IF
- Work = MID$(Work, TiDx)
- Work = PARSE$(Work, $TAB, 1)
- TiDx = INSTR(Work, ":")
- Work = LEFT$(Work, TiDx - 1)
- EnumerateItemNames = Work
- END FUNCTION
- SUB AnalyzeActions(hDlg AS LONG, JsonFile AS STRING)
- LOCAL FileOut AS LONG
- LOCAL ActionIndex AS LONG
- LOCAL ActionNames() AS STRING
- LOCAL Work, FileName AS STRING
- LOCAL ActionTypes, Samples AS STRING
- LOCAL StatusText AS STRING
- LOCAL CardType, Hunter, PriorHunter AS STRING
- ActionIndex = 0
- REDIM ActionNames(ActionIndex)
- FetchDataSet hDlg, JsonFile, "\actions.mbox", ActionNames()
- IF (UBOUND(ActionNames) = 0) THEN
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Failed Action Extraction"
- END IF
- FOR ActionIndex = 0 TO UBOUND(ActionNames)
- StatusText = "Analyzing Action "& FORMAT$(ActionIndex)
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
- DIALOG DOEVENTS
- CardType = ExtractItemValue("type", ActionNames(ActionIndex))
- IF (INSTR(ActionTypes, CardType) = 0) THEN
- ActionTypes = ActionTypes & CardType
- END IF
- IF (CardType = "|updateCard|") THEN
- Hunter = "data"
- PriorHunter = ""
- DO
- Work = EnumerateItemNames(Hunter, ActionNames(ActionIndex), PriorHunter)
- IF (LEN(Work) = 0) THEN EXIT DO
- PriorHunter = Work
- IF (INSTR(Samples, Work) = 0) THEN
- Samples = Samples & Work &":"& ExtractItemValue(Simple(Work), ActionNames(ActionIndex)) & $TAB
- END IF
- LOOP
- END IF
- NEXT ActionIndex
- FileOut = FREEFILE
- FileName = PATHNAME$(PATH, JsonFile) &"analyze.txt"
- OPEN FileName FOR OUTPUT AS FileOut
- REPLACE "||" WITH "|"& $TAB &"|" IN ActionTypes
- ActionIndex = 1
- DO
- Work = PARSE$(ActionTypes, $TAB, ActionIndex)
- IF (LEN(Work) = 0) THEN EXIT DO
- PRINT #FileOut, Work
- INCR ActionIndex
- LOOP
- ActionIndex = 1
- DO
- Work = PARSE$(Samples, $TAB, ActionIndex)
- IF (LEN(Work) = 0) THEN EXIT DO
- PRINT #FileOut, Work
- INCR ActionIndex
- LOOP
- CLOSE FileOut
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, "Done"
- END SUB
- SUB FetchDataSet(hDlg AS DWORD, JsonFile AS STRING, BoxName AS STRING, BYREF DataItems() AS STRING)
- LOCAL FileIn, DataIndex, Depth AS LONG
- LOCAL wIndex, idShort AS LONG
- LOCAL StatusText AS STRING
- LOCAL SectionPath, Work, Card AS STRING
- LOCAL nFix, Prefix, Char, Opener AS STRING
- SectionPath = PATHNAME$(PATH, JsonFile) & PATHNAME$(NAME, JsonFile)
- FileIn = FREEFILE
- OPEN SectionPath & BoxName FOR INPUT AS FileIn
- ' dispose of first item, do until depth=2
- LINE INPUT #FileIn, Work
- DataIndex = 0
- REDIM DataItems(DataIndex)
- DO
- LINE INPUT #FileIn, Work
- Depth = VAL(Work)
- IF (Depth = 2) THEN EXIT DO
- Work = TRIM$(MID$(Work, 2))
- REPLACE CHR$(34) WITH "|" IN Work
- nFix = PARSE$(Work, "|", 2)
- REPLACE "|"& nFix WITH "|"& Prefix & nFix IN Work
- Char = RIGHT$(Work, 1)
- IF ((Char = ":") OR (Char = "[")) THEN
- Prefix = Prefix & nFix & "."
- Opener = Opener & Char
- END IF
- Char = LEFT$(Work, 1)
- IF ((Char = "]") AND (RIGHT$(Opener, 1) = "[") AND (Depth > 3)) THEN
- IF (LEN(Prefix) > 0) THEN
- wIndex = PARSECOUNT(Prefix, ".")
- Char = PARSE$(Prefix, ".", wIndex - 1) &"."
- REPLACE Char WITH "" IN Prefix
- Opener = LEFT$(Opener, LEN(Opener) - 1)
- END IF
- END IF
- IF ((Char = "}") AND (RIGHT$(Opener, 1) = ":") AND (Depth > 3)) THEN
- IF (LEN(Prefix) > 0) THEN
- wIndex = PARSECOUNT(Prefix, ".")
- Char = PARSE$(Prefix, ".", wIndex - 1) &"."
- REPLACE Char WITH "" IN Prefix
- Opener = LEFT$(Opener, LEN(Opener) - 1)
- END IF
- END IF
- Card = Card & $TAB & Work
- IF ((Depth = 3) AND (INSTR(Work, "}") > 0)) THEN
- ' we are only interested in closing brackets
- StatusText = "Reading "& BoxName &": "& FORMAT$(DataIndex)
- STATUSBAR SET TEXT hDlg, %IDSB_STATUS, 1, 0, StatusText
- DIALOG DOEVENTS
- REDIM PRESERVE DataItems(DataIndex)
- DataItems(DataIndex) = Card
- INCR DataIndex
- Card = ""
- END IF
- LOOP
- CLOSE FileIn
- END SUB
Advertisement
Add Comment
Please, Sign In to add comment