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

Code before:
            self.sf.info(f"No {self.meta['name']} info found for {qry}")
            return None

        try:
            info = json.loads(res["content"])
        except Exception as e:
            self.sf.error(
                f"Error processing JSON response from {self.meta['name']}: {e}", False
            )
            return None

        return info

    def emit(self, etype, data, pevent, notify=True):
        evt = SpiderFootEvent(etype, data, self.__name__, pevent)
        if notify:
            self.notifyListeners(evt)
        return evt

    def generate_events(self, data, pevent):
        if not isinstance(data, dict):
            return

        scams = data.get("scams", [])
        if scams:
            self.emit("MALICIOUS_BITCOIN_ADDRESS", pevent.data)

    def handleEvent(self, event):
        if self.errorState:
            return None

        self.sf.debug(f"Received event, {event.eventType}, from {event.module}")

        if self.opts["api_key"] == "":
            self.sf.error(f"You enabled {self.__name__} but did not set an API key!", False)
            self.errorState = True
            return None

        if event.data in self.results:
            self.sf.debug(f"Skipping {event.data}, already checked.")
            return None
        self.results[event.data] = True

        if event.eventType == "BITCOIN_ADDRESS":
            data = self.query(event.data)
            self.generate_events(data, event)

            self.emit("RAW_RIR_DATA", json.dumps(data), event)

# End of sfp_bitcoinwhoswho class


Review comment (suggestion):
Same as with other `MALICIOUS_` types, the content should be consistent with the others.

Code after:
            return None

        try:
            info = json.loads(res["content"])
        except Exception as e:
            self.sf.error(
                f"Error processing JSON response from {self.meta['name']}: {e}", False
            )
            return None

        return info

    def emit(self, etype, data, pevent, notify=True):
        evt = SpiderFootEvent(etype, data, self.__name__, pevent)
        if notify:
            self.notifyListeners(evt)
        return evt

    def generate_events(self, data, pevent):
        if not isinstance(data, dict):
            return

        scams = data.get("scams", [])
        if scams:
            self.emit("MALICIOUS_BITCOIN_ADDRESS", f"Bitcoin Who's Who[{pevent.data}]")

    def handleEvent(self, event):
        if self.errorState:
            return None

        self.sf.debug(f"Received event, {event.eventType}, from {event.module}")

        if self.opts["api_key"] == "":
            self.sf.error(f"You enabled {self.__class__.__name__} but did not set an API key!", False)
            self.errorState = True
            return None

        if event.data in self.results:
            self.sf.debug(f"Skipping {event.data}, already checked.")
            return None
        self.results[event.data] = True

        if event.eventType == "BITCOIN_ADDRESS":
            data = self.query(event.data)
            self.generate_events(data, event)

            self.emit("RAW_RIR_DATA", json.dumps(data), event)

# End of sfp_bitcoinwhoswho class