diff --git a/..gitignore b/.gitignore similarity index 48% rename from ..gitignore rename to .gitignore index 5d7a16da456b9d95710ccebe08e413911d890c62..e534df9d48d9f1d78bdbefcf85eaa38ae0f8477e 100644 --- a/..gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -*.log -*.json +*.log +*.json /__pycache__ \ No newline at end of file diff --git a/README.md b/README.md index ac1b66e315f0665db1182ee71419e1f93546afd9..02cc726cd315a023db65cb9ca4a0c88a0cd2f587 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,27 @@ -# Video Monitor - -## 运行方式 - -1. git clone -2. cd -3. python app.py - - -## 开发环境 - -- python 3.8.8 -- 库 - - 详见requirement.txt - -## 开发进度 -- 基础监测 --- 99% -- cli --- 0% - -## issue要求 - -fix|doc|feat(模块):本次修复的描述 - -例 -> feat(cli): 新增了____功能 - -> fix(app): 修复了_____bug +# Video Monitor + +## 运行方式 + +1. git clone +2. cd +3. python app.py + + +## 开发环境 + +- python 3.8.8 +- 库 + - 详见requirement.txt + +## 开发进度 +- 基础监测 --- 99% +- cli --- 0% + +## issue要求 + +fix|doc|feat(模块):本次修复的描述 + +例 +> feat(cli): 新增了____功能 + +> fix(app): 修复了_____bug diff --git a/__pycache__/app.cpython-38.pyc b/__pycache__/app.cpython-38.pyc deleted file mode 100644 index 797b50356c7369637c227987f2608c53304108ef..0000000000000000000000000000000000000000 Binary files a/__pycache__/app.cpython-38.pyc and /dev/null differ diff --git a/app.py b/app.py index 6946949c23dd2dd8df34241b99cd17f568f7089f..9d3cfc5c53d3c2f423b13b83db1cbca9fcb7bc44 100644 --- a/app.py +++ b/app.py @@ -1,59 +1,66 @@ -import sys,os,requests,json -import logging -sys.path.append(os.path.abspath('./lib')) -from apscheduler.events import EVENT_JOB_ERROR, EVENT_JOB_EXECUTED -from apscheduler.schedulers.blocking import BlockingScheduler -from api import REQUEST_VDIEO_VDIEOLIST -from config import CONFIG - -logging.basicConfig( - level=CONFIG['LOG_LEVEL'], - format=CONFIG['LOG_FORMAT'], - filemode=CONFIG['LOG_FILEMODE'], - filename=CONFIG['LOG_FILENAME'], - datefmt=CONFIG['LOG_DATEFORMAT'] -) - -def errorCatch(event): - if (event.exception): - print(event.exception) - else: - pass - -class Monitor: - def __init__(self) -> None: - self.maxItem = 10 - self.q = [] - self.scheduler = BlockingScheduler() - self.scheduler.add_listener(errorCatch,EVENT_JOB_EXECUTED or EVENT_JOB_ERROR) - def loop(self): - self.scheduler.add_job(self.job,"interval",hours=CONFIG['BASIC_LOOPDELAY']) - self.scheduler._logger = logging - self.scheduler.start() - def job(self): - response = requests.get(REQUEST_VDIEO_VDIEOLIST + '477792') - if (response.status_code == 200): - logging.info('Request Success') - rawData = response.json()['data']['list']['vlist'][0:10] - for i in rawData: - self.q.append( - { - 'description': i['description'], - 'pic': i['pic'], - 'title': i['title'], - 'subtitle': i['subtitle'], - } - ) - if (not os.path.exists(CONFIG['SAVE_LOCATION'])): - os.mkdir(CONFIG['SAVE_LOCATION']) - fs=open(CONFIG['SAVE_LOCATION'] + CONFIG['SAVE_FILENAME'],'w',encoding='utf-8') - else: - fs=open(CONFIG['SAVE_LOCATION'] + CONFIG['SAVE_FILENAME'],'w',encoding='utf-8') - fs.write(json.dumps(self.q,ensure_ascii=False)) - self.q = [] - else: - logging.info('Reqeust Fail') - def runNow(self): - self.job() -m = Monitor() -m.loop() \ No newline at end of file +import sys,os,requests,json +import logging +sys.path.append(os.path.abspath('./lib')) +from apscheduler.events import EVENT_JOB_ERROR, EVENT_JOB_EXECUTED +from apscheduler.schedulers.blocking import BlockingScheduler +from api import REQUEST_VDIEO_VDIEOLIST +from config import CONFIG +from fake_useragent import UserAgent + +logging.basicConfig( + level=CONFIG['LOG_LEVEL'], + format=CONFIG['LOG_FORMAT'], + filemode=CONFIG['LOG_FILEMODE'], + filename=CONFIG['LOG_FILENAME'], + datefmt=CONFIG['LOG_DATEFORMAT'], + ) + +def errorCatch(event): + if (event.exception): + print(event.exception) + else: + pass +ua = UserAgent(verify_ssl=False) +class Monitor: + def __init__(self) -> None: + self.maxItem = 10 + self.q = [] + self.scheduler = BlockingScheduler() + self.scheduler.add_listener(errorCatch,EVENT_JOB_EXECUTED or EVENT_JOB_ERROR) + def loop(self): + self.scheduler.add_job(self.job,"interval",hours=CONFIG['BASIC_LOOPDELAY']) +# self.scheduler.add_job(self.job, "interval", seconds=2) + self.scheduler._logger = logging + self.scheduler.start() + def job(self): + response = requests.get(REQUEST_VDIEO_VDIEOLIST + '477792',headers={ + 'User-Agent': ua.random + }) + if (response.status_code == 200): + logging.info('Request Success') + rawData = response.json()['data']['list']['vlist'][0:10] + for i in rawData: + self.q.append( + { + 'description': i['description'], + 'pic': i['pic'], + 'title': i['title'], + 'subtitle': i['subtitle'], + } + ) + if (not os.path.exists(CONFIG['SAVE_LOCATION'])): + os.mkdir(CONFIG['SAVE_LOCATION']) + fs=open(CONFIG['SAVE_LOCATION'] + CONFIG['SAVE_FILENAME'],'w',encoding='utf-8') + else: + fs=open(CONFIG['SAVE_LOCATION'] + CONFIG['SAVE_FILENAME'],'w',encoding='utf-8') + fs.write(json.dumps(self.q,ensure_ascii=False)) + self.q = [] + logging.info("{0} save success".format(CONFIG['SAVE_LOCATION'] + CONFIG['SAVE_FILENAME'])) + print("{0} save success".format(CONFIG['SAVE_LOCATION'])) + else: + logging.error('Reqeust Fail') + logging.error('Because: {0}'.format(response.status_code)) + def runNow(self): + self.job() +m = Monitor() +m.loop() diff --git a/data.json b/data.json deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/lib/__pycache__/config.cpython-38.pyc b/lib/__pycache__/config.cpython-38.pyc index edfe81aec091d0cf8b5742118abc5fcf1a7f246f..cb4ccb62b04462c3deeae7aa414034d287939bc4 100644 Binary files a/lib/__pycache__/config.cpython-38.pyc and b/lib/__pycache__/config.cpython-38.pyc differ diff --git a/lib/api.py b/lib/api.py index bd63144cac24d96dcd03e1b4d7b6c357083519e5..2e1e4a3a4e6824efbdfe67f4e377842ee7b8a4f4 100644 --- a/lib/api.py +++ b/lib/api.py @@ -1 +1 @@ -REQUEST_VDIEO_VDIEOLIST = 'https://api.bilibili.com/x/space/arc/search?mid=' +REQUEST_VDIEO_VDIEOLIST = 'https://api.bilibili.com/x/space/arc/search?mid=' diff --git a/lib/config.py b/lib/config.py index 69d09f6aa551db2d8012f15a46cd9316f6543d78..58995ffcf4eeec98d440387b52303e4b877a4a62 100644 --- a/lib/config.py +++ b/lib/config.py @@ -1,29 +1,29 @@ -import sys,os -from logging import INFO - - -CONFIG = { - -} - -####################### -#########Basic######### -####################### - -# 默认定时时间 -CONFIG['BASIC_LOOPDELAY'] = 2 - -# 数据存放位置 -CONFIG['SAVE_LOCATION'] = os.path.abspath('./') + '\\' - -# 数据存放名称 -CONFIG['SAVE_FILENAME'] = 'data.json' - -######################## -###########Log########## -######################## -CONFIG['LOG_LEVEL'] = INFO -CONFIG['LOG_FILENAME'] = 'log.log' -CONFIG['LOG_DATEFORMAT'] = '%Y-%M-%D %H:%M:%S' -CONFIG['LOG_FORMAT'] = '%(asctime)s - [%(levelname)s] - %(message)s-%(funcName)s' -CONFIG['LOG_FILEMODE'] = 'a' \ No newline at end of file +import sys,os +from logging import INFO + + +CONFIG = { + +} + +####################### +#########Basic######### +####################### + +# 默认定时时间 +CONFIG['BASIC_LOOPDELAY'] = 2 + +# 数据存放位置 +CONFIG['SAVE_LOCATION'] = './data/' + +# 数据存放名称 +CONFIG['SAVE_FILENAME'] = 'data.json' + +######################## +###########Log########## +######################## +CONFIG['LOG_LEVEL'] = INFO +CONFIG['LOG_FILENAME'] = 'log.log' +CONFIG['LOG_DATEFORMAT'] = '%Y-%M-%D %H:%M:%S' +CONFIG['LOG_FORMAT'] = '%(asctime)s - [%(levelname)s] - %(message)s-%(funcName)s' +CONFIG['LOG_FILEMODE'] = 'a' diff --git a/log.log b/log.log deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/requirements.txt b/requirements.txt index cee98d0cfb5478db16cd0116ec5a8797dc2f1e2f..e3ef569b5b86b0267a07e98a6fc0ce2a307288cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ APScheduler==3.8.1 -MONITOR==0.0.1 -requests==2.25.1 +fake_useragent==0.1.11 +requests==2.22.0 diff --git a/tools/cli.py b/tools/cli.py index dc82ac2ad4a86080336ce89fa9df9418ef94ac67..6d50220d9c5b50c147a9af1fe22224458b3d19f2 100644 --- a/tools/cli.py +++ b/tools/cli.py @@ -1,25 +1,25 @@ -from MONITOR.app import * -print('Monitor Manager Tools v0.1') -def help(): - print("Monitor Manager Tools v0.1") - print("-h -help -- 获取帮助") - print("-update -- 强制更新") - print("-showConfig -- 列出当前配置") -def update(): - handle = Monitor() - handle.job() -def showConfig(): - print(CONFIG) - pass -stateMachine = { - '-h':help, - '-help': help, - '-update': update, - '-showConfig': showConfig -} -while True: - command = input('>: ') - try: - stateMachine[command]() - except Exception as e: +from MONITOR.app import * +print('Monitor Manager Tools v0.1') +def help(): + print("Monitor Manager Tools v0.1") + print("-h -help -- 获取帮助") + print("-update -- 强制更新") + print("-showConfig -- 列出当前配置") +def update(): + handle = Monitor() + handle.job() +def showConfig(): + print(CONFIG) + pass +stateMachine = { + '-h':help, + '-help': help, + '-update': update, + '-showConfig': showConfig +} +while True: + command = input('>: ') + try: + stateMachine[command]() + except Exception as e: print('未知命令{0},您是否输入正确?'.format(command)) \ No newline at end of file