def main(params=None):
    """
    Main function to launch usufy.

    The function is created in this way so as to let other applications make
    use of the full configuration capabilities of the application. The
    parameters received are used as parsed by this modules `getParser()`.

    Args:
    -----
        params: A list with the parameters as grabbed by the terminal. It is
            None when this is called by an entry_point. If it is called by osrf
            the data is already parsed.

    Returns:
    --------
        dict: A Json representing the matching results.
    """
    if params == None:
        parser = getParser()
        args = parser.parse_args(params)
    else:
        args = params

    print(general.title(banner.text))

    sayingHello = """
      Usufy | Copyright (C) Yaiza Rubio & Félix Brezo (i3visio) 2014-2018

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. For additional info,
visit <{}>.

""".format(general.LICENSE_URL)
    print(general.info(sayingHello))

    if args.fuzz:
        res = fuzzUsufy(args.fuzz, args.fuzz_config)
    else:
        # Recovering the list of platforms to be launched
        listPlatforms = platform_selection.getPlatformsByName(platformNames=args.platforms, tags=args.tags, mode="usufy", excludePlatformNames=args.exclude)

        if args.info:
            # Information actions...
            if args.info == 'list_platforms':
                infoPlatforms="Listing the platforms:\n"
                for p in listPlatforms:
                    infoPlatforms += "\t\t" + (str(p) + ": ").ljust(16, ' ') + str(p.tags)+"\n"
                return infoPlatforms
            elif args.info == 'list_tags':
                tags = {}
                # Going through all the selected platforms to get their tags
                for p in listPlatforms:
                    for t in p.tags:
                        if t not in tags.keys():
                            tags[t] = 1
                        else:
                            tags[t] += 1
                infoTags = "List of tags:\n"
                # Displaying the results in a sorted list
                for t in tags.keys():
                    infoTags += "\t\t" + (t + ": ").ljust(16, ' ') + str(tags[t]) + "  time(s)\n"
                return infoTags
            else:
                pass

        # performing the test
        elif args.benchmark:
            platforms = platform_selection.getAllPlatformNames("usufy")
            res = benchmark.doBenchmark(platforms)
            strTimes = ""
            for e in sorted(res.keys()):
                strTimes += str(e) + "\t" + str(res[e]) + "\n"
            return strTimes

        # showing the tags of the usufy platforms
        elif args.show_tags:
            tags = platform_selection.getAllPlatformNamesByTag("usufy")
            print(general.info("This is the list of platforms grouped by tag.\n"))
            print(json.dumps(tags, indent=2, sort_keys=True))
            print(general.info("[Tip] Remember that you can always launch the platform using the -t option followed by any of the aforementioned.\n"))
            return tags

        # Executing the corresponding process...
        else:
            # Showing the execution time...
            startTime= dt.datetime.now()
            print(str(startTime) + "\tStarting search in " + general.emphasis(str(len(listPlatforms))) + " platform(s)... Relax!\n")
            print(general.emphasis("\tPress <Ctrl + C> to stop...\n"))

            # Defining the list of users to monitor
            nicks = []
            if args.nicks:
                for n in args.nicks:
                    # TO-DO
                    #     A trick to avoid having the processing of the properties when being queried by Maltego
                    if "properties.i3visio" not in n:
                        nicks.append(n)
            else:
                # Reading the nick files
                try:
                    nicks = args.list.read().splitlines()
                except:
                    print(general.error("ERROR: there has been an error when opening the file that stores the nicks.\tPlease, check the existence of this file."))

            # Definning the results
            res = []

            if args.output_folder != None:
                # if Verifying an output folder was selected
                if not os.path.exists(args.output_folder):
                    os.makedirs(args.output_folder)
                # Launching the process...
                res = processNickList(nicks, listPlatforms, args.output_folder, avoidProcessing = args.avoid_processing, avoidDownload = args.avoid_download, nThreads=args.threads, verbosity= args.verbose, logFolder=args.logfolder)

            else:
                try:
                    res = processNickList(nicks, listPlatforms, nThreads=args.threads, verbosity= args.verbose, logFolder=args.logfolder)
                except Exception as e:
                    print(general.error("Exception grabbed when processing the nicks: " + str(e)))
                    print(general.error(traceback.print_stack()))

            # We are going to iterate over the results...
            strResults = "\t"

            # Structure returned
            """
            [
                {
                  "attributes": [
                    {
                      "attributes": [],
                      "type": "i3visio.uri",
                      "value": "http://twitter.com/i3visio"
                    },
                    {
                      "attributes": [],
                      "type": "i3visio.alias",
                      "value": "i3visio"
                    },
                    {
                      "attributes": [],
                      "type": "i3visio.platform",
                      "value": "Twitter"
                    }
                  ],
                  "type": "i3visio.profile",
                  "value": "Twitter - i3visio"
                }
                ,
                ...
            ]
            """
            for r in res:
                # The format of the results (attributes) for a given nick is a list as follows:

                for att in r["attributes"]:
                    # iterating through the attributes
                    platform = ""
                    uri = ""
                    for details in att["attributes"]:
                        if details["type"] == "i3visio.platform":
                            platform = details["value"]
                        if details["type"] == "i3visio.uri":
                            uri = details["value"]
                    try:
                        strResults+= (str(platform) + ":").ljust(16, ' ')+ " "+ str(uri)+"\n\t\t"
                    except:
                        pass

            # Generating summary files for each ...
            if args.extension:
                # Verifying if the outputPath exists
                if not os.path.exists (args.output_folder):
                    os.makedirs(args.output_folder)

                # Grabbing the results
                fileHeader = os.path.join(args.output_folder, args.file_header)

                # Iterating through the given extensions to print its values
                for ext in args.extension:
                    # Generating output files
                    general.exportUsufy(res, ext, fileHeader)

            now = dt.datetime.now()
            print("\n{}\tResults obtained:\n".format(str(now)))
            print(general.success(general.usufyToTextExport(res)))

            if args.web_browser:
                general.openResultsInBrowser(res)

            now = dt.datetime.now()
            print("\n" + str(now) + "\tYou can find all the information here:")
            for ext in args.extension:
                # Showing the output files
                print("\t" + general.emphasis(fileHeader + "." + ext))

            # Showing the execution time...
            endTime= dt.datetime.now()
            print("\n" + str(endTime) +"\tFinishing execution...\n")
            print("Total time consumed:\t" + general.emphasis(str(endTime-startTime)))
            print("Average seconds/query:\t" + general.emphasis(str((endTime-startTime).total_seconds()/len(listPlatforms))) +" seconds\n")

            # Urging users to place an issue on Github...
            print(banner.footer)

    if params:
        return res
