I’ve been messing with this for a while and finally got it working – thanks recent Python class!

Here’s the code

 

import json
import urllib2
import time
from datetime import datetime, timedelta, date

def sendToKodi(message):
req = urllib2.Request(‘http://TV:80/jsonrpc’)
req.add_header(‘Content-Type’, ‘application/json’)
data = {“jsonrpc”:”2.0″,”method”:”GUI.ShowNotification”,”params”:{“title”:”Caller ID”, “message”:message},”id”:1}
response = urllib2.urlopen(req, json.dumps(data))

def tail_f(file):
interval = 1.0

while True:
where = file.tell()
line = file.readline()
if not line:
time.sleep(interval)
file.seek(where)
else:
yield line

for line in tail_f(open(‘/var/log/router.log’)):
if “CID” in line:
print line
splits = line.split()
month = splits[0]
day = int(splits[1].strip())
timestamp = splits[2]
cid = line.split(“:”,3)[3]
cur_year = datetime.now().year
log_datetime = datetime.strptime(month + ” ” + str(day) + ” ” + str(cur_year) + ” ” + timestamp, “%b %d %Y %H:%M:%S”)
print “Curtime<%s> log_time<%s>”%(datetime.now(),log_datetime)
if datetime.now() < log_datetime + timedelta(seconds=10): #if within last 10 seconds
#send to kodi
print “Kodi”
sendToKodi(cid)
else:
print “old log %s %s” % (cid, log_datetime)