Created
August 15, 2012 00:55
-
-
Save N3MIS15/3354372 to your computer and use it in GitHub Desktop.
simple URL opener script for maraschino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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