Skip to content

Commit

Permalink
🐞 fix(auto_comment_plus,readme): 修复windows下不兼容的代码bug
Browse files Browse the repository at this point in the history
Fixes #62
  • Loading branch information
rootphantomer committed Aug 30, 2024
1 parent 0e6b089 commit e3fcf14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## 思路

由爬虫先行对商品的既有评价进行爬取,在此基础上进行自己的评价
由爬虫先行对商品的既有评价进行爬取,在此基础上进行自己的评价。此程序只适用于 pc 端网页上可进行评论的订单进行评论,不适用于 一些 京东小程序、京东外卖、京东到家这类的订单评论。

## 用法

Expand Down
20 changes: 9 additions & 11 deletions auto_comment_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,15 @@ def generate_unique_filename() -> str:
# 组合生成10位的唯一文件名
unique_filename = f"{timestamp}{unique_id}.jpg"

return unique_filename
return str(unique_filename)


# 下载图片
def download_image(img_url: str, file_name: str) -> bool:
try:
img_path = os.path.exists("./img")
if img_path:
pass
else:
os.makedirs(img_path)
img_path = os.path.join(os.getcwd(), "img")
os.makedirs(img_path, exist_ok=True)
opts["logger"].info("img_path: %s", img_path)
fullUrl = f"https:{img_url}"
response = requests.get(fullUrl, verify=False, timeout=10)
if response.status_code == 200:
Expand Down Expand Up @@ -244,7 +242,7 @@ def all_evaluate(opts=None):

def delete_jpg():
try:
current_directory = "./img/"
current_directory = os.path.join(os.getcwd(), "img")
files = os.listdir(current_directory)
for file in files:
if file.lower().endswith(".jpg"):
Expand Down Expand Up @@ -389,8 +387,8 @@ def ordinary(N, opts=None):
opts["logger"].info("imgurl2 url: %s", imgurl2)
session = requests.Session()
imgBasic = "//img14.360buyimg.com/shaidan/"
imgName1 = f"./img/" + generate_unique_filename()
opts["logger"].debug(f"Image :{imgName1}")
imgName1 = os.path.join(os.getcwd(), "img", generate_unique_filename())
opts["logger"].info(f"imgName1 :{imgName1}")
# 上传图片
if download_image(imgurl1, imgName1):
imgPart1 = upload_image(imgName1, session, headers)
Expand All @@ -401,8 +399,8 @@ def ordinary(N, opts=None):
imgurl1 = ""
opts["logger"].info("上传图片失败")
exit(0)
imgName2 = f"./img/" + generate_unique_filename()
opts["logger"].debug(f"Image :{imgName2}")
imgName2 = os.path.join(os.getcwd(), "img", generate_unique_filename())
opts["logger"].info(f"imgName2 :{imgName2}")
# 上传图片
if download_image(imgurl2, imgName2):
imgPart2 = upload_image(imgName2, session, headers)
Expand Down

0 comments on commit e3fcf14

Please sign in to comment.