Created
June 14, 2012 00:36
-
-
Save petrushev/2927383 to your computer and use it in GitHub Desktop.
Irc logger on the command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from time import sleep | |
from simplejson import loads, dumps | |
from datetime import datetime | |
BASE = 'http://irc.softver.org.mk/api/_changes' | |
DEFAULT_PARAMS = {'feed':'longpoll', 'heartbeat':'30000', 'include_docs':'true', | |
'filter':'log/channel', 'channel':'lugola'} | |
def main(): | |
params = dict(DEFAULT_PARAMS) | |
last_seq = 275508 # starting log | |
headers = {'content-type': 'application/json'} | |
while True: | |
params['since'] = last_seq | |
r = requests.get(BASE, params=params, headers=headers) | |
json_ = loads(r.text.strip()) | |
for item in json_['results']: | |
doc = item['doc'] | |
sent = datetime.fromtimestamp(doc['timestamp']) | |
print "%s [%s] %s" % (sent.strftime("%H:%M"), doc['sender'], doc['message']) | |
last_seq = json_['last_seq'] | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment