forked from nakkaa/aminome
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaminome.py
64 lines (55 loc) · 1.63 KB
/
aminome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Register all notes on Misskey to Meilisearch
import psycopg2
import psycopg2.extras
import orjson
import requests
# postgresql config
db = psycopg2.connect(
host='localhost',
user='misskey-user',
password='password',
database='misskey',
port=5432,
cursor_factory=psycopg2.extras.DictCursor
)
# meilisearch config
api_key = "APIKEY"
index = ""
url = f"http://localhost:7700/indexes/{index}---notes/documents?primaryKey=id"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
lmt = 100000
ofs = 0
while True:
# Initialize notes from batch
notes = []
# Get a batch
with db.cursor() as cur:
cur.execute('SELECT "id", "createdAt", "userId", "userHost", "channelId", "cw", "text", "tags" FROM "note" \
WHERE ("note"."text" IS NOT NULL) \
LIMIT ' + str(lmt) + ' OFFSET ' + str(ofs))
qnotes = cur.fetchall()
if not qnotes:
break
for note in qnotes:
notes.append({
'id': note['id'],
'text': note['text'],
'createdAt': int(note['createdAt'].timestamp() * 1000),
'userId': note['userId'],
'userHost': note['userHost'],
'channelId': note['channelId'],
'cw': note['cw'],
'text': note['text'],
'tags': note['tags']
})
print(f'{ofs=} {lmt=} {len(notes)=}')
ofs = ofs + lmt
# Post a batch
response = requests.post(url, data=orjson.dumps(notes), headers=headers)
# Print batch result
print(response.content)
print('All notes uploaded, program finish.')
db.close()