This repository was archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (59 loc) · 1.59 KB
/
main.py
File metadata and controls
72 lines (59 loc) · 1.59 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
This is a re-write of my old bot at https://goo.gl/ekxnJS
into python3 and adding a logging library
risingsunomi
"""
import signal
import os
import sys
import logging
import time
import local
from RSS import RSS
from IRCClient import IRCClient
# signal from keyboard handler
def killKey(signum, frame):
"""
kill key being ctrl+c
"""
MAIN_LOGGER.info('Kill key manually called')
sys.exit(0)
def app(nickname, channels, network):
"""
Where the news and irc client is placed
"""
MAIN_LOGGER.info('Initializing IRCClient with RSS')
# rssobj = RSS('http://www.rssmix.com/u/8273687/rss.xml')
# rssobj.readFeed()
# print("\n\nrssobj entry - {}".format(rssobj.news_entries[0]))
iclient = IRCClient(
nickname=nickname,
channels=channels,
network=network,
rssobj=RSS(local.RSSFEEDS)
)
MAIN_LOGGER.info('Connecting to irc server ')
iclient.connect()
if __name__ == '__main__':
"""
This will run the bot and will have methods to connect, scrape rss and
output
"""
# setup logging
LOGGINGDIR = '{}/logs/'.format(
os.path.dirname(os.path.realpath(__file__)))
if not os.path.exists(LOGGINGDIR):
os.makedirs(LOGGINGDIR)
MAIN_LOGGER = logging.getLogger('newsirc.main')
LOGFILEHANDLER = logging.FileHandler(
time.strftime(
"{}Main%m%d%Y.log".format(LOGGINGDIR))
)
LOGFORMAT = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
LOGFILEHANDLER.setFormatter(LOGFORMAT)
MAIN_LOGGER.addHandler(LOGFILEHANDLER)
# add signal handling
signal.signal(signal.SIGINT, killKey)
MAIN_LOGGER.info('Running app method')
app(local.NICKNAME, local.CHANNELS, local.SERVER)