Create __main__.py
Browse files- stylish/__main__.py +47 -0
stylish/__main__.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import asyncio
|
3 |
+
import logging
|
4 |
+
import platform
|
5 |
+
from pyrogram import idle
|
6 |
+
from stylish.bot import Stylish
|
7 |
+
|
8 |
+
|
9 |
+
logging.basicConfig(
|
10 |
+
level=logging.INFO,
|
11 |
+
format="%(name)s.%(funcName)s | %(levelname)s | %(message)s",
|
12 |
+
datefmt="[%X]",
|
13 |
+
)
|
14 |
+
logging.getLogger("pyrogram.syncer").setLevel(logging.WARNING)
|
15 |
+
logging.getLogger("pyrogram.client").setLevel(logging.WARNING)
|
16 |
+
|
17 |
+
logger = logging.getLogger(__name__)
|
18 |
+
|
19 |
+
|
20 |
+
async def main():
|
21 |
+
stylish = Stylish()
|
22 |
+
|
23 |
+
try:
|
24 |
+
# start the bot
|
25 |
+
await stylish.start()
|
26 |
+
|
27 |
+
if "test" not in sys.argv:
|
28 |
+
await idle()
|
29 |
+
except KeyboardInterrupt:
|
30 |
+
# exit gracefully
|
31 |
+
logger.warning("Forced stop, Bye!")
|
32 |
+
finally:
|
33 |
+
# close connections
|
34 |
+
await stylish.stop()
|
35 |
+
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
# open new asyncio event loop
|
39 |
+
add_event_loop = asyncio.get_event_loop_policy()
|
40 |
+
set_event_loop = add_event_loop.new_event_loop()
|
41 |
+
asyncio.set_event_loop(set_event_loop)
|
42 |
+
|
43 |
+
# start the bot
|
44 |
+
set_event_loop.run_until_complete(main())
|
45 |
+
|
46 |
+
# close asyncio event loop
|
47 |
+
set_event_loop.close()
|