Hi Matzunaga,
The script you sent works for a value that is defined as a string or equals a string. The problem i am having is that the values that are coming from the function need a certain format to be treated as a string instead of an integer/float. I am using the script you made that worked in python 2.0. I reworked it a bit to work with python 3. The only problem left is the values for the days and temperature to be converted to a string. I have tried every combination i can think of to convert the value to a string.
It always returns the error of "NameError: name 'inputFromXML' is not defined. I tried the encode function you suggested but it give another error. Is there a way to convert the values from the xml to a string?
Here is the script: The last socket send line at the bottom is where i am so far.
#Weather update from URL with Pyton
# Import necessary libraries
from xml.dom import minidom
import socket
import sys
import datetime
import time
from datetime import datetime
#'import urllib2
import urllib.request
#Var declaration
dayCounter = 0
highTempCounter = 0
weekReport = ()
dayReport = ()
dayCommandPreffix = '0 MAIN_SCENE*TREE*$day0'
#highTempCommandPreffix = '0 MAIN_SCENE*TREE*$high_temp0'
highTempCommandPreffix = '0 MAIN_SCENE*TREE*$'
Temp1 = "high_temp01"
Temp2 = "high_temp02"
vizCommandPreffix2 = '*GEOM*TEXT SET '
vizCommandSuffix = '\0'
def main():
readFeed()
printDays()
printHighTemps()
def readFeed():
global weekReport
global dayReport
readXMLfromURL = urllib.request.urlopen("http://xml.customweather.com/xml?product=current_extended&latitude=27.964157&longitude=-82.452606&client=vizrt_test&client_password=t3mp")
wxMiguelXML = minidom.parse(readXMLfromURL)
weekReport = wxMiguelXML.getElementsByTagName("report")[0]
dayReport = weekReport.getElementsByTagName("forecast")
def printDays():
for i in dayReport:
myDays = i.attributes["weekday"]
dayNames = myDays.value
daytalkToViz(dayNames)
#print (dayCommandPreffix)
#print (dayNames)
#print (f'MAIN_SCENE*TREE*$day01*FUNCTION*ControlText*input SET {dayNames}')
def printHighTemps():
for j in dayReport:
myHighs = j.attributes["high_temp"]
dayHighTemps = myHighs.value
highTemptalkToViz(dayHighTemps)
#print (dayHighTemps)
#print (f'MAIN_SCENE*TREE*$high_temp01*FUNCTION*ControlText*input SET {dayHighTemps}')
def daytalkToViz(inputFromXML):
global dayCounter
dayCounter = dayCounter + 1
#x = print (dayCommandPreffix + str(dayCounter) + vizCommandPreffix2 + inputFromXML + vizCommandSuffix)
x = dayCommandPreffix + str(dayCounter) + vizCommandPreffix2 + inputFromXML + vizCommandSuffix
print(x)
#---------------------------------------------------------------------------------------------------------------------
HOST = '10.55.14.104' # The remote host
PORT = 6100 # The same port as used by the server
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect((HOST, PORT))
#--------------------
def highTemptalkToViz(inputFromXML):
global highTempCounter
highTempCounter = highTempCounter + 1
#x = print (highTempCommandPreffix + str(highTempCounter) + vizCommandPreffix2 + inputFromXML + vizCommandSuffix)
y = highTempCommandPreffix + str(highTempCounter) + vizCommandPreffix2 + inputFromXML + vizCommandSuffix
print
#socket.send(highTempCommandPreffix + str(highTempCounter) + vizCommandPreffix2 + inputFromXML + vizCommandSuffix)
##socket.send(b'0 MAIN_SCENE*TREE*$high_temp01*FUNCTION*ControlText*input SET 44' )
##socket.send(b'0 MAIN_SCENE*TREE*$day01*GEOM*TEXT SET Wednesday')
#socket.send(highTempCommandPreffix.encode() + bytes(highTempCounter) + vizCommandPreffix2.encode() + vizCommandSuffix.encode())
#socket.send(highTempCommandPreffix.encode() + Temp1.encode() + vizCommandPreffix2.encode() + Temp1.encode() + vizCommandSuffix.encode())
socket.send(highTempCommandPreffix.encode() + Temp2.encode() + vizCommandPreffix2.encode() + Temp2.encode() + str(highTemptalkToViz(inputFromXML)) + vizCommandSuffix.encode())
socket.close()
main()