Spaces:
Running
Running
set -e | |
run_script() { | |
echo "开始执行脚本" | |
# 确保我们在正确的目录 | |
cd /app | |
# clone 代码 | |
if [ "${GIT_CLONE_PROXY}" = "1" ]; then | |
echo "克隆 aggregator(使用 ghproxy 代理)" | |
git clone https://mirror.ghproxy.com/https://github.com/wzdnzd/aggregator.git | |
else | |
echo "克隆 aggregator" | |
git clone https://github.com/wzdnzd/aggregator.git | |
fi | |
# 设置代理 | |
export https_proxy=$PROXY http_proxy=$PROXY all_proxy=$PROXY | |
# 运行代码 | |
echo "运行 collect.py" | |
cd /app/aggregator && python -u subscribe/collect.py -si | |
echo "运行 merged2upload.py" | |
python /app/merged2upload.py | |
# 清理克隆的代码 | |
cd /app && rm -rf aggregator | |
} | |
# 立即运行一次脚本 | |
run_script | |
# 启动调度器 | |
python /app/scheduler.py & | |
# 启动一个简单的 HTTP 服务器来提供merged.txt文件 | |
echo "启动 HTTP 服务器在端口 8080" | |
python -c " | |
import http.server | |
import socketserver | |
class Handler(http.server.SimpleHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.send_header('Content-type', 'text/plain') | |
self.end_headers() | |
with open('/app/merged.txt', 'rb') as file: | |
self.wfile.write(file.read()) | |
with socketserver.TCPServer(('', 8080), Handler) as httpd: | |
print('服务器运行在端口 8080...') | |
httpd.serve_forever() | |
" |