def main ( params = None ) : if params == None : parser = getParser ( ) args = parser . parse_args ( params ) else : args = params print ( general . title ( banner . text ) ) sayingHello = """
      Usufy | Copyright (C) Yaiza Rubio & Félix Brezo (i3visio) 2014-2018
This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. For additional info,
visit <{}>.
""" . format ( general . LICENSE_URL ) print ( general . info ( sayingHello ) ) if args . fuzz : res = fuzzUsufy ( args . fuzz , args . fuzz_config ) else : listPlatforms = platform_selection . getPlatformsByName ( platformNames = args . platforms , tags = args . tags , mode = "usufy" , excludePlatformNames = args . exclude ) if args . info : if args . info == 'list_platforms' : infoPlatforms = "Listing the platforms:\n" for p in listPlatforms : infoPlatforms += "\t\t" + ( str ( p ) + ": " ) . ljust ( 16 , ' ' ) + str ( p . tags ) + "\n" return infoPlatforms elif args . info == 'list_tags' : tags = { } for p in listPlatforms : for t in p . tags : if t not in tags . keys ( ) : tags [ t ] = 1 else : tags [ t ] += 1 infoTags = "List of tags:\n" for t in tags . keys ( ) : infoTags += "\t\t" + ( t + ": " ) . ljust ( 16 , ' ' ) + str ( tags [ t ] ) + "  time(s)\n" return infoTags else : pass elif args . benchmark : platforms = platform_selection . getAllPlatformNames ( "usufy" ) res = benchmark . doBenchmark ( platforms ) strTimes = "" for e in sorted ( res . keys ( ) ) : strTimes += str ( e ) + "\t" + str ( res [ e ] ) + "\n" return strTimes elif args . show_tags : tags = platform_selection . getAllPlatformNamesByTag ( "usufy" ) print ( general . info ( "This is the list of platforms grouped by tag.\n" ) ) print ( json . dumps ( tags , indent = 2 , sort_keys = True ) ) print ( general . info ( "[Tip] Remember that you can always launch the platform using the -t option followed by any of the aforementioned.\n" ) ) return tags else : startTime = dt . datetime . now ( ) print ( str ( startTime ) + "\tStarting search in " + general . emphasis ( str ( len ( listPlatforms ) ) ) + " platform(s)... Relax!\n" ) print ( general . emphasis ( "\tPress <Ctrl + C> to stop...\n" ) ) nicks = [ ] if args . nicks : for n in args . nicks : if "properties.i3visio" not in n : nicks . append ( n ) else : try : nicks = args . list . read ( ) . splitlines ( ) except : print ( general . error ( "ERROR: there has been an error when opening the file that stores the nicks.\tPlease, check the existence of this file." ) ) res = [ ] if args . output_folder != None : if not os . path . exists ( args . output_folder ) : os . makedirs ( args . output_folder ) res = processNickList ( nicks , listPlatforms , args . output_folder , avoidProcessing = args . avoid_processing , avoidDownload = args . avoid_download , nThreads = args . threads , verbosity = args . verbose , logFolder = args . logfolder ) else : try : res = processNickList ( nicks , listPlatforms , nThreads = args . threads , verbosity = args . verbose , logFolder = args . logfolder ) except Exception as e : print ( general . error ( "Exception grabbed when processing the nicks: " + str ( e ) ) ) print ( general . error ( traceback . print_stack ( ) ) ) strResults = "\t" """
            [
                {
                  "attributes": [
                    {
                      "attributes": [],
                      "type": "i3visio.uri",
                      "value": "http://twitter.com/i3visio"
                    },
                    {
                      "attributes": [],
                      "type": "i3visio.alias",
                      "value": "i3visio"
                    },
                    {
                      "attributes": [],
                      "type": "i3visio.platform",
                      "value": "Twitter"
                    }
                  ],
                  "type": "i3visio.profile",
                  "value": "Twitter - i3visio"
                }
                ,
                ...
            ]
            """ for r in res : for att in r [ "attributes" ] : platform = "" uri = "" for details in att [ "attributes" ] : if details [ "type" ] == "i3visio.platform" : platform = details [ "value" ] if details [ "type" ] == "i3visio.uri" : uri = details [ "value" ] try : strResults += ( str ( platform ) + ":" ) . ljust ( 16 , ' ' ) + " " + str ( uri ) + "\n\t\t" except : pass if args . extension : if not os . path . exists ( args . output_folder ) : os . makedirs ( args . output_folder ) fileHeader = os . path . join ( args . output_folder , args . file_header ) for ext in args . extension : general . exportUsufy ( res , ext , fileHeader ) now = dt . datetime . now ( ) print ( "\n{}\tResults obtained:\n" . format ( str ( now ) ) ) print ( general . success ( general . usufyToTextExport ( res ) ) ) if args . web_browser : general . openResultsInBrowser ( res ) now = dt . datetime . now ( ) print ( "\n" + str ( now ) + "\tYou can find all the information here:" ) for ext in args . extension : print ( "\t" + general . emphasis ( fileHeader + "." + ext ) ) endTime = dt . datetime . now ( ) print ( "\n" + str ( endTime ) + "\tFinishing execution...\n" ) print ( "Total time consumed:\t" + general . emphasis ( str ( endTime - startTime ) ) ) print ( "Average seconds/query:\t" + general . emphasis ( str ( ( endTime - startTime ) . total_seconds ( ) / len ( listPlatforms ) ) ) + " seconds\n" ) print ( banner . footer ) if params : return res
Main function to launch usufy.

    The function is created in this way so as to let other applications make
    use of the full configuration capabilities of the application. The
    parameters received are used as parsed by this modules `getParser()`.

    Args:
    -----
        params: A list with the parameters as grabbed by the terminal. It is
            None when this is called by an entry_point. If it is called by osrf
            the data is already parsed.

    Returns:
    --------
        dict: A Json representing the matching results.