18
18
download_folder .mkdir ()
19
19
20
20
headers = {
21
- 'accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' ,
21
+ 'accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;'
22
+ 'q=0.8,application/signed-exchange;v=b3;q=0.7' ,
22
23
'accept-language' : 'zh-CN,zh;q=0.9,en;q=0.8' ,
23
24
'cache-control' : 'no-cache' ,
24
25
'dnt' : '1' ,
31
32
'sec-fetch-site' : 'none' ,
32
33
'sec-fetch-user' : '?1' ,
33
34
'upgrade-insecure-requests' : '1' ,
34
- 'user-agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' ,
35
+ 'user-agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '
36
+ 'Chrome/123.0.0.0 Safari/537.36' ,
35
37
}
36
38
httpx_cookies = httpx .Cookies ()
37
39
limit = asyncio .Semaphore (20 )
@@ -73,11 +75,11 @@ def load_cookies():
73
75
async def get (url : str , params : dict ) -> Response :
74
76
try :
75
77
async with limit :
76
- async with httpx .AsyncClient () as client :
78
+ async with httpx .AsyncClient (timeout = 30 ) as client :
77
79
response = await client .get (url , params = params , cookies = httpx_cookies , headers = headers )
78
80
return response
79
81
except Exception as e :
80
- print ( e )
82
+ tqdm . tqdm . write ( f'Error: { url } { e } ' )
81
83
time .sleep (1 )
82
84
return await get (url , params )
83
85
@@ -105,7 +107,7 @@ async def download(url: str, emote_name: str, ids: str, filename: str) -> None:
105
107
else :
106
108
return
107
109
except Exception as e :
108
- print ( e , url )
110
+ tqdm . tqdm . write ( f'Error: { e } { url } ' )
109
111
110
112
111
113
# 获取表情列表
@@ -117,7 +119,7 @@ async def get_emote_list() -> Union[None, Dict[str, Union[str, Dict[str, str]]]]
117
119
if response ['code' ] == 0 :
118
120
return response ['data' ]['all_packages' ]
119
121
else :
120
- print ('error code:' , response ['code' ])
122
+ tqdm . tqdm . write ('error code:' , response ['code' ])
121
123
return None
122
124
123
125
@@ -134,11 +136,11 @@ async def get_emote_detail_list(data) -> List:
134
136
return list (chain (* resp ))
135
137
136
138
137
- def download_emote_list () -> List :
138
- # emote_list = await get_emote_list()
139
- # emote_detail_list = await get_emote_detail_list(emote_list)
140
- emote_list = asyncio .run (get_emote_list ())
141
- emote_detail_list = asyncio .run (get_emote_detail_list (emote_list ))
139
+ async def download_emote_list () -> List :
140
+ emote_list = await get_emote_list ()
141
+ emote_detail_list = await get_emote_detail_list (emote_list )
142
+ # emote_list = asyncio.run(get_emote_list())
143
+ # emote_detail_list = asyncio.run(get_emote_detail_list(emote_list))
142
144
if emote_list is None :
143
145
return []
144
146
else :
@@ -167,7 +169,7 @@ def download_emote_list() -> List:
167
169
168
170
async def main ():
169
171
load_cookies ()
170
- resp = download_emote_list ()
172
+ resp = await download_emote_list ()
171
173
task_list = []
172
174
for i in resp :
173
175
task_list .append (asyncio .create_task (download (* i )))
0 commit comments