Upload 4 files
Browse files- Dockerfile +2 -0
- README.md +1 -1
- app.py +30 -7
- requirements.txt +3 -1
Dockerfile
CHANGED
@@ -8,4 +8,6 @@ COPY ./app.py /code/app.py
|
|
8 |
|
9 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
10 |
|
|
|
|
|
11 |
CMD ["python", "app.py"]
|
|
|
8 |
|
9 |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
10 |
|
11 |
+
EXPOSE 7860
|
12 |
+
|
13 |
CMD ["python", "app.py"]
|
README.md
CHANGED
@@ -6,5 +6,5 @@ colorTo: indigo
|
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
license: mit
|
9 |
-
app_port:
|
10 |
---
|
|
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
license: mit
|
9 |
+
app_port: 7860
|
10 |
---
|
app.py
CHANGED
@@ -1,6 +1,11 @@
|
|
1 |
import requests
|
2 |
import schedule
|
3 |
import time
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def check_available_tokens():
|
6 |
"""
|
@@ -46,7 +51,7 @@ def read_and_prepare_tokens(file_path):
|
|
46 |
|
47 |
def post_tokens():
|
48 |
"""
|
49 |
-
读取tokens并发送单次POST请求
|
50 |
"""
|
51 |
# 首先检查是否需要发送 tokens
|
52 |
if not check_available_tokens():
|
@@ -75,17 +80,35 @@ def post_tokens():
|
|
75 |
except Exception as e:
|
76 |
print(f"请求发生错误: {e}")
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
def main():
|
79 |
# 立即执行一次
|
80 |
-
post_tokens()
|
81 |
|
82 |
# 每5分钟执行一次
|
83 |
-
schedule.every(5).minutes.do(post_tokens)
|
84 |
|
85 |
# 持续运行
|
86 |
-
|
87 |
-
schedule.run_pending()
|
88 |
-
time.sleep(1)
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
-
main()
|
|
|
|
|
|
1 |
import requests
|
2 |
import schedule
|
3 |
import time
|
4 |
+
import os
|
5 |
+
|
6 |
+
import threading
|
7 |
+
from fastapi import FastAPI
|
8 |
+
app = FastAPI()
|
9 |
|
10 |
def check_available_tokens():
|
11 |
"""
|
|
|
51 |
|
52 |
def post_tokens():
|
53 |
"""
|
54 |
+
检查, 读取tokens并发送单次POST请求
|
55 |
"""
|
56 |
# 首先检查是否需要发送 tokens
|
57 |
if not check_available_tokens():
|
|
|
80 |
except Exception as e:
|
81 |
print(f"请求发生错误: {e}")
|
82 |
|
83 |
+
def run_schedule():
|
84 |
+
"""
|
85 |
+
运行定时任务
|
86 |
+
"""
|
87 |
+
while True:
|
88 |
+
schedule.run_pending()
|
89 |
+
time.sleep(1)
|
90 |
+
|
91 |
+
@app.on_event("startup")
|
92 |
+
async def startup_event():
|
93 |
+
"""
|
94 |
+
应用启动时初始化定时任务
|
95 |
+
"""
|
96 |
+
schedule.every(5).minutes.do(post_tokens)
|
97 |
+
# 在新线程中运行定时任务
|
98 |
+
threading.Thread(target=run_schedule, daemon=True).start()
|
99 |
+
|
100 |
+
@app.get("/")
|
101 |
def main():
|
102 |
# 立即执行一次
|
103 |
+
#post_tokens()
|
104 |
|
105 |
# 每5分钟执行一次
|
106 |
+
#schedule.every(5).minutes.do(post_tokens)
|
107 |
|
108 |
# 持续运行
|
109 |
+
#run_schedule()
|
|
|
|
|
110 |
|
111 |
if __name__ == "__main__":
|
112 |
+
#main()
|
113 |
+
import uvicorn
|
114 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
requests
|
2 |
-
schedule
|
|
|
|
|
|
1 |
requests
|
2 |
+
schedule
|
3 |
+
fastapi
|
4 |
+
uvicorn
|