lqg 2 years ago
parent
commit
26cf24eca0

+ 0 - 0
conf/main.ui → conf/configure_window.ui


+ 1 - 1
crawl_baidu/__init__.py

@@ -8,7 +8,7 @@
 '''
 
 from PyQt5.QtWidgets import QApplication
-from crawl_baidu.qt_ui import ConfigureWindow
+from crawl_baidu.pages.configure_window import ConfigureWindow
 
 def main():
     app=QApplication([])

+ 1 - 1
crawl_baidu/crawl_baidu.py

@@ -11,7 +11,7 @@
 from http import cookies
 import requests
 import sys,os,json
-from crawl_baidu.lib.json_conf import JsonConf
+from crawl_baidu.utils.json_conf import JsonConf
 import time
 headers = {
     'Accept': 'application/json, text/plain, */*',

+ 0 - 0
crawl_baidu/lib/__init__.py → crawl_baidu/pages/__init__.py


+ 94 - 122
crawl_baidu/qt_ui.py → crawl_baidu/pages/base_window.py

@@ -1,122 +1,94 @@
-#!/usr/bin/env python
-# -*- encoding: utf-8 -*-
-'''
-@Contact :   liuyuqi.gov@msn.cn
-@Time    :   2022/06/29 12:42:58
-@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
-@Desc    :   main ui
-'''
-
-from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsDropShadowEffect, QListWidgetItem, QListView, QWidget, \
-    QLabel, QHBoxLayout, QFileDialog
-from PyQt5.QtCore import Qt, QPropertyAnimation, QEasingCurve, QThread, pyqtSignal, QMutex, QSize, QEvent, QPoint
-from PyQt5.QtGui import QMouseEvent, QCursor, QColor
-from PyQt5.uic import loadUi
-
-class Window(QMainWindow):
-    '''主窗体'''
-
-    def mousePressEvent(self, event):
-        # 重写一堆方法使其支持拖动
-        if event.button() == Qt.LeftButton:
-            self.m_drag = True
-            self.m_DragPosition = event.globalPos() - self.pos()
-            event.accept()
-
-    def mouseMoveEvent(self, QMouseEvent):
-        try:
-            if Qt.LeftButton and self.m_drag:
-                self.move(QMouseEvent.globalPos() - self.m_DragPosition)
-                QMouseEvent.accept()
-        except:
-            pass
-
-    def mouseReleaseEvent(self, QMouseEvent):
-        self.m_drag = False
-
-    def _frame(self):
-        # 边框
-        self.setWindowFlags(Qt.FramelessWindowHint)
-        self.setAttribute(Qt.WA_TranslucentBackground, True)
-        # 阴影
-        effect = QGraphicsDropShadowEffect(blurRadius=12, xOffset=0, yOffset=0)
-        effect.setColor(QColor(25, 25, 25, 170))
-        # self.mainFrame.setGraphicsEffect(effect)
-
-    def doFadeIn(self):
-        # 动画
-        self.animation = QPropertyAnimation(self, b'windowOpacity')
-        # 持续时间250ms
-        self.animation.setDuration(250)
-        try:
-            # 尝试先取消动画完成后关闭窗口的信号
-            self.animation.finished.disconnect(self.close)
-        except:
-            pass
-        self.animation.stop()
-        # 透明度范围从0逐渐增加到1
-        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
-        self.animation.setStartValue(0)
-        self.animation.setEndValue(1)
-        self.animation.start()
-
-    def doFadeOut(self):
-        self.animation.stop()
-        # 动画完成则关闭窗口
-        self.animation.finished.connect(self.close)
-        # 透明度范围从1逐渐减少到0s
-        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
-        self.animation.setStartValue(1)
-        self.animation.setEndValue(0)
-        self.animation.start()
-
-    def setWarninginfo(self, text):
-        self.lab_info.setStyleSheet("""
-            .QLabel {
-                border:1px solid #ffccc7;
-                border-radius:3px;
-                line-height: 140px;
-                padding: 5px;
-                color: #434343;
-                background: #fff2f0;
-            }
-            """)
-        self.lab_info.setText(text)
-
-    def setSuccessinfo(self, text):
-        self.lab_info.setStyleSheet("""
-            .QLabel {
-                border:1px solid #b7eb8f;
-                border-radius:3px;
-                line-height: 140px;
-                padding: 5px;
-                color: #434343;
-                background: #f6ffed;
-            }
-            """)
-        self.lab_info.setText(text)
-
-class ConfigureWindow(Window):
-    '''配置弹框'''
-    config = {}
-    def __init__(self):
-        super().__init__()
-        loadUi("./conf/main.ui", self)
-        # self._frame()
-        # self._eventfilter()
-        # self.doFadeIn()
-        self.config_exists = True
-
-        # 判断配置文件是否存在
-        # if not os.path.exists(working_dir + "/config.json"):
-        #     self.setWarninginfo("配置文件不存在!请单击“设置”创建配置文件")
-        #     self.config_exists = False
-
-        self.show()
-        
-    def saveConf(self):
-        self.updateConfig()
-        self.doFadeOut()
-
-    def updateConfig():
-        pass
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2023/03/16 01:29:59
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   base windows
+'''
+from PyQt5.QtWidgets import QMainWindow, QGraphicsDropShadowEffect
+from PyQt5.QtCore import Qt, QPropertyAnimation, QEasingCurve
+from PyQt5.QtGui import QColor
+
+class BaseWindow(QMainWindow):
+    '''主窗体'''
+
+    def mousePressEvent(self, event):
+        # 重写一堆方法使其支持拖动
+        if event.button() == Qt.LeftButton:
+            self.m_drag = True
+            self.m_DragPosition = event.globalPos() - self.pos()
+            event.accept()
+
+    def mouseMoveEvent(self, QMouseEvent):
+        try:
+            if Qt.LeftButton and self.m_drag:
+                self.move(QMouseEvent.globalPos() - self.m_DragPosition)
+                QMouseEvent.accept()
+        except:
+            pass
+
+    def mouseReleaseEvent(self, QMouseEvent):
+        self.m_drag = False
+
+    def _frame(self):
+        # 边框
+        self.setWindowFlags(Qt.FramelessWindowHint)
+        self.setAttribute(Qt.WA_TranslucentBackground, True)
+        # 阴影
+        effect = QGraphicsDropShadowEffect(blurRadius=12, xOffset=0, yOffset=0)
+        effect.setColor(QColor(25, 25, 25, 170))
+        # self.mainFrame.setGraphicsEffect(effect)
+
+    def doFadeIn(self):
+        # 动画
+        self.animation = QPropertyAnimation(self, b'windowOpacity')
+        # 持续时间250ms
+        self.animation.setDuration(250)
+        try:
+            # 尝试先取消动画完成后关闭窗口的信号
+            self.animation.finished.disconnect(self.close)
+        except:
+            pass
+        self.animation.stop()
+        # 透明度范围从0逐渐增加到1
+        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
+        self.animation.setStartValue(0)
+        self.animation.setEndValue(1)
+        self.animation.start()
+
+    def doFadeOut(self):
+        self.animation.stop()
+        # 动画完成则关闭窗口
+        self.animation.finished.connect(self.close)
+        # 透明度范围从1逐渐减少到0s
+        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
+        self.animation.setStartValue(1)
+        self.animation.setEndValue(0)
+        self.animation.start()
+
+    def setWarninginfo(self, text):
+        self.lab_info.setStyleSheet("""
+            .QLabel {
+                border:1px solid #ffccc7;
+                border-radius:3px;
+                line-height: 140px;
+                padding: 5px;
+                color: #434343;
+                background: #fff2f0;
+            }
+            """)
+        self.lab_info.setText(text)
+
+    def setSuccessinfo(self, text):
+        self.lab_info.setStyleSheet("""
+            .QLabel {
+                border:1px solid #b7eb8f;
+                border-radius:3px;
+                line-height: 140px;
+                padding: 5px;
+                color: #434343;
+                background: #f6ffed;
+            }
+            """)
+        self.lab_info.setText(text)

+ 36 - 0
crawl_baidu/pages/configure_window.py

@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2023/03/16 01:29:59
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   configure windows
+'''
+
+from crawl_baidu.pages.base_window import BaseWindow
+from PyQt5.uic import loadUi
+
+class ConfigureWindow(BaseWindow):
+    '''配置窗口,主窗口'''
+    config = {}
+    def __init__(self):
+        super().__init__()
+        loadUi("./conf/configure_window.ui", self)
+        # self._frame()
+        # self._eventfilter()
+        # self.doFadeIn()
+        self.config_exists = True
+
+        # 判断配置文件是否存在
+        # if not os.path.exists(working_dir + "/config.json"):
+        #     self.setWarninginfo("配置文件不存在!请单击“设置”创建配置文件")
+        #     self.config_exists = False
+
+        self.show()
+        
+    def saveConf(self):
+        self.updateConfig()
+        self.doFadeOut()
+
+    def updateConfig():
+        pass

+ 0 - 0
crawl_baidu/utils/__init__.py


+ 66 - 66
crawl_baidu/lib/json_conf.py → crawl_baidu/utils/json_conf.py

@@ -1,66 +1,66 @@
-#!/usr/bin/env python
-# -*- encoding: utf-8 -*-
-'''
-@Contact :   liuyuqi.gov@msn.cn
-@Time    :   2022/05/24 15:07:14
-@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
-@Desc    :   yaml util
-'''
-import os
-import json
-
-config_path = "conf/config.json"
-
-
-class JsonConf:
-    '''json配置文件类'''
-    @staticmethod
-    def save(data):
-        global config_path
-        with open(config_path, 'w') as json_file:
-            json_file.write(json.dumps(data, indent=4))
-
-    @staticmethod
-    def load():
-        global config_path
-        if not os.path.exists(config_path):
-            with open(config_path, 'w') as json_file:
-                pass
-        with open(config_path, encoding="utf-8") as json_file:
-            try:
-                data = json.load(json_file)
-            except Exception as e:
-                if(str(e).index("utf-8-sig") > 0):
-                    with open(config_path, encoding="utf-8-sig") as json_file:
-                        data = json.load(json_file)
-                        return data
-                else:
-                    print(e)
-            return data
-
-    @staticmethod
-    def set(data_dict):
-        json_obj = JsonConf.load()
-        for key in data_dict:
-            json_obj[key] = data_dict[key]
-        JsonConf.save(json_obj)
-        print(json.dumps(json_obj, indent=4))
-
-    @staticmethod
-    def get(key, default_val=""):
-        '''
-        配置文件获取key对象的值,如果没有设置就返回默认值
-        '''
-        try:
-            result = JsonConf.load()[key]
-            return result
-        except Exception as e:
-            print(e)
-            return default_val
-
-    @staticmethod
-    def get(jsonData, key, default_val=""):
-        try:
-            return jsonData[key]
-        except Exception as e:
-            return default_val
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/05/24 15:07:14
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   yaml util
+'''
+import os
+import json
+
+config_path = "conf/config.json"
+
+
+class JsonConf:
+    '''json配置文件类'''
+    @staticmethod
+    def save(data):
+        global config_path
+        with open(config_path, 'w') as json_file:
+            json_file.write(json.dumps(data, indent=4))
+
+    @staticmethod
+    def load():
+        global config_path
+        if not os.path.exists(config_path):
+            with open(config_path, 'w') as json_file:
+                pass
+        with open(config_path, encoding="utf-8") as json_file:
+            try:
+                data = json.load(json_file)
+            except Exception as e:
+                if(str(e).index("utf-8-sig") > 0):
+                    with open(config_path, encoding="utf-8-sig") as json_file:
+                        data = json.load(json_file)
+                        return data
+                else:
+                    print(e)
+            return data
+
+    @staticmethod
+    def set(data_dict):
+        json_obj = JsonConf.load()
+        for key in data_dict:
+            json_obj[key] = data_dict[key]
+        JsonConf.save(json_obj)
+        print(json.dumps(json_obj, indent=4))
+
+    @staticmethod
+    def get(key, default_val=""):
+        '''
+        配置文件获取key对象的值,如果没有设置就返回默认值
+        '''
+        try:
+            result = JsonConf.load()[key]
+            return result
+        except Exception as e:
+            print(e)
+            return default_val
+
+    @staticmethod
+    def get(jsonData, key, default_val=""):
+        try:
+            return jsonData[key]
+        except Exception as e:
+            return default_val

