Repository: smicallef/spiderfoot
File: modules/sfp_stackoverflow.py (Python)

Code before:
            'logo': "https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png",
            'description': "A paragraph of text with details about the data source / services. "
            "Keep things neat by breaking the text up across multiple lines as "
            "has been done here. If line breaks are needed for breaking up "
            "multiple paragraphs, use \n.",
        }
    }

    # Default Options
    opts = {
        'api_key': '',
    }

    # Option descriptions
    optdescs = {
        "api_key": "StackApps Optional API Key."
    }

    # Results Tracking
    results = None

    # Tracking the error state of the module
    errorState = False

    def setup(self, sfc, userOpts=dict()):
        self.sf = sfc
        self.results = self.tempStorage()

        for opt in list(userOpts.keys()):
            self.opts[opt] = userOpts[opt]

    # What events is this module interested in for input
    def watchedEvents(self):
        return ["DOMAIN_NAME"]

    # What events this module produces
    def producedEvents(self):
        return ["RAW_RIR_DATA", "EMAILADDR", "USERNAME", "IP_ADDRESS"]

    def query(self, qry, qryType):
        # The Stackoverflow excerpts endpoint will search the site for mentions of a keyword and returns a snippet of relevant results
        if qryType == "excerpts":
            res = self.sf.fetchUrl(
                f"https://api.stackexchange.com/2.3/search/excerpts?order=desc&q={qry}&site=stackoverflow",
                timeout=self.opts['_fetchtimeout'],
                useragent="SpiderFoot"
            )

        # User profile endpoint
        if qryType == "questions":
            res = self.sf.fetchUrl(

Review comment (security):
errorState doesn't appear to be used in the module. This is typically used in cases where the module encounters an error that should mean it no longer processes any events, e.g. if the API appears to be down or credentials rejected.

Code after:
                "The OAuth Domain can either be a valid domain you own or control, or stackexchange.com."
                "Select 'Register Your Application'."
                "Under the Title 'Key' is your API key, use this for an increased request quota."
            ],
            'favIcon': "https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196",
            'logo': "https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png",
            'description': "StackOverflow is a knowledge sharing public platform for IT professionals"
            "and students where users can post questions and get answers from other users."
        }
    }

    # Default Options
    opts = {
        'api_key': '',
    }

    # Option descriptions
    optdescs = {
        "api_key": "StackApps has an optional API key. Using an API key will increase the amount of requests allowed."
    }

    # Results Tracking
    results = None

    # Tracking the error state of the module
    errorState = False

    def setup(self, sfc, userOpts=dict()):
        self.sf = sfc
        self.results = self.tempStorage()

        for opt in list(userOpts.keys()):
            self.opts[opt] = userOpts[opt]

    # What events is this module interested in for input
    def watchedEvents(self):
        return ["DOMAIN_NAME"]

    # What events this module produces
    def producedEvents(self):
        return ["RAW_RIR_DATA",
                "EMAILADDR",
                "AFFILIATE_EMAILADDR",
                "USERNAME",
                "IP_ADDRESS",
                "IPV6_ADDRESS",
                "HUMAN_NAME"
                ]

    def query(self, qry, qryType):
        # The Stackoverflow excerpts endpoint will search the site for mentions of a keyword and returns a snippet of relevant results