Ejemplo n.º 1
0
    def test_parse(self):
        print("parse")
        import parseXML

        comps = [17220, 21666, 12345]

        self.assertTrue(
            parseXML.parse(comps[0])["name"] == "Tiomila i Nynäshamn")
        self.assertTrue(
            parseXML.parse(comps[1])["name"] == "Markdubbeln, medel")
        self.assertTrue(parseXML.parse(comps[2])["name"] == "Motions 5-Dagars")
Ejemplo n.º 2
0
def extractElementData(apk, xml, eid):

    directoryToXML = []

    absolute_path = os.path.dirname(os.path.abspath(__file__))
    directoryName = apk.replace("_apkpure.com.apk", "")
    folderName = apk.replace(".apk", "")
    workingDirectory = f"C:\\research\\Analysis\\APK-Malicious\\{folderName}"
    #\\{folderName}"

    os.chdir(workingDirectory)

    for file in glob.iglob('**/*', recursive=True):
        if file.endswith(xml):
            directoryToXML.append(file)

    filename = f"{workingDirectory}\\{directoryToXML[0]}"

    layoutDetails = dict()
    content = ""

    with open(filename, encoding="utf8") as f:
        content = f.read()
    f.close()

    if eid in content:
        layoutDetails = parseXML.parse(eid, filename)

    return layoutDetails
Ejemplo n.º 3
0
def runXMLFileList(plaintextFilesListFilename, inputJSONFilename,
                   outputJSONFilename):
    # We'll have to go through the input JSON the same way, line by line.
    # Depending on how the line number modulos with 500, give it a new XML
    import json
    inputJSONFile = open(inputJSONFilename, 'r')
    outputJSONFile = open(outputJSONFilename, 'w')
    inputJSON = json.load(inputJSONFile)

    outputJSONList = []
    startTime = ""
    endTime = ""

    # Lists to keep track of parsed XMLs
    plaintextFilenames = open(plaintextFilesListFilename, 'r')
    xmlAlreadyParsedList = []
    xmlFilenamesList = []
    import parseXML
    for filename in plaintextFilenames:
        # Remove newline from filename
        xmlAlreadyParsedList.append(False)
        xmlFilenamesList.append(filename.rstrip('\n') + ".xml")

    # Loop through the entire input JSON file
    parsedXML = None
    for index, line in enumerate(inputJSON):
        # WARNING - magic number
        # Integer truncation shortcut
        fileIndex = index / 500
        if xmlAlreadyParsedList[fileIndex]:
            None
        else:
            xmlAlreadyParsedList[fileIndex] = True
            parsedXML = parseXML.parse(xmlFilenamesList[fileIndex])

        lineNumber = index % 500

        if (parseXML.hasLine(parsedXML, lineNumber)):
            if (parseXML.hasTwoTimesUnique(parsedXML, lineNumber)):
                (startTime, endTime) = parseXML.getTwoTimesOrderedDict(
                    parsedXML, lineNumber)

        # Add times to output JSON
        line['startTime'] = startTime
        line['endTime'] = endTime
        outputJSONList.append(line)

        # reset times
        startTime = ""
        endTime = ""

    json.dump(outputJSONList, outputJSONFile)
    outputJSONFile.close()
Ejemplo n.º 4
0
 def callback(ch, method, properties, body):
     print(" [x] Received %r" % body)
     f = open(filePath, "a")
     msg = parse(body.decode("utf-8"))
     f.write(msg + '\n')
     f.close()
Ejemplo n.º 5
0
async def on_message(message):
    logging.info(str(message.author) + ": " + str(message.content)) 


    # The bot is not supposed to answer its own messages.
    if message.author == client.user:
        return


    if message.content.startswith('!Hej'):
        msg = 'Hej {0.author.mention}'.format(message)
        await message.channel.send(msg)


    if message.content.startswith('!Hjälp'):
        msg = 'Sök efter tävling "!Sök <tävlingsnamn>" \n' + 'Hämta spurttider "!Res <tävlingsId>" t.ex. "!Res 30549" '
        await message.channel.send(msg)
    

    if message.content.startswith('!Res'):
        try:
            eventId = message.content.split(" ")[1]
            logging.info(eventId)

            try:
                results = parseXML.parse(eventId) #checks if results are allredy downloaded
                logging.info(results)
                if results == False:
                    downloadResults.download(eventId) #download results
                    results = parseXML.parse(eventId)

            except Exception as e:
                logging.info(e)
                
            try:
                res = []
                for i in range(10):
                    runner = results["results"][i]
                    res.append((runner["name"], runner["lastSplitTime"], runner["lastCcode"]))

                def Sort(sub_li): 
                    sub_li.sort(key = lambda x: x[1]) 
                    return sub_li 

                l = Sort(res)

                msg = "Topp 10 tider på spurten på: " + results["name"] + "\n"
                msg += "i Järfälla OK" + "\n"
                msg += "Datum: " + results["raceDate"] + "\n"

                msg += tabulate(l, headers=['Namn', 'Tid (s)', 'Sista kontroll'])
            
            except Exception as e:
                msg = "error"
                logging.info(e)
        except Exception as e:
            logging.info(e)
            msg = "error"
    
        await message.channel.send(msg)


    if message.content.startswith('!Sök'):
        s = message.content.replace("!Sök", " ").strip()
        msg = SearchCompetition.search(s)
            
        await message.channel.send(msg)