+ 49 - 49
crawl_baidu/lib/yml_conf.py → crawl_baidu/utils/yml_conf.py

@@ -1,50 +1,50 @@
-'''
-Created on 2019430
-
-yaml一般用来写配置文件。
-@author: liuyuqi
-'''
-
-import yaml
-import os
-
-config_path ="conf/config.yml"
-
-class YamlConf:
-    '''
-    yaml配置
-    '''
-    @staticmethod
-    def save(data):
-        global config_path
-        try:
-            yaml.dump(data, open(config_path, "w"))
-        except Exception as e:
-            print(e)
-
-    @staticmethod
-    def load():
-        global config_path
-        config = {}
-        try:
-            config = yaml.load(open(config_path, "r", encoding="utf-8"), Loader=yaml.SafeLoader)
-            if config is None:
-                config = {}
-        except Exception as e:
-            print(e)
-        return config
-
-    @staticmethod
-    def set(data_dict):
-        json_obj = YamlConf.load()
-        for key in data_dict:
-            json_obj[key] = data_dict[key]
-        YamlConf.save(json_obj)
-    
-    @staticmethod
-    def get(key, default_val=""):
-        try:
-            result = YamlConf.load()[key]
-            return result
-        except Exception as e:
+'''
+Created on 2019430
+
+yaml一般用来写配置文件。
+@author: liuyuqi
+'''
+
+import yaml
+import os
+
+config_path ="conf/config.yml"
+
+class YamlConf:
+    '''
+    yaml配置
+    '''
+    @staticmethod
+    def save(data):
+        global config_path
+        try:
+            yaml.dump(data, open(config_path, "w"))
+        except Exception as e:
+            print(e)
+
+    @staticmethod
+    def load():
+        global config_path
+        config = {}
+        try:
+            config = yaml.load(open(config_path, "r", encoding="utf-8"), Loader=yaml.SafeLoader)
+            if config is None:
+                config = {}
+        except Exception as e:
+            print(e)
+        return config
+
+    @staticmethod
+    def set(data_dict):
+        json_obj = YamlConf.load()
+        for key in data_dict:
+            json_obj[key] = data_dict[key]
+        YamlConf.save(json_obj)
+    
+    @staticmethod
+    def get(key, default_val=""):
+        try:
+            result = YamlConf.load()[key]
+            return result
+        except Exception as e:
             return default_val

+ 0 - 44
demo.spec

@@ -1,44 +0,0 @@
-# -*- mode: python ; coding: utf-8 -*-
-
-
-block_cipher = None
-
-
-a = Analysis(
-    ['demo.py'],
-    pathex=[],
-    binaries=[],
-    datas=[],
-    hiddenimports=[],
-    hookspath=[],
-    hooksconfig={},
-    runtime_hooks=[],
-    excludes=[],
-    win_no_prefer_redirects=False,
-    win_private_assemblies=False,
-    cipher=block_cipher,
-    noarchive=False,
-)
-pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
-
-exe = EXE(
-    pyz,
-    a.scripts,
-    a.binaries,
-    a.zipfiles,
-    a.datas,
-    [],
-    name='demo',
-    debug=False,
-    bootloader_ignore_signals=False,
-    strip=False,
-    upx=True,
-    upx_exclude=[],
-    runtime_tmpdir=None,
-    console=True,
-    disable_windowed_traceback=False,
-    argv_emulation=False,
-    target_arch=None,
-    codesign_identity=None,
-    entitlements_file=None,
-)

+ 1 - 1
requirements.txt

@@ -1,2 +1,2 @@
-requests
+requests==2.27.1
 PyQt5==5.9.2