This commit is contained in:
Frisk 2018-06-17 14:57:06 +02:00
parent fa688be9c2
commit d67b05b86a
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C
2 changed files with 14 additions and 8 deletions

View file

@ -20,7 +20,7 @@ Explanation for settings:
`header` it's recommended to leave this value as it is, it's a header the script will use to communicate with Gamepedia. Please note that without it, no communication will be possible. `header` it's recommended to leave this value as it is, it's a header the script will use to communicate with Gamepedia. Please note that without it, no communication will be possible.
`limit` amount of actions retrieved every `cooldown` amount of seconds. The higher it is the more network data will be used and the data will be processed longer, setting it to higher values is not recommended, but if you want to make sure no edit is omitted (which only happen if there are more actions in last `cooldown` seconds than this value). `limit` amount of actions retrieved every `cooldown` amount of seconds. The higher it is the more network data will be used and the data will be processed longer, setting it to higher values is not recommended, but if you want to make sure no edit is omitted (which only happen if there are more actions in last `cooldown` seconds than this value).
`webhookURL` webhook URL you can get using channel settings in Discord `webhookURL` webhook URL you can get using channel settings in Discord
`limitrefetch` limit of how many changes can be retrieved when refetch happens `limitrefetch` limit of how many changes can be retrieved when refetch happens, cannot be lower than limit. -1 if you want to disable auto-refetch
### How to use ### ### How to use ###
Make sure you have installed all of dependencies and filled settings.json properly. Make sure you have installed all of dependencies and filled settings.json properly.

View file

@ -14,7 +14,9 @@ _ = lambda s: s
with open("settings.json") as sfile: with open("settings.json") as sfile:
settings = json.load(sfile) settings = json.load(sfile)
if os.path.exists("lastchange.txt") == False: if settings["limitrefetch"] < settings["limit"] and settings["limitrefetch"]!=-1:
settings["limitrefetch"] = settings["limit"]
if settings["limitrefetch"] != -1 and os.path.exists("lastchange.txt") == False:
with open("lastchange.txt", 'w') as sfile: with open("lastchange.txt", 'w') as sfile:
sfile.write("") sfile.write("")
logging.info("Current settings: {settings}".format(settings=settings)) logging.info("Current settings: {settings}".format(settings=settings))
@ -388,9 +390,12 @@ class recent_changes(object):
recent_id = 0 recent_id = 0
downtimecredibility = 0 downtimecredibility = 0
last_downtime = 0 last_downtime = 0
with open("lastchange.txt", "r") as record: if settings["limitrefetch"] != -1:
file_id = int(record.read().strip()) with open("lastchange.txt", "r") as record:
logging.debug("File_id is {val}".format(val=file_id)) file_id = int(record.read().strip())
logging.debug("File_id is {val}".format(val=file_id))
else:
file_id = 9999999
def add_cache(self, change): def add_cache(self, change):
self.cache.append(change) self.cache.append(change)
self.ids.append(change["rcid"]) self.ids.append(change["rcid"])
@ -399,7 +404,7 @@ class recent_changes(object):
self.ids.pop(0) self.ids.pop(0)
def fetch(self, amount=settings["limit"]): def fetch(self, amount=settings["limit"]):
self.recent_id = self.fetch_changes(amount=amount) self.recent_id = self.fetch_changes(amount=amount)
if self.recent_id != self.file_id: if settings["limitrefetch"] != -1 and self.recent_id != self.file_id:
self.file_id = self.recent_id self.file_id = self.recent_id
with open("lastchange.txt", "w") as record: with open("lastchange.txt", "w") as record:
record.write(str(self.file_id)) record.write(str(self.file_id))
@ -425,7 +430,6 @@ class recent_changes(object):
if change["rcid"] in self.ids: if change["rcid"] in self.ids:
continue continue
self.add_cache(change) self.add_cache(change)
logging.debug("Info {val} | {val2} | {val3} | {val4}".format(val=clean, val2=self.file_id, val3=change["rcid"], val4=self.recent_id))
if clean and not (self.recent_id == 0 and change["rcid"] > self.file_id): if clean and not (self.recent_id == 0 and change["rcid"] > self.file_id):
logging.debug("Rejected {val}".format(val=change["rcid"])) logging.debug("Rejected {val}".format(val=change["rcid"]))
continue continue
@ -468,11 +472,13 @@ class recent_changes(object):
self.last_downtime = time.time() self.last_downtime = time.time()
recent_changes = recent_changes() recent_changes = recent_changes()
recent_changes.fetch(amount=settings["limitrefetch"]) recent_changes.fetch(amount=settings["limitrefetch" ] if settings["limitrefetch"] != -1 else settings["limit"])
while 1: while 1:
time.sleep(float(settings["cooldown"])) time.sleep(float(settings["cooldown"]))
logging.debug(time.time())
recent_changes.fetch() recent_changes.fetch()
logging.debug(time.time())
if (recent_changes.day != datetime.date.fromtimestamp(time.time()).day): if (recent_changes.day != datetime.date.fromtimestamp(time.time()).day):
logging.info("A brand new day! Printing the summary and clearing the cache") logging.info("A brand new day! Printing the summary and clearing the cache")
#recent_changes.summary() #recent_changes.summary()