Skip to content

Instantly share code, notes, and snippets.

@petrushev
Created June 14, 2012 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrushev/2927383 to your computer and use it in GitHub Desktop.
Save petrushev/2927383 to your computer and use it in GitHub Desktop.
Irc logger on the command line
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