Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spider
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
selection-new
spider
Commits
8066e738
Commit
8066e738
authored
Apr 21, 2026
by
Peng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
d065bab7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
33 deletions
+18
-33
download_pic.py
.../picture_material/stock_summery/new_stock/download_pic.py
+6
-12
upload_pic.py
...ts/picture_material/stock_summery/new_stock/upload_pic.py
+11
-20
xnj_url.py
...jects/picture_material/stock_summery/new_stock/xnj_url.py
+1
-1
No files found.
wangjing_projects/projects/picture_material/stock_summery/new_stock/download_pic.py
View file @
8066e738
from
time
import
sleep
from
random
import
randint
from
all_connect
import
ConnectSpider
Con
=
ConnectSpider
()
import
imaplib
import
email
import
os
os
.
environ
[
'NO_PROXY'
]
=
'stackoverflow.com'
import
logging
logging
.
captureWarnings
(
True
)
from
DrissionPage
import
ChromiumPage
import
json
import
requests
import
re
import
random
import
time
from
datetime
import
datetime
,
timedelta
import
concurrent.futures
import
time
import
threading
from
datetime
import
datetime
class
Download
():
def
__init__
(
self
):
...
...
@@ -73,7 +64,12 @@ class Download():
content_type
=
res
.
headers
.
get
(
"Content-Type"
,
""
)
print
(
'content_type: 查看返回的类型:'
,
content_type
)
if
res
.
status_code
!=
200
or
not
content_type
.
startswith
(
"image/"
):
print
(
f
'下载失败 image_id:{image_id} status:{res.status_code} content_type:{content_type}'
)
return
# 构建完整的文件路径
os
.
makedirs
(
save_folder
,
exist_ok
=
True
)
file_path
=
os
.
path
.
join
(
save_folder
,
pic_name
)
self
.
download_image
(
file_path
,
res
)
Con
.
update_url_state_to_3
(
image_id
)
...
...
@@ -83,8 +79,6 @@ class Download():
except
Exception
as
e
:
print
(
e
)
import
time
def
process_item_id
(
self
,
item_id
):
has_new_data
=
False
# 用于标记当前item_id是否有新数据被处理
print
(
f
"开始处理item_id: {item_id}"
)
...
...
wangjing_projects/projects/picture_material/stock_summery/new_stock/upload_pic.py
View file @
8066e738
import
json
import
os
from
datetime
import
datetime
# import requests
import
PIL
from
PIL
import
Image
from
all_connect
import
ConnectSpider
# import time
# import shutil
import
re
# from pathlib import Path
import
shutil
import
traceback
from
pathlib
import
Path
import
tempfile
import
time
...
...
@@ -36,7 +31,6 @@ def generate_thumbnail_240(input_image_path, output_image_path):
img
=
img
.
convert
(
"RGB"
)
# 保存缩略图
img
.
save
(
output_image_path
)
pass
def
generate_thumbnail_big
(
input_image_path
,
output_image_path
):
...
...
@@ -113,6 +107,8 @@ class UploadPicture():
break
except
Exception
as
e
:
print
(
'get_microservice_token, 报错'
,
e
)
if
not
hasattr
(
self
,
'token'
):
raise
Exception
(
'获取token失败,已重试5次'
)
def
upload_file
(
self
,
img_id
,
file_path
):
print
(
img_id
,
' file_path:::'
,
file_path
)
...
...
@@ -146,13 +142,12 @@ class UploadPicture():
big_img_path
=
os
.
path
.
join
(
tmpdir
,
"thumbnail_image_big"
+
suffix
)
img_240_path
=
os
.
path
.
join
(
tmpdir
,
"thumbnail_image_240"
+
suffix
)
try
:
print
(
target_path
,
os
.
path
.
join
(
tmpdir
,
big_img_path
),
'23333333333'
)
generate_thumbnail_big
(
target_path
,
os
.
path
.
join
(
tmpdir
,
big_img_path
)
)
generate_thumbnail_240
(
target_path
,
os
.
path
.
join
(
tmpdir
,
img_240_path
)
)
print
(
target_path
,
big_img_path
)
generate_thumbnail_big
(
target_path
,
big_img_path
)
generate_thumbnail_240
(
target_path
,
img_240_path
)
except
Exception
as
ex
:
print
(
f
"文件{filename}生成缩略图失败:"
,
ex
)
return
False
pass
retry_time
=
1
while
retry_time
<
3
:
...
...
@@ -186,21 +181,17 @@ class UploadPicture():
print
(
'errMsg:::'
,
errMsg
)
if
errMsg
==
'您上传的文件已经被上传过~!请勿重复上传!'
:
exec_sql
(
f
"""update stock_image_detail_wj set upload_time='{formatted_time}',err_msg='success' where image_id ='
img_id
'"""
)
f
"""update stock_image_detail_wj set upload_time='{formatted_time}',err_msg='success' where image_id ='
{img_id}
'"""
)
self
.
count
=
self
.
count
+
1
success_flag
=
True
break
else
:
exec_sql
(
f
"""update stock_image_detail_wj set upload_time='{formatted_time}',err_msg='{json.dumps(response_data)}' where image_id = '{img_id}'"""
)
if
""
in
errMsg
:
# 此处超时等
pass
retry_time
=
retry_time
+
1
retry_time
+=
1
except
Exception
as
e
:
print
(
'报错:33333'
,
e
)
self
.
get_microservice_token
()
retry_time
+=
1
finally
:
# 关闭文件流
for
file
in
files
.
values
():
...
...
@@ -241,7 +232,6 @@ class UploadPicture():
# 转移到上传成功的文件夹中
print
(
'转移到上传成功的文件夹中'
)
shutil
.
move
(
file_path
,
os
.
path
.
join
(
all_pic_success_dir
,
file_name
))
pass
return
1
def
run
(
self
):
folder_path_list
=
[
...
...
@@ -278,8 +268,8 @@ class UploadPicture():
]
for
account_id
in
folder_path_list
:
if
9
<=
datetime
.
now
()
.
hour
<
16
:
print
(
f
"当前时间 {datetime.now().hour} 点,
超出运行时段
18:00–08:00,退出循环。"
)
if
8
<=
datetime
.
now
()
.
hour
<
18
:
print
(
f
"当前时间 {datetime.now().hour} 点,
白天时段暂停上传,运行时段为
18:00–08:00,退出循环。"
)
break
print
(
f
"当前时间 {datetime.now().hour} 点,开始处理账户 {account_id}"
)
if
'@'
in
account_id
:
...
...
@@ -294,6 +284,7 @@ class UploadPicture():
try
:
str_null
=
self
.
upload_dir
(
folder_path
)
if
str_null
==
'null'
:
success
=
True
# 目录不存在,不算失败
break
success
=
True
break
...
...
wangjing_projects/projects/picture_material/stock_summery/new_stock/xnj_url.py
View file @
8066e738
...
...
@@ -419,7 +419,7 @@ class GetSS_details():
# self.login_out()
# 查找并点击登录按钮
login_button
=
self
.
page
.
ele
(
'xpath://
a
[@data-automation="loginButton"]'
,
timeout
=
15
)
login_button
=
self
.
page
.
ele
(
'xpath://
button
[@data-automation="loginButton"]'
,
timeout
=
15
)
login_button
.
click
()
sleep
(
randint
(
12
,
24
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment