rogerxavier commited on
Commit
3ec3367
1 Parent(s): 92a3b39

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +64 -65
api.py CHANGED
@@ -1,65 +1,64 @@
1
-
2
- import uvicorn
3
- from fastapi import FastAPI
4
- from utils import *
5
- from typing import *
6
- from config import *
7
- from apscheduler.schedulers.background import BackgroundScheduler#定时任务
8
-
9
- scheduler = BackgroundScheduler()#这个不要用缓存的
10
-
11
-
12
- def load_config():
13
- return get_variables()
14
-
15
- class configData():
16
- def update(self):
17
- self.data = load_config()
18
- print(self.data)
19
- return self.data
20
-
21
-
22
- configData = configData()#复用实例
23
- app = FastAPI()
24
-
25
- def periodic_function():
26
- data = configData.update()
27
- print(f'定时执行的操作时间:{datetime.now()}')
28
- print("是否允许定时任务",data['allow_scheduler'])
29
- run_asp_task()#执行asp任务进行发送
30
-
31
-
32
-
33
-
34
- #启动app时候的定时任务 - 每天根据manga_abs_dir路径是否有jpg文件来判断是否运行
35
- @app.on_event("startup")
36
- async def app_start():
37
- #scheduler.add_job(periodic_function, 'interval', seconds=55)
38
- scheduler.add_job(periodic_function, 'interval', seconds=18000)#间隔5小时执行一次
39
- scheduler.start()
40
-
41
-
42
-
43
- # 返回当前目录及其子目录下的所有信息
44
- @app.get("/listFiles")
45
- def list_files_func():
46
- result = list_files()
47
- return result
48
-
49
- # 返回一个章节并删除
50
- @app.get("/random_chapter")
51
- def random_chapter_handler():
52
- result = random_chapter()
53
- return result
54
-
55
-
56
-
57
-
58
- #两个blocks放到不同的地方,一个管理manga素材上传,一个管理任务处理
59
- app = gr.mount_gradio_app(app, mangaManager, path="/gr")
60
- #下面这个暂不更新->没想到太大作用
61
- app = gr.mount_gradio_app(app, taskManager, path="/taskManager")
62
-
63
- if __name__ == '__main__':
64
-
65
- uvicorn.run(app, host='0.0.0.0', port=7860)
 
1
+
2
+ import uvicorn
3
+ from fastapi import FastAPI
4
+ from utils import *
5
+ from typing import *
6
+ from config import *
7
+ from apscheduler.schedulers.background import BackgroundScheduler#定时任务
8
+
9
+ scheduler = BackgroundScheduler()#这个不要用缓存的
10
+
11
+
12
+ def load_config():
13
+ return get_variables()
14
+
15
+ class configData():
16
+ def update(self):
17
+ self.data = load_config()
18
+ print(self.data)
19
+ return self.data
20
+
21
+
22
+ configData = configData()#复用实例
23
+ app = FastAPI()
24
+
25
+ def periodic_function():
26
+ data = configData.update()
27
+ print(f'定时执行的操作时间:{datetime.now()}')
28
+ print("是否允许定时任务",data['allow_scheduler'])
29
+ run_asp_task()#执行asp任务进行发送
30
+
31
+
32
+
33
+
34
+ #启动app时候的定时任务 - 每天根据manga_abs_dir路径是否有jpg文件来判断是否运行
35
+ @app.on_event("startup")
36
+ async def app_start():
37
+ #scheduler.add_job(periodic_function, 'interval', seconds=55)
38
+ scheduler.add_job(periodic_function, 'interval', seconds=18000)#间隔5小时执行一次
39
+ scheduler.start()
40
+
41
+
42
+
43
+ # 返回当前目录及其子目录下的所有信息
44
+ @app.get("/listFiles")
45
+ def list_files_func():
46
+ result = list_files()
47
+ return result
48
+
49
+ # 返回一个章节并删除
50
+ @app.get("/random_chapter")
51
+ def random_chapter_handler():
52
+ result = random_chapter()
53
+ return result
54
+
55
+
56
+
57
+
58
+ #两个blocks放到不同的地方,一个管理manga素材上传,一个管理任务处理
59
+ app = gr.mount_gradio_app(app, mangaManager, path="/gr")
60
+ #下面这个暂不更新->没想到太大作用
61
+ app = gr.mount_gradio_app(app, taskManager, path="/taskManager")
62
+
63
+ if __name__ == '__main__':
64
+ uvicorn.run(app, host='0.0.0.0', port=7860)