-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
37 lines (27 loc) · 967 Bytes
/
test.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
import asyncio
import os
from listeners import get_listeners
from listeners.abstract_listener import AbstractListener, MessageResult
from parsers import get_parser_for_url
from utils.string_utils import StringUtils
async def main():
'''
Entry point of the app
'''
def handle(listener: AbstractListener, result: MessageResult) -> None:
url = StringUtils.find_url(result.text)
if url:
parsed_video = get_parser_for_url(result.text)[0].parse(result.text)
listener.send(MessageResult(parsed_video.to_json(), result.extra))
listeners = get_listeners(dict(os.environ))
for listener in listeners:
asyncio.ensure_future(listener.start(handler=handle))
try:
while 1:
await asyncio.sleep(1)
except KeyboardInterrupt:
print('bye')
if __name__ == "__main__":
#raise SystemExit(main())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())