mirror of
https://git.mia.jetzt/scrubber
synced 2024-11-23 05:47:25 -07:00
changes and alterations
This commit is contained in:
parent
7e060e5cf2
commit
88394c7d82
5 changed files with 31 additions and 13 deletions
|
@ -17,12 +17,12 @@ intermediate = parse_graph()
|
||||||
def transform(entry: dict) -> FilterableNote:
|
def transform(entry: dict) -> FilterableNote:
|
||||||
time.sleep(0.0001)
|
time.sleep(0.0001)
|
||||||
note = conn.execute(
|
note = conn.execute(
|
||||||
'select "createdAt", reactions, "renoteCount", visibility from note where id = %s',
|
'select "createdAt", reactions, "renoteCount", visibility, cw from note where id = %s',
|
||||||
[entry["id"]],
|
[entry["id"]],
|
||||||
).fetchone()
|
).fetchone()
|
||||||
if note is None:
|
if note is None:
|
||||||
return None # part of thread disappeared during processing
|
return None # part of thread disappeared during processing
|
||||||
when, reactions, renotes, visibility = note
|
when, reactions, renotes, visibility, cw = note
|
||||||
|
|
||||||
replies = [transform(intermediate[reply]) for reply in entry["replies"]]
|
replies = [transform(intermediate[reply]) for reply in entry["replies"]]
|
||||||
quotes = [transform(intermediate[quote]) for quote in entry["quotes"]]
|
quotes = [transform(intermediate[quote]) for quote in entry["quotes"]]
|
||||||
|
@ -38,6 +38,7 @@ def transform(entry: dict) -> FilterableNote:
|
||||||
sum(reactions.values()),
|
sum(reactions.values()),
|
||||||
renotes,
|
renotes,
|
||||||
Visibility.from_db(visibility),
|
Visibility.from_db(visibility),
|
||||||
|
cw,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,10 @@ def collect_note(id: str):
|
||||||
output["attachments"] = []
|
output["attachments"] = []
|
||||||
for file_id in file_ids:
|
for file_id in file_ids:
|
||||||
time.sleep(0.0005)
|
time.sleep(0.0005)
|
||||||
name, type_, comment, url = conn.execute('select name, type, comment, url from drive_file where id = %s', [file_id]).fetchone()
|
row = conn.execute('select name, type, comment, url from drive_file where id = %s', [file_id]).fetchone()
|
||||||
|
if row is None:
|
||||||
|
continue
|
||||||
|
name, type_, comment, url = row
|
||||||
attachment = {
|
attachment = {
|
||||||
"id": file_id,
|
"id": file_id,
|
||||||
"type": type_,
|
"type": type_,
|
||||||
|
|
26
4_delete.py
26
4_delete.py
|
@ -3,9 +3,10 @@ import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
import psutil
|
||||||
import psycopg
|
import psycopg
|
||||||
|
|
||||||
from com import eval_config, parse_graph, progressbar, FilterAction
|
from com import FilterAction, eval_config, parse_graph, progressbar
|
||||||
|
|
||||||
config = eval_config()
|
config = eval_config()
|
||||||
conn: psycopg.Connection = config["connect"]()
|
conn: psycopg.Connection = config["connect"]()
|
||||||
|
@ -94,17 +95,25 @@ for note, action in queue:
|
||||||
pb.update(message="down")
|
pb.update(message="down")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
continue
|
continue
|
||||||
|
Path('queue-stats.dump').write_text(f"status:{resp.status_code}\nbody:\n{resp.text}")
|
||||||
deliver_waiting = resp.json()["deliver"]["waiting"]
|
deliver_waiting = resp.json()["deliver"]["waiting"]
|
||||||
obliterate_waiting = resp.json()["obliterate"]["waiting"]
|
obliterate_waiting = resp.json()["obliterate"]["waiting"]
|
||||||
obliterate_delayed = resp.json()["obliterate"]["delayed"]
|
if deliver_waiting < 100 and obliterate_waiting < 50000:
|
||||||
if deliver_waiting < 100 and obliterate_waiting + obliterate_delayed< 50000:
|
|
||||||
break
|
break
|
||||||
pb.update(message=f"queue ({deliver_waiting}/{obliterate_waiting + obliterate_delayed})")
|
pb.update(message=f"queue ({deliver_waiting}/{obliterate_waiting})")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
# make sure there's enough memory for new jobs
|
||||||
|
while True:
|
||||||
|
vmem = psutil.virtual_memory()
|
||||||
|
if vmem.available > (512 * 1024 * 1024):
|
||||||
|
break
|
||||||
|
pb.update(message="memory")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
# prevent api rate limiting
|
# prevent api rate limiting
|
||||||
req_delay = time.time() - last_req
|
req_delay = time.time() - last_req
|
||||||
if req_delay < 15:
|
if req_delay < 30:
|
||||||
pb.update(message="delaying")
|
pb.update(message="delaying")
|
||||||
time.sleep(req_delay)
|
time.sleep(req_delay)
|
||||||
|
|
||||||
|
@ -122,16 +131,19 @@ for note, action in queue:
|
||||||
continue
|
continue
|
||||||
elif resp.status_code == 502:
|
elif resp.status_code == 502:
|
||||||
pb.update(status="down")
|
pb.update(status="down")
|
||||||
continue
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
continue
|
||||||
elif resp.status_code >= 400:
|
elif resp.status_code >= 400:
|
||||||
body = resp.json()
|
body = resp.json()
|
||||||
if body["error"]["code"] == "NO_SUCH_NOTE":
|
if body["error"]["code"] == "NO_SUCH_NOTE":
|
||||||
pb.increment(message="seeking")
|
pb.increment(message="seeking")
|
||||||
seeking = True
|
seeking = True
|
||||||
break
|
break
|
||||||
|
elif body["error"]["code"] == "QUEUE_FULL":
|
||||||
|
print("\nobliterate queue overflowed, exiting to save server")
|
||||||
|
break
|
||||||
err += 1
|
err += 1
|
||||||
if err > 10:
|
if err > 3:
|
||||||
raise Exception(f"{body['error']['code']}: {body['error']['message']}")
|
raise Exception(f"{body['error']['code']}: {body['error']['message']}")
|
||||||
sys.stdout.write("\r")
|
sys.stdout.write("\r")
|
||||||
print(f"err {body['error']['code']} {body['error']['message']} ")
|
print(f"err {body['error']['code']} {body['error']['message']} ")
|
||||||
|
|
2
com.py
2
com.py
|
@ -44,6 +44,7 @@ class FilterableNote:
|
||||||
reactions: int
|
reactions: int
|
||||||
renotes: int
|
renotes: int
|
||||||
visibility: Visibility
|
visibility: Visibility
|
||||||
|
cw: str
|
||||||
|
|
||||||
def thread(self) -> List["FilterableNote"]:
|
def thread(self) -> List["FilterableNote"]:
|
||||||
acc = []
|
acc = []
|
||||||
|
@ -73,6 +74,7 @@ class FilterableNote:
|
||||||
"when": self.when.isoformat(),
|
"when": self.when.isoformat(),
|
||||||
"reactions": self.reactions,
|
"reactions": self.reactions,
|
||||||
"renotes": self.renotes,
|
"renotes": self.renotes,
|
||||||
|
"cw": self.cw,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ api = "https://void.rehab/api"
|
||||||
early_exit = 0xFFF
|
early_exit = 0xFFF
|
||||||
|
|
||||||
now = datetime.now(UTC)
|
now = datetime.now(UTC)
|
||||||
threshold = 0.1
|
threshold = 2.0
|
||||||
|
|
||||||
def criteria(root: FilterableNote) -> FilterAction:
|
def criteria(root: FilterableNote) -> FilterAction:
|
||||||
thread = root.thread()
|
thread = root.thread()
|
||||||
|
@ -34,7 +34,7 @@ def criteria(root: FilterableNote) -> FilterAction:
|
||||||
|
|
||||||
# get my...
|
# get my...
|
||||||
most_recent_post = max(thread_self, key=lambda note: note.when) # ...most recent post...
|
most_recent_post = max(thread_self, key=lambda note: note.when) # ...most recent post...
|
||||||
score = lambda note: note.reactions + note.renotes*5
|
score = lambda note: note.reactions + note.renotes*5 + 1
|
||||||
high_score_post = max(thread_self, key=score) # ...highest scoring post...
|
high_score_post = max(thread_self, key=score) # ...highest scoring post...
|
||||||
# ...and their values...
|
# ...and their values...
|
||||||
most_recent = most_recent_post.when
|
most_recent = most_recent_post.when
|
||||||
|
@ -45,7 +45,7 @@ def criteria(root: FilterableNote) -> FilterAction:
|
||||||
# ...and check it against a threshold
|
# ...and check it against a threshold
|
||||||
if weighted_score < threshold:
|
if weighted_score < threshold:
|
||||||
if any(map(
|
if any(map(
|
||||||
lambda note: note.visibility in [Visibility.public, Visibility.unlisted],
|
lambda note: note.visibility in [Visibility.public, Visibility.unlisted] or note.cw,
|
||||||
thread_self,
|
thread_self,
|
||||||
)):
|
)):
|
||||||
return FilterAction.Obliterate
|
return FilterAction.Obliterate
|
||||||
|
|
Loading…
Reference in a new issue