generated from jarp0l/discord.py-bot-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeep_alive.py
58 lines (38 loc) · 1.28 KB
/
keep_alive.py
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
from flask import Flask, Response
from threading import Thread
from apscheduler.schedulers.background import BackgroundScheduler
from libs.my_feed import MyFeed
app = Flask(__name__)
@app.route("/")
def home():
return "076bei-bot is running."
@app.route("/rss")
def feed():
with open("feed/rss.xml") as f:
xml = f.readlines()
r = Response(response=xml, status=200, mimetype="application/xml")
r.headers["Content-Type"] = "text/xml; charset=utf-8"
return r
@app.route("/feed/rss.xml")
def feed_old():
with open("feed/rss.xml") as f:
xml = f.readlines()
r = Response(response=xml, status=200, mimetype="application/xml")
r.headers["Content-Type"] = "text/xml; charset=utf-8"
return r
# def deploy():
# import subprocess
# exec_cmd = '''npx surge ./_site --domain "$SURGE_DOMAIN" --token "$SURGE_TOKEN"'''
# # if update_feed:
# MyFeed().update_feed()
# process = subprocess.Popen(exec_cmd.split(), stdout=subprocess.PIPE)
# output, error = process.communicate()
scheduler = BackgroundScheduler()
scheduler.add_job(MyFeed().update_feed, "interval", minutes=30)
scheduler.start()
def run():
MyFeed().update_feed()
app.run(host="0.0.0.0", port=1337)
def keep_alive():
t = Thread(target=run)
t.start()