mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
parent
1ad8528f79
commit
65400f3fb5
|
@ -54,7 +54,7 @@ class DataFile:
|
||||||
def generate_datafile():
|
def generate_datafile():
|
||||||
"""Generate a data.json file from a template."""
|
"""Generate a data.json file from a template."""
|
||||||
try:
|
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))
|
data.write(json.dumps(data_template, indent=4))
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
misc_logger.critical("Could not create a data file (no permissions). No way to store last edit.")
|
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
|
:rtype: dict
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open("data.json") as data:
|
with open("data.json", encoding="utf-8") as data:
|
||||||
return json.loads(data.read())
|
return json.loads(data.read())
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.generate_datafile()
|
self.generate_datafile()
|
||||||
|
@ -77,7 +77,7 @@ class DataFile:
|
||||||
if self.changed is False: # don't cause unnecessary write operations
|
if self.changed is False: # don't cause unnecessary write operations
|
||||||
return
|
return
|
||||||
try:
|
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))
|
data_file.write(json.dumps(self.data, indent=4))
|
||||||
self.changed = False
|
self.changed = False
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
|
|
24
src/rc.py
24
src/rc.py
|
@ -63,6 +63,7 @@ class Recent_Changes_Class(object):
|
||||||
self.session = session
|
self.session = session
|
||||||
self.logged_in = False
|
self.logged_in = False
|
||||||
self.initial_run_complete = False
|
self.initial_run_complete = False
|
||||||
|
self.memory_id = None # Used only when limitrefetch is set to -1 to avoid reading from storage
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def handle_mw_errors(request):
|
def handle_mw_errors(request):
|
||||||
|
@ -114,9 +115,12 @@ class Recent_Changes_Class(object):
|
||||||
messagequeue.resend_msgs()
|
messagequeue.resend_msgs()
|
||||||
last_check = self.fetch_changes(amount=amount)
|
last_check = self.fetch_changes(amount=amount)
|
||||||
if last_check is not None:
|
if last_check is not None:
|
||||||
storage["rcid"] = last_check[0] if last_check[0] else storage["rcid"]
|
if settings["limitrefetch"] != -1:
|
||||||
storage["abuse_log_id"] = last_check[1] if last_check[1] else storage["abuse_log_id"]
|
storage["rcid"] = last_check[0] if last_check[0] else storage["rcid"]
|
||||||
storage.save_datafile()
|
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
|
self.initial_run_complete = True
|
||||||
|
|
||||||
def fetch_recentchanges_request(self, amount):
|
def fetch_recentchanges_request(self, amount):
|
||||||
|
@ -155,8 +159,11 @@ class Recent_Changes_Class(object):
|
||||||
categorize_events = {}
|
categorize_events = {}
|
||||||
new_events = 0
|
new_events = 0
|
||||||
changes.reverse()
|
changes.reverse()
|
||||||
highest_id = recent_id = storage["rcid"]
|
if settings["limitrefetch"] == -1 and self.memory_id is not None:
|
||||||
dry_run = True if recent_id is None else False
|
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:
|
for change in changes:
|
||||||
if not dry_run and not (change["rcid"] <= recent_id):
|
if not dry_run and not (change["rcid"] <= recent_id):
|
||||||
new_events += 1
|
new_events += 1
|
||||||
|
@ -217,8 +224,11 @@ class Recent_Changes_Class(object):
|
||||||
if not abuse_log:
|
if not abuse_log:
|
||||||
return None
|
return None
|
||||||
abuse_log.reverse()
|
abuse_log.reverse()
|
||||||
recent_id = storage["abuse_log_id"]
|
if self.memory_id is not None and settings["limitrefetch"] == -1:
|
||||||
dryrun = True if recent_id is None else False
|
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:
|
for entry in abuse_log:
|
||||||
if dryrun:
|
if dryrun:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue