diff --git a/src/misc.py b/src/misc.py index f241806..ee9ab47 100644 --- a/src/misc.py +++ b/src/misc.py @@ -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: diff --git a/src/rc.py b/src/rc.py index 2accac9..2b6b5a4 100644 --- a/src/rc.py +++ b/src/rc.py @@ -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: - 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() + 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() - highest_id = recent_id = storage["rcid"] - dry_run = True if recent_id is None else False + 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 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() - recent_id = storage["abuse_log_id"] - dryrun = True if recent_id is None else False + 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 or (self.initial_run_complete is False and settings["limitrefetch"] == -1) else False for entry in abuse_log: if dryrun: continue