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

Code before:
    }

    # Option descriptions
    optdescs = {
        "days_limit": "Maximum age of data to be considered valid (0 = unlimited)."
    }

    # Be sure to completely clear any class variables in setup()
    # or you run the risk of data persisting between scan runs.

    results = None

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

        # Clear / reset any other class member variables here
        # or you risk them persisting between threads.

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

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

    # What events this module produces
    def producedEvents(self):
        return ["WIKIPEDIA_PAGE_EDIT"]

    def query(self, qry):
        params = {
            "action": "feedcontributions",
            "user": qry.encode('raw_unicode_escape').decode("ascii", errors='replace')
        }

        if self.opts['days_limit'] != "0":
            dt = datetime.datetime.now() - datetime.timedelta(days=int(self.opts['days_limit']))
            params["year"] = dt.strftime("%Y")
            params["month"] = dt.strftime("%m")

        res = self.sf.fetchUrl(
                "https://en.wikipedia.org/w/api.php?%s" % urllib.parse.urlencode(params),
                timeout=self.opts['_fetchtimeout'],
                useragent="SpiderFoot"
                )

        if res['code'] in ["404", "403", "500"]:
            return None


Review comment (suggestion):
```suggestion
        return ["IP_ADDRESS", "USERNAME"]
```

Code after:
    }

    # Option descriptions
    optdescs = {
        "days_limit": "Maximum age of data to be considered valid (0 = unlimited)."
    }

    # Be sure to completely clear any class variables in setup()
    # or you run the risk of data persisting between scan runs.

    results = None

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

        # Clear / reset any other class member variables here
        # or you risk them persisting between threads.

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

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

    # What events this module produces
    def producedEvents(self):
        return ["WIKIPEDIA_PAGE_EDIT"]

    def query(self, qry):
        params = {
            "action": "feedcontributions",
            "user": qry.encode('raw_unicode_escape').decode("ascii", errors='replace')
        }

        if self.opts['days_limit'] != "0":
            dt = datetime.datetime.now() - datetime.timedelta(days=int(self.opts['days_limit']))
            params["year"] = dt.strftime("%Y")
            params["month"] = dt.strftime("%m")

        res = self.sf.fetchUrl(
                "https://en.wikipedia.org/w/api.php?%s" % urllib.parse.urlencode(params),
                timeout=self.opts['_fetchtimeout'],
                useragent="SpiderFoot"
                )

        if res['code'] in ["404", "403", "500"]:
            return None