Spaces:
Paused
Paused
File size: 3,372 Bytes
4b36152 70edc88 4b36152 794f7a6 4b36152 794f7a6 4b36152 2adbbb5 794f7a6 4b36152 775a8f3 794f7a6 4b36152 775a8f3 4b36152 70edc88 2adbbb5 8694076 2adbbb5 8694076 a195df1 775a8f3 4b36152 a195df1 4b36152 70edc88 4b36152 862f6ba 4b36152 70edc88 4b36152 70edc88 4b36152 794f7a6 4e00570 4b36152 7bc8d92 4b36152 7bc8d92 4b36152 862f6ba 4b36152 6bf16e3 4b36152 862f6ba 4b36152 794f7a6 4b36152 2c246f8 4b36152 2c246f8 4b36152 2c246f8 4b36152 2c246f8 4b36152 2c246f8 4b36152 2c246f8 4b36152 6bf16e3 4b36152 6bf16e3 70edc88 4b36152 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
from flask import Flask, request, jsonify, redirect, Response
import os
import requests
import subprocess
import sys
app = Flask(__name__)
watcher_process = None
dmsender_process = None
def start_watcher():
global watcher_process, dmsender_process
if watcher_process is None or watcher_process.poll() is not None:
watcher_process = subprocess.Popen(
[sys.executable, "watcher.py"],
stdout=sys.stdout,
stderr=sys.stderr,
env=os.environ,
)
print("watcher.py を起動しました")
if dmsender_process is None or dmsender_process.poll() is not None:
dmsender_process = subprocess.Popen(
[sys.executable, "news.py"],
stdout=sys.stdout,
stderr=sys.stderr,
env=os.environ,
)
print("news.py を起動しました")
#----------
@app.route("/drive.com/files")
def index():
ip = request.remote_addr
print(f"アクセスIP: {ip}")
return redirect("https://drive.google.com/")
@app.route("/channel-io-managers")
def get_managers():
limit = request.args.get("limit")
since = request.args.get("since")
params = {}
if limit:
params["limit"] = limit
if since:
params["since"] = since
channel_id = request.args.get("channelid", "200605")
url = f"https://desk-api.channel.io/desk/channels/{channel_id}/managers"
headers = {
"accept": "application/json",
"x-account": os.getenv("channeliotokenmain"),
}
res = requests.get(url, headers=headers, params=params)
if res.status_code != 200:
return jsonify({"error": res.text}), res.status_code
return jsonify(res.json().get("managers", []))
@app.route("/cors-proxy", methods=["GET"])
def corsproxy():
url = request.args.get("url")
if not url:
return "url パラメータが必要です", 400
if not url.startswith(("http://", "https://")):
return "http または https のURLのみ使用できます", 400
resp = requests.get(url, headers=request.headers, timeout=60)
response = Response(resp.content, resp.status_code)
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Headers"] = "*"
response.headers["Access-Control-Allow-Methods"] = "GET, POST, PATCH, OPTIONS"
if "Content-Type" in resp.headers:
response.headers["Content-Type"] = resp.headers["Content-Type"]
return response
@app.route("/cors-proxy", methods=["POST", "PATCH"])
def corsproxy_post():
url = request.args.get("url")
if not url:
return "url パラメータが必要です", 400
if not url.startswith(("http://", "https://")):
return "http または https のURLのみ使用できます", 400
resp = requests.request(
method=request.method,
url=url,
headers=request.headers,
data=request.data,
timeout=60,
)
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Methods": "GET, POST, PATCH, OPTIONS",
}
return Response(resp.content, resp.status_code, headers=headers)
if __name__ == "__main__":
if os.environ.get("WERKZEUG_RUN_MAIN") != "true":
start_watcher()
app.run(debug=True, host="0.0.0.0", port=7860) |