0

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()
Alireza
  • 100,211
  • 27
  • 269
  • 172
shaggs
  • 600
  • 7
  • 27
  • Possible duplicate of [What is a "callable" in Python?](https://stackoverflow.com/questions/111234/what-is-a-callable-in-python) – Psytho Jul 11 '17 at 13:32

1 Answers1

0

Add this to the bottom of the script.

if __name__ == "__main__":
    function_you_wish_to_call_here()

Anything under the if statement will run when you call the script directly.

Marcel Wilson
  • 3,842
  • 1
  • 26
  • 55