Commit c6034ea7 authored by haowang's avatar haowang

modify upload_picture script

parent b8560e3a
...@@ -46,8 +46,8 @@ class UploadImage(object): ...@@ -46,8 +46,8 @@ class UploadImage(object):
except: except:
with open(self.JS_FILE_PATH, 'r', encoding='utf-8') as f: with open(self.JS_FILE_PATH, 'r', encoding='utf-8') as f:
js = f.read() js = f.read()
# print(js) # self.exec_js = execjs.compile(js, cwd='/home/gmuser/node_modules')
self.exec_js = execjs.compile(js, ) self.exec_js = execjs.compile(js)
def get_serach_page_cookies(self): def get_serach_page_cookies(self):
''' '''
...@@ -142,6 +142,22 @@ class UploadImage(object): ...@@ -142,6 +142,22 @@ class UploadImage(object):
文章图片剪切和下载 文章图片剪切和下载
''' '''
def _deal_image_by_path(file_path):
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]))
self.cur.execute(sql)
self.conn.commit()
else:
print('image open error : ', file_path)
urls = self.find_all_url(content) urls = self.find_all_url(content)
self.insert_picture_urls(table, urls, content_id, key_id) self.insert_picture_urls(table, urls, content_id, key_id)
...@@ -171,18 +187,7 @@ class UploadImage(object): ...@@ -171,18 +187,7 @@ class UploadImage(object):
with open(pathes, 'wb') as f: # 打开写入到path路径里-二进制文件,返回的句柄名为f with open(pathes, 'wb') as f: # 打开写入到path路径里-二进制文件,返回的句柄名为f
f.write(r.content) # 往f里写入r对象的二进制文件 f.write(r.content) # 往f里写入r对象的二进制文件
f.close() f.close()
_deal_image_by_path(pathes)
img = cv2.imread(pathes)
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]))
self.cur.execute(sql)
self.conn.commit()
def picture_process(self, path, new_path, table, pic_table, key_id, offset=0, count=10): 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) content_dict = self.gets_content_dict(table, key_id, offset, count)
...@@ -190,7 +195,7 @@ class UploadImage(object): ...@@ -190,7 +195,7 @@ class UploadImage(object):
for content_id, content in content_dict.items(): for content_id, content in content_dict.items():
self.picture_download_and_cut(path, new_path, pic_table, key_id, content_id, content) self.picture_download_and_cut(path, new_path, pic_table, key_id, content_id, content)
def insert_picture_urls(self, table, urls, content_id, key_id, has_old=True): def insert_picture_urls(self, table, urls, content_id, key_id):
def _delete_repeat_url(instance, columns): def _delete_repeat_url(instance, columns):
print(columns) print(columns)
...@@ -213,7 +218,7 @@ class UploadImage(object): ...@@ -213,7 +218,7 @@ class UploadImage(object):
values = [] values = []
for url in urls: for url in urls:
if has_old and not _url_exist(self, url): if not _url_exist(self, url):
continue continue
values.append("({}, '{}')".format(content_id, url)) values.append("({}, '{}')".format(content_id, url))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment