from urllib import request
import xml.etree.ElementTree as ET
from datetime import datetime, time
valuesChecked = pyqtSignal(dict)
def __init__(self, xmlUrl, timerIntervalMs=10):
self.xmlUrl = xmlUrl
self.timer.setInterval(timerIntervalMs)
self.timer.timeout.connect(self.timerFires)
self.timer.start()
self.sample = {}
def getSample(self, sourcePiece):
return self.sample[sourcePiece[0], sourcePiece[1]]
def timerFires(self):
response = request.urlopen(self.xmlUrl)
xmlStr = response.read()
root = ET.fromstring(xmlStr)
for child in root:
asset = child.attrib["Symbol"]
self.sample[asset] = {
"bid": float(child.find("Bid").text),
"ask": float(child.find("Ask").text),
"high": float(child.find("High").text),
"low": float(child.find("Low").text),
"@ last": time(child.find("Last").text),
"direction": int(child.find("Direction").text),
}
self.valuesChecked.emit(self.sample)
from PyQt5.QtCore import QObject, QTimer, pyqtSignal
from urllib import request
import xml.etree.ElementTree as ET
from datetime import datetime, time
class SignalSource(QObject):
valuesChecked = pyqtSignal(dict)
def __init__(self, xmlUrl, timerIntervalMs=10):
QObject.__init__(self)
self.xmlUrl = xmlUrl
self.timer = QTimer()
self.timer.setInterval(timerIntervalMs)
self.timer.timeout.connect(self.timerFires)
self.timer.start()
self.sample = {}
def getSample(self, sourcePiece):
return self.sample[sourcePiece[0], sourcePiece[1]]
def timerFires(self):
response = request.urlopen(self.xmlUrl)
xmlStr = response.read()
root = ET.fromstring(xmlStr)
for child in root:
asset = child.attrib["Symbol"]
self.sample[asset] = {
"bid": float(child.find("Bid").text),
"ask": float(child.find("Ask").text),
"high": float(child.find("High").text),
"low": float(child.find("Low").text),
"@ last": time(child.find("Last").text),
"direction": int(child.find("Direction").text),
}
self.valuesChecked.emit(self.sample)
To copy to clipboard, switch view to plain text mode
Bookmarks