Tuesday, 29 January 2013

Serverlove API - Python


To complete my adventure into the Serverlove GUI I ditched the batchfile and made a wee python script and converted that to exe, much nicer than bat files.  Not that I am much of a programmer - this is still well within the bounds of Pointless Posts.  I mean, to turn on and off a server I could just use the website control-panel, right?  The time I have wasted doing this would probably fuel several years worth of logging onto the portal and clicking the icon.  Utterly pointless, is all this.  Please note some details like, eh, passwords, have been changed.


import requests

from requests.auth import HTTPBasicAuth

user = 'a279f838-1234-1234-1234-277b1f414501'

password = '9nzfwh2atZcidontthinksoPfYqwgUGuGb8j6'

print "Please choose from the following options:\n\n\n(1) Start VPN Server\n\n(2) Stop VPN Server\n\n"

while True:

   try:

      choice = int(raw_input("Type here:"))

   except ValueError:

      print "Try Again"

   finally:

     if choice == 1:

      r = requests.post('https://api.z1-man.serverlove.com/servers/775f7bcb-7f07-1234-1234-af1fa8dc1fd9/start', auth=(user, password))

      print r.text

     elif choice == 2:

      r = requests.post('https://api.z1-man.serverlove.com/servers/775f7bcb-7f07-1234-1234-af1fa8dc1fd9/stop', auth=(user, password))

      print "Killing the VPN Server...\n"

     else:

       print "Hey that isnt an option yet!\n"



print r.url

print r.text

No comments:

Post a Comment

Found this pointless and feel you must comment? Really, there is no need, we are fully aware of the pointlessness of this article. But if you must...

Google+ Followers