-
Notifications
You must be signed in to change notification settings - Fork 0
/
extracting-ids.py
58 lines (45 loc) · 1.77 KB
/
extracting-ids.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
# This source code is a part of Project Violet.
# Copyright (C) 2022. violet-team. Licensed under the Apache-2.0 License.
import requests
import sys
import os
import sqlite3
# https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests
def download_file(url):
filename = url.split('/')[-1]
with open(filename, "wb") as f:
response = requests.get(url, stream=True)
total_length = response.headers.get('content-length')
if total_length is None: # no content length header
f.write(response.content)
else:
dl = 0
total_length = int(total_length)
for data in response.iter_content(chunk_size=4096):
dl += len(data)
f.write(data)
done = int(50 * dl / total_length)
sys.stdout.write("\r[%s%s] %s" % (
'=' * done, ' ' * (50-done), str(round(dl / total_length * 100.0, 2)) + "%"))
sys.stdout.flush()
if not os.path.isfile("data.db"):
releases = requests.get(
'https://api.github.com/repos/violet-dev/sync-data/releases/latest')
latest_db = releases.json()['assets'][0]['browser_download_url']
download_file(latest_db)
def show_tables():
conn = sqlite3.connect("data.db")
cur = conn.cursor()
rows = cur.execute("SELECT * FROM sqlite_master WHERE type='table';")
for row in rows:
print(row)
conn.close()
def extract_ids():
conn = sqlite3.connect("data.db")
cur = conn.cursor()
rows = cur.execute(
"SELECT Id FROM HitomiColumnModel WHERE Language='korean' AND ExistOnHitomi=1 AND NOT Type='anime';")
with open('ids.txt.temp', "w") as f:
f.write(','.join(map(lambda x: str(x[0]), rows)))
conn.close()
extract_ids()