-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-logs.py
executable file
·72 lines (65 loc) · 1.77 KB
/
get-logs.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vi: set ft=python :
'''
Get Ubuntu IRC logs
usage: get-logs.py [--DATE=DATE] [--channel=channel]
options:
-c channel, --channel channel The channel whose logs you want to get [default: ubuntu-desktop]
-d DATE, --DATE=DATE The DATE of the logs in format YYYY-MM-DD [default: today]
'''
import sys
import datetime
import requests
import docopt
try:
from raffaello import Raffaello, parse_request
REQUEST = r'''
\d+:\d+=>cyan_bold
flexiondotorg=>color007_bold
Laney=>color049_bold
jbicha=>color230_bold
seb128=>yellow_bold
Trevinho=>color120_bold
tsimonq2=>color117_bold
willcooke=>color122_bold
hikiko=>bgcolor019_bold
didrocks=>color111_bold
duflu=>color229_bold
oSoMoN=>color123_bold
kenvandine=>color210_bold
n-m=>yellow_bold
network\smanager=>yellow_bold
m-m=>yellow_bold
clobrano=>green_bold
'''
RAFFAELLO = Raffaello(parse_request(REQUEST))
except ImportError as error:
print('could not colorize output: {}'.format(error))
RAFFAELLO = None
OPTS = docopt.docopt(__doc__)
DATE = OPTS['--DATE']
if DATE == 'today':
DATE = str(datetime.datetime.now()).replace('-', '/').split(' ')[0]
else:
DATE = DATE.replace('-', '/')
CHANNEL = OPTS['--channel']
URL = 'https://irclogs.ubuntu.com/{DATE}/%23{channel}.txt'.format(DATE=DATE, channel=CHANNEL)
ALERT = False
MESSAGES = []
for line in requests.get(URL).text.split('\\n'):
line = line.rstrip()
if "lobrano" in line or "carlo" in line:
ALERT = True
MESSAGES.append(line)
if RAFFAELLO:
print(RAFFAELLO.paint(line))
else:
print(line)
if ALERT:
print("\n\nThere are messages for you")
for msg in MESSAGES:
if RAFFAELLO:
print(RAFFAELLO.paint(msg))
else:
print(msg)