Skip to content

Instantly share code, notes, and snippets.

@N3MIS15
Created August 15, 2012 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save N3MIS15/3354372 to your computer and use it in GitHub Desktop.
Save N3MIS15/3354372 to your computer and use it in GitHub Desktop.
simple URL opener script for maraschino
import datetime, getopt, sys, urllib, urllib2
def main(argv):
try:
opts, args = getopt.getopt(argv, "ipsw:", ["ip=", "port=", "script_id=", "webroot=", "url="])
except getopt.GetoptError:
sys.exit(2)
ip = None
port = None
script_id = None
webroot = ''
maraschino_url = ''
url = None
for opt, arg in opts:
if opt in ("-i", "--ip"):
ip = arg
elif opt in ("-p", "--port"):
port = arg
elif opt in ("-s", "--script_id"):
script_id = arg
elif opt in ("-w", "--webroot"):
webroot = arg
elif opt in ("-u", "--url"):
url = arg
if ip and port and script_id:
maraschino_url = 'http://%s:%s%s/xhr/script_launcher/script_status/%s' % (ip, port, webroot, script_id)
def finished():
now = datetime.datetime.now()
update_status("Last Ran: %s" % now.strftime("%m-%d-%Y %H:%M"))
def update_status(status):
if maraschino_url:
data = [('status', status)]
data=urllib.urlencode(data)
req=urllib2.Request(maraschino_url, data)
req.add_header("Content-type", "application/x-www-form-urlencoded")
urllib2.urlopen(req).read()
if url:
urllib.urlopen(url).read()
finished()
else:
update_status('No URL provided')
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment