Last active
May 15, 2020 23:37
-
-
Save koi8-r/59f0d170414e7c86b56444ab7c9264e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiohttp import web, ClientSession as UA | |
import asyncio as A | |
import sys, os | |
def update(data: bytes): | |
path = __file__ | |
with open(path, mode='wb') as f: | |
f.write(data) | |
print('Updated') | |
print(sys.executable) | |
print(sys.argv) | |
os.execl(sys.executable, *sys.argv) | |
async def update_svc(_app): | |
while True: | |
await A.sleep(1) | |
async with UA() as ua: | |
async with ua.get('https://gist.githubusercontent.com/koi8-r/59f0d170414e7c86b56444ab7c9264e3/raw/a19447a8451c2974626ecb819b8c50389b53e196/pst-updater.py') as resp: | |
script: bytes = await resp.read() | |
update(script) | |
async def start_background_tasks(app): | |
app['update_svc'] = A.create_task(update_svc(app)) | |
async def stop_background_tasks(app): | |
app['update_svc'].cancel() | |
await app['update_svc'] | |
async def index(req: web.Request): | |
return web.Response(text='Home') | |
app = web.Application() | |
app.on_startup.append(start_background_tasks) | |
app.on_cleanup.append(stop_background_tasks) | |
app.get('/', index) | |
web.run_app(app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment