|
|
|
@ -14,19 +14,15 @@ def log_print(source, text): |
|
|
|
|
print(text) |
|
|
|
|
|
|
|
|
|
def log_pprint(source, obj): |
|
|
|
|
log(source, pprint.pformat(obj)) |
|
|
|
|
|
|
|
|
|
# Floor datetime to nearest hour |
|
|
|
|
#def floor_dt(dt): |
|
|
|
|
# return dt - timedelta( |
|
|
|
|
# minutes = dt.minute, |
|
|
|
|
# seconds = dt.second, |
|
|
|
|
# microseconds = dt.microsecond) |
|
|
|
|
log_print(source, pprint.pformat(obj)) |
|
|
|
|
|
|
|
|
|
def encode_time(dt): |
|
|
|
|
return int(dt.strftime("%Y%m%d%H")) |
|
|
|
|
return int(dt.strftime("%Y%m%d%H%M")) |
|
|
|
|
|
|
|
|
|
def decode_time(value): |
|
|
|
|
if len(value) == 12: |
|
|
|
|
return dt.strptime(str(value), "%Y%m%d%H%M") |
|
|
|
|
else: |
|
|
|
|
return dt.strptime(str(value), "%Y%m%d%H") |
|
|
|
|
|
|
|
|
|
class Instance: |
|
|
|
@ -136,23 +132,32 @@ class Instance: |
|
|
|
|
def purger(self): |
|
|
|
|
while True: |
|
|
|
|
try: |
|
|
|
|
|
|
|
|
|
deleted = False |
|
|
|
|
timeslot_key, status_id = self.next_expired() |
|
|
|
|
|
|
|
|
|
if not timeslot_key is None: |
|
|
|
|
log_print(self.name, "Deleting status {} in timeslot {}".format(status_id, timeslot_key)) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
log_print(self.name, "Inspecting status {} in timeslot {}".format(status_id, timeslot_key)) |
|
|
|
|
status = self.api.status(status_id) |
|
|
|
|
|
|
|
|
|
if status["favourited"]: |
|
|
|
|
log_print(self.name, "Keeping favourited status {} in timeslot {}".format(status_id, timeslot_key)) |
|
|
|
|
else: |
|
|
|
|
log_print(self.name, "Deleting status {} in timeslot {}".format(status_id, timeslot_key)) |
|
|
|
|
self.api.status_delete(status_id) |
|
|
|
|
deleted = True |
|
|
|
|
|
|
|
|
|
except MastodonNotFoundError: |
|
|
|
|
log_print(self.name, |
|
|
|
|
"Cannot delete missing status {} from server".format(status_id)) |
|
|
|
|
"Cannot find status {} on server".format(status_id)) |
|
|
|
|
|
|
|
|
|
self.expire_status(timeslot_key, status_id) |
|
|
|
|
|
|
|
|
|
if deleted: |
|
|
|
|
time.sleep(60) |
|
|
|
|
else: |
|
|
|
|
time.sleep(1) |
|
|
|
|
|
|
|
|
|
except: |
|
|
|
|
log_print(self.name, traceback.format_exc()) |
|
|
|
|
time.sleep(60) |
|
|
|
@ -214,7 +219,7 @@ class Instance: |
|
|
|
|
|
|
|
|
|
def next_expired(self): |
|
|
|
|
now = datetime.now(timezone.utc) |
|
|
|
|
min_timeslot_key = encode_time(now - timedelta(hours = self.config["max_age"])) |
|
|
|
|
min_timeslot_key = encode_time(now - timedelta(minutes = self.config["max_age"])) |
|
|
|
|
|
|
|
|
|
self.state_lock.acquire() |
|
|
|
|
|
|
|
|
|