This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

pager_tail.py

By: a guest on Jan 27th, 2014  |  syntax: Python  |  size: 0.94 KB  |  views: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def getStation(address):
  2.   #Ć’unction to take in a RIC code and return some meaningful string
  3.   return 'Unknown'
  4.  
  5. f = subprocess.Popen(['tail','-F','multi.log'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
  6. prev_address = ''
  7. while True:
  8.     line = f.stdout.readline()
  9.     if not line.startswith('POCSAG512:'):
  10.         #Skip to the next line
  11.         continue
  12.  
  13.     if 'CORRUPT' in line:
  14.         continue
  15.  
  16.     if 'Address' in line:
  17.         prev_address = line.split(' ')[2]
  18.         continue
  19.  
  20.     if 'Alpha' in line:
  21.         d = datetime.datetime.now()
  22.         nowstr = "%s/%s/%s %s:%s:%s" % (d.year,d.month,d.day,d.hour,d.minute,d.second)
  23.         addr = getStation(prev_address)
  24.         message = " ".join(line.split(' ')[2:])
  25.         message = message.strip()
  26.         if message.endswith('<NUL>'):
  27.             message = message[:-5]
  28.         print "%s\t%s\t%s" % (addr,nowstr,message)
  29.         continue
  30.  
  31.     prev_address = ''
clone this paste RAW Paste Data