@@ -0,0 +1,2960 @@
+from __future__ import print_function%0A%0Aimport json%0Aimport xml.etree.ElementTree as xmlElementTree%0Aimport base64 %0Aimport os%0Aimport sys%0Afrom os.path import isfile, join%0Aimport gzip%0Aimport datetime%0Aimport random%0Aimport traceback%0Aimport sys%0A%0Aimport features_JSON%0Aimport features_XML%0A    %0AVERSION=%222018-12-13-Stacktraces%22%0A%0Adef extract(path, out_path):%0A    try:%0A        f = gzip.open (path)%0A        fo = open(out_path , 'w')%0A        stacktraces = %5B%5D%0A        sessionStartMicroTime = 0%0A%0A        # Helper function to export data so far%0A        # TODO: De-nest this function%0A        def writeDataToFile():%0A            print (json.dumps(%0A                %7B%0A                    %22StackTraces%22 : searchMap,%0A                    %22UserID%22: userId,%0A                    %22WorkspaceVersion%22: version,%0A                    %22Date%22: sessionDate,%0A                %7D), file=fo)%0A%0A        # Process each line of the session file%0A        for bytes_ln in f:%0A            ln = bytes_ln.decode(%22utf-8%22) %0A            # ln = str(ln)%0A            # print (ln)%0A            # print (type(ln))%0A            if ln.startswith(%22Downloading phase%22): # Marker from the download script, ignore%0A                continue%0A            data = json.loads(ln)%0A%0A            # Compute the first day%0A            if sessionStartMicroTime == 0:%0A                sessionStartMicroTime = int(data%5B%22MicroTime%22%5D)%0A                sessionDate = data%5B%22DateTime%22%5D.split(%22 %22)%5B0%5D%0A%0A            # Data is in base64 to protect against special characters, unpack it%0A            b64decodedData = base64.b64decode(data%5B%22Data%22%5D).decode(%22utf-8%22) %0A%0A            # Text entered into the search box%0A            if data%5B%22Tag%22%5D == %22StackTrace%22:%0A                stackTraces.append(b64decodedData)%0A%0A            # A workspace being reported%0A            if data%5B%22Tag%22%5D == %22Workspace%22:%0A                if b64decodedData == '':    # An empty workspace, ignore%0A                    continue%0A%0A                # Select which feature extraction library to use depending on what version on the file format %0A                feature_lib = None%0A                if b64decodedData.startswith(%22%3C%22):%0A                    feature_lib = features_XML%0A                else:%0A                    isJSON = True%0A                    feature_lib = features_JSON%0A%0A                # Extract version number (first time only)%0A                if (version == None):%0A                    version = feature_lib.getVersion(b64decodedData)%0A%0A            # Extract user ID (first time only)%0A            if userId == None:%0A                userId = data%5B%22UserID%22%5D%0A    except Exception as e:%0A        # If there were a problem, get the stack trace for what happeend%0A        exc_type, exc_value, exc_traceback = sys.exc_info()%0A%0A        # Log it%0A        print (e)%0A        print (path)%0A        traceback.print_tb(exc_traceback, file=sys.stdout)%0A        %0A        # Remove partial results%0A        fo.flush()%0A        os.remove(out_path)%0A    # Flush any further data to the file%0A    writeDataToFile()%0A

Add stacktrace extractor