jack 1 жил өмнө
parent
commit
57e638d10a
1 өөрчлөгдсөн 21 нэмэгдсэн , 15 устгасан
  1. 21 15
      flaticon/flaticon.py

+ 21 - 15
flaticon/flaticon.py

@@ -175,7 +175,7 @@ def download_img(load_data, target_file_path):
                 cursor.execute(query, (True, id))
                 conn.commit()
 
-                print(f'已下载:{img_name}')
+                # print(f'已下载:{img_name}')
                 time.sleep(random.uniform(1, 2))
                 break
             except Exception as e:
@@ -312,24 +312,29 @@ def check_local_downloads_dir():
     return target_file_path
 
 
+def check_target_url_txt():
+    txt_file_name = 'target_link.txt'
+    if not os.path.exists(txt_file_name):
+        with open(txt_file_name, 'w') as file:
+            file.write('')
+        print('需要在 target_link.txt 中填写目标链接')
+        exit(0)
+    else:
+        with open('target_link.txt', 'r') as f:
+            targets = [target.strip() for target in f.readlines()]
+            if not targets:
+                print('在 target_link.txt 中未找到目标链接')
+                exit(0)
+
+    return targets
+
+
 if __name__ == "__main__":
     # 检查数据库
     check_psql()
 
     if step == 1:
-        txt_file_name = 'target_link.txt'
-        if not os.path.exists(txt_file_name):
-            with open(txt_file_name, 'w') as file:
-                file.write('')
-            print('需要在 target_link.txt 中填写目标链接')
-            exit(0)
-        else:
-            with open('target_link.txt', 'r') as f:
-                targets = [target.strip() for target in f.readlines()]
-                if not targets:
-                    print('在 target_link.txt 中未找到目标链接')
-                    exit(0)
-
+        targets = check_target_url_txt()
         open_browser(targets)
     elif step == 2:
         # 开始读取数据
@@ -340,7 +345,8 @@ if __name__ == "__main__":
         download_img(load_data, target_file_path)
         print('下载完成, 程序退出')
     elif step == 3:
-        #  保存 img 链接
+        targets = check_target_url_txt()
+        #  保存 img 合集链接
         open_browser(targets)
 
         # 开始读取数据