This commit is contained in:
Frisk 2021-04-27 23:51:59 +02:00
parent 1ad8528f79
commit 65400f3fb5
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
2 changed files with 20 additions and 10 deletions

View file

@ -54,7 +54,7 @@ class DataFile:
def generate_datafile():
"""Generate a data.json file from a template."""
try:
with open("data.json", 'w') as data:
with open("data.json", 'w', encoding="utf-8") as data:
data.write(json.dumps(data_template, indent=4))
except PermissionError:
misc_logger.critical("Could not create a data file (no permissions). No way to store last edit.")
@ -65,7 +65,7 @@ class DataFile:
:rtype: dict
"""
try:
with open("data.json") as data:
with open("data.json", encoding="utf-8") as data:
return json.loads(data.read())
except FileNotFoundError:
self.generate_datafile()
@ -77,7 +77,7 @@ class DataFile:
if self.changed is False: # don't cause unnecessary write operations
return
try:
with open("data.json", "w") as data_file:
with open("data.json", "w", encoding="utf-8") as data_file:
data_file.write(json.dumps(self.data, indent=4))
self.changed = False
except PermissionError:

View file

@ -63,6 +63,7 @@ class Recent_Changes_Class(object):
self.session = session
self.logged_in = False
self.initial_run_complete = False
self.memory_id = None # Used only when limitrefetch is set to -1 to avoid reading from storage
@staticmethod
def handle_mw_errors(request):
@ -114,9 +115,12 @@ class Recent_Changes_Class(object):
messagequeue.resend_msgs()
last_check = self.fetch_changes(amount=amount)
if last_check is not None:
if settings["limitrefetch"] != -1:
storage["rcid"] = last_check[0] if last_check[0] else storage["rcid"]
storage["abuse_log_id"] = last_check[1] if last_check[1] else storage["abuse_log_id"]
storage.save_datafile()
else:
self.memory_id = last_check
self.initial_run_complete = True
def fetch_recentchanges_request(self, amount):
@ -155,8 +159,11 @@ class Recent_Changes_Class(object):
categorize_events = {}
new_events = 0
changes.reverse()
if settings["limitrefetch"] == -1 and self.memory_id is not None:
highest_id = recent_id = self.memory_id[0]
else:
highest_id = recent_id = storage["rcid"]
dry_run = True if recent_id is None else False
dry_run = True if recent_id is None or (self.memory_id is None and settings["limitrefetch"] == -1) else False
for change in changes:
if not dry_run and not (change["rcid"] <= recent_id):
new_events += 1
@ -217,8 +224,11 @@ class Recent_Changes_Class(object):
if not abuse_log:
return None
abuse_log.reverse()
if self.memory_id is not None and settings["limitrefetch"] == -1:
recent_id = self.memory_id[1]
else:
recent_id = storage["abuse_log_id"]
dryrun = True if recent_id is None else False
dryrun = True if recent_id is None or (self.initial_run_complete is False and settings["limitrefetch"] == -1) else False
for entry in abuse_log:
if dryrun:
continue