-
Notifications
You must be signed in to change notification settings - Fork 1
/
heart_of_bot.py
48 lines (36 loc) · 1.13 KB
/
heart_of_bot.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
import logging
import asyncio
import argparse
logger = logging.getLogger('nojam')
logging.basicConfig(level=logging.INFO)
if __name__ == '__main__':
# Use argument parser
parser = argparse.ArgumentParser(
description='This is a script to run nojambot'
)
parser.add_argument(
'mode',
help='Choose whether to run on Slack or Twitter',
choices=['twitter', 'slack'],
type=str
)
args = parser.parse_args()
if args.mode == 'twitter':
logger.info('Run on Twitter')
from twitter_bot import Twitter
twt = Twitter()
try:
twt.execute_bot()
except KeyboardInterrupt:
logger.info('Terminate nojambot on Twitter')
else:
logger.info('Run on Slack')
from slack_bot import Slack
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
slk = Slack()
try:
asyncio.get_event_loop().run_until_complete(slk.execute_bot())
asyncio.get_event_loop().run_forever()
except KeyboardInterrupt:
logger.info('Terminate nojambot on Slack')