# /var/www/py/testInternet.py *************************************************
# Created by: HARB rboek2@gmail.com august 2018 GPL copyrights                
# Prepaired and optimized for use with Python 3
# www.flora.py?


# IMPORT LIBRARIES install like: pip install --upgrade psycopg2 --user ********
import platform                        #needed to check if we are using Python3
import datetime                #Needed to create a timestamp for the datarecord
import time           #Needed to be able to perform the request every 5 minutes
import requests                           #Simplest internet reader for Python3

#import urllib         #Needed to load the contents of a webpage into a variable
#import urllib2                   #URLLIB2 seems to function better for requests https://docs.python.org/2/howto/urllib2.html
#import urllib3
import requests

python_version=platform.python_version()                #Actual version request
print ("De gebruikte versie van Python is:", python_version)      #Show to user

# while True:                               #Meaning this loop will run forever
if True:
   # This is a list of all the data that will be written into the database when
   # stations are not activated.    All stations must be asked in one sequence.
   now = datetime.datetime.now()                          #Read the system time
   stampz    = now.strftime("%Y-%m-%d %H:%M:%S")   #Format to a database format

   #*** COUVEUSE **************************************************************
   link       = "http://192.168.2.18"       #Calculate the entire link KWEEKKAS
   #   link       = "http://robotigs.nl"    #Calculate the entire link ROBOTIGS
   myfile = "2003-08-01 13:48:18 28.40 62.40 524 0 2 2"
   try:           #Make a provision for if the station does not answer properly
      r = requests.get(link)            
      myfile = (r.text)
   except:                    #If the station does not answer properly use this
      pass            #Just do nothing if this station does not answer properly
   #print (myfile)
   print (" ")
   print (r.headers)
   print (" ")
   datalist = myfile.split(" ")    #Splice the answer into an array
   propklokz = datalist[0] + " " + datalist[1]        #Assign the data
   proptmpz  = datalist[2]                            #Assign the data
   prophumz  = datalist[3]                            #Assign the data
   proprel1z = datalist[4]                            #Assign the data
   proprel2z = datalist[5]                            #Assign the data
   proprel3z = datalist[6]                            #Assign the data
   proprel4z = datalist[7]                            #Assign the data
   print ("    ", proptmpz, "    ", prophumz, "    ", propklokz, 
          "    ", proprel1z, "    ", proprel2z, "    ", proprel3z, 
          "     " , proprel4z)
   print ("Wie verstuurt er nou tveel bytes of verwacht er te winig. Of omgekeerd zelfs, kan dat wel dan, is het symmmetrisch>")

