import urllib.request
import sys
if len(sys.argv) > 1:
  variables = str(sys.argv[1]) + 'variables'
from variables import *

thisfile = 'Run.php'

# make url
url = server + thisfile + '?auth=' + auth + '&pid=' + pid + '&mode=' + mode
url = url.replace(' ','%20')
#print(url)

# call url
#urllib.request.urlopen(url)

# call url
urldata = urllib.request.urlopen(url).read().decode("utf-8")

# write url contents to stdout
#print(urldata)

# get file name
nameurl = server + 'GetName.php?auth=' + auth + '&pid=' + pid + '&mode=' + mode # new
nameurl = nameurl.replace(' ','%20') # new
filename = urllib.request.urlopen(nameurl).read().decode("utf-8") # new

# write url contents to file
handle = open(filename,'w')
handle.write(urldata)
handle.close()

# write filename to screen
print("Calibration completed")
print("Output file is called " + filename + " contents follow:")
print(" ")
f = open(filename, 'r')
file_contents = f.read()
print (file_contents)
f.close()

