Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
crawler
Project
Project
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
Chengyang Zhong
crawler
Commits
c606ec23
Commit
c606ec23
authored
Dec 01, 2020
by
haowang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix upload image
parent
c6034ea7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
upload_picture.py
tasks/zhihu/upload_picture.py
+14
-5
No files found.
tasks/zhihu/upload_picture.py
View file @
c606ec23
...
...
@@ -142,14 +142,14 @@ class UploadImage(object):
文章图片剪切和下载
'''
def
_deal_image_by_path
(
file_path
):
def
_deal_image_by_path
(
file_path
,
old_url
):
img
=
cv2
.
imread
(
file_path
)
if
img
:
high
,
width
=
img
.
shape
[:
2
]
cropped
=
img
[
0
:
int
(
high
/
10
*
9
),
0
:
width
]
pathes
=
new_path
+
"num"
+
str
(
i
)
+
".jpg"
cv2
.
imwrite
(
pathes
,
cropped
)
new_url
=
self
.
upload_image_with_path
(
pathes
)
sql
=
"""UPDATE {} SET new_url = "{}" WHERE url = "{}" """
.
format
(
table
,
str
(
new_url
),
str
(
tuple
[
i
][
1
]))
...
...
@@ -157,7 +157,16 @@ class UploadImage(object):
self
.
conn
.
commit
()
else
:
print
(
'image open error : '
,
file_path
)
_upload_picture
(
file_path
,
old_url
)
def
_upload_picture
(
file_path
,
old_url
):
new_url
=
self
.
upload_image_with_path
(
file_path
)
sql
=
"""UPDATE {} SET new_url = "{}" WHERE url = "{}" """
.
format
(
table
,
str
(
new_url
),
str
(
old_url
))
self
.
cur
.
execute
(
sql
)
self
.
conn
.
commit
()
urls
=
self
.
find_all_url
(
content
)
self
.
insert_picture_urls
(
table
,
urls
,
content_id
,
key_id
)
...
...
@@ -179,7 +188,7 @@ class UploadImage(object):
new_url
=
self
.
upload_image_with_path
(
pathes
)
sql
=
"""UPDATE {} SET new_url = "{}" WHERE url = "{}" """
.
format
(
table
,
str
(
new_url
),
str
(
tuple
[
i
][
1
]
))
table
,
str
(
new_url
),
str
(
url
))
self
.
cur
.
execute
(
sql
)
self
.
conn
.
commit
()
else
:
...
...
@@ -187,7 +196,7 @@ class UploadImage(object):
with
open
(
pathes
,
'wb'
)
as
f
:
# 打开写入到path路径里-二进制文件,返回的句柄名为f
f
.
write
(
r
.
content
)
# 往f里写入r对象的二进制文件
f
.
close
()
_deal_image_by_path
(
pathes
)
_deal_image_by_path
(
pathes
,
url
)
def
picture_process
(
self
,
path
,
new_path
,
table
,
pic_table
,
key_id
,
offset
=
0
,
count
=
10
):
content_dict
=
self
.
gets_content_dict
(
table
,
key_id
,
offset
,
count
)
...
...
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