-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotdb.py
132 lines (104 loc) · 4.16 KB
/
notdb.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import sqlite3
from argparse import ArgumentParser
import os
import requests
def action_in_progress(token):
url = 'https://api.github.com/repos/DistPub/image-feed-labels-generator/actions/runs'
path = 'notdb_gen.yml'
response = requests.get(url, headers={
'Authorization': f'token {token}'
}, params={'status': 'in_progress'})
data = response.json()
status_mismatch_ids = [
13811086833,
13810761455,
]
runs = [item for item in data['workflow_runs'] if item['path'].endswith(path) and item['id'] not in status_mismatch_ids]
if len(runs) < 2:
return False
return True
def fetch_list(aturl, cursor = None):
url = f'https://public.api.bsky.app/xrpc/app.bsky.graph.getList'
response = requests.get(url, params={'list': aturl, 'limit': 100, 'cursor': cursor})
data = response.json()
dids = [item['subject']['did'] for item in data['items']]
cursor = data.get('cursor')
if cursor:
dids.extend(fetch_list(aturl, cursor))
return dids
def git_commit():
os.system('git config --global user.email "[email protected]"')
os.system('git config --global user.name "robot auto"')
os.system('git add .')
os.system('git commit -m "update not.db"')
def git_push():
os.system('git push')
def main(dev, token):
if not dev and action_in_progress(token):
print(f'action in progress, skip')
return
# 连接到数据库(如果不存在则创建)
conn = sqlite3.connect("not.db")
# 创建一个游标对象,用于执行 SQL 语句
cursor = conn.cursor()
# get old
cursor.execute("SELECT did FROM not_good_user")
did_rows = cursor.fetchall()
cursor.execute("SELECT hostname FROM not_chinese_website")
hostname_rows = cursor.fetchall()
# fetch pastebin for not chinese website
response = requests.get('https://pastebin.smitechow.com/~notcnweb')
data = response.json()
new_hostname_rows = [(x,) for x in data]
add_hostname = set(new_hostname_rows) - set(hostname_rows)
removed_hostname = set(hostname_rows) - set(new_hostname_rows)
# fetch @smitechow.com list for not good user
list_keys = [
'at://did:web:smite.hukoubook.com/app.bsky.graph.list/3li4glzdchy2r', # 成功暴富爱好者
'at://did:web:smite.hukoubook.com/app.bsky.graph.list/3li4d2wvyny2r', # 黄赌毒从业者
'at://did:web:smite.hukoubook.com/app.bsky.graph.list/3li4bgpci5i2r', # 玄学爱好者
'at://did:web:smite.hukoubook.com/app.bsky.graph.list/3li4b326e5y2r', # 键政爱好者
'at://did:web:smite.hukoubook.com/app.bsky.graph.list/3lbfa5esptk2s', # 高音喇叭
]
not_good_users = []
for list_key in list_keys:
not_good_users.extend(fetch_list(list_key))
new_did_rows = [(x,) for x in not_good_users]
add_did = set(new_did_rows) - set(did_rows)
removed_did = set(did_rows) - set(new_did_rows)
if not add_hostname and not removed_hostname and not add_did and not removed_did:
print(f'not changed, skip update not.db')
cursor.close()
conn.close()
return
cursor.execute('''DROP TABLE IF EXISTS not_chinese_website''')
cursor.execute('''DROP TABLE IF EXISTS not_good_user''')
# 创建一个表
cursor.execute('''
CREATE TABLE IF NOT EXISTS not_chinese_website (
hostname STRING PRIMARY KEY
)''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS not_good_user (
did STRING PRIMARY KEY
)
''')
print(f'update not chinese website {len(data)}')
cursor.executemany('''INSERT INTO not_chinese_website (hostname) VALUES (?)''', new_hostname_rows)
conn.commit()
print(f'update not good user {len(not_good_users)}')
cursor.executemany('''INSERT INTO not_good_user (did) VALUES (?)''', new_did_rows)
conn.commit()
# 关闭数据库
cursor.close()
conn.close()
print(f'not.db updated')
if not dev:
git_commit()
git_push()
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("--dev", action="store_true")
parser.add_argument("--gh-token", help="gh token")
args = parser.parse_args()
main(args.dev, args.gh_token)