need some help making the below a callable object for another script e.g scrape.run()
I'm not sure where to start any pointers?
scrape.py
from clint.textui import puts, colored
import subprocess, sys
from datetime import datetime
from time import sleep as sleep
today = datetime.now().strftime("%H:%M:%S")
multimon_ng = subprocess.Popen("rtl_fm -A lut -s 22050 -f 148.81250M | multimon-ng -t raw -a FLEX -f alpha /dev/stdin",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
while True:
try:
nextline = multimon_ng.stdout.readline()
if not nextline:
pass
else:
try:
flex, mdate, mtime, bitrate, other, capcode, o2, msg = nextline.split(" ", 7)
except ValueError:
print "invalid line", nextline
else:
puts(colored.yellow(capcode), newline=False)
puts(" [", newline=False)
puts(colored.green(mdate + " " + str(datetime.now().strftime('%H:%M'))), newline=False)
puts(" ]", newline=False)
puts(msg)
except KeyboardInterrupt:
print "exit"
multimon_ng.poll()