Qt Code:
  1. from PyQt5.QtCore import QObject, QTimer, pyqtSignal
  2. from urllib import request
  3. import xml.etree.ElementTree as ET
  4. from datetime import datetime, time
  5.  
  6. class SignalSource(QObject):
  7. valuesChecked = pyqtSignal(dict)
  8.  
  9. def __init__(self, xmlUrl, timerIntervalMs=10):
  10. QObject.__init__(self)
  11. self.xmlUrl = xmlUrl
  12. self.timer = QTimer()
  13. self.timer.setInterval(timerIntervalMs)
  14. self.timer.timeout.connect(self.timerFires)
  15. self.timer.start()
  16.  
  17. self.sample = {}
  18.  
  19. def getSample(self, sourcePiece):
  20. return self.sample[sourcePiece[0], sourcePiece[1]]
  21.  
  22. def timerFires(self):
  23. response = request.urlopen(self.xmlUrl)
  24. xmlStr = response.read()
  25. root = ET.fromstring(xmlStr)
  26.  
  27. for child in root:
  28. asset = child.attrib["Symbol"]
  29. self.sample[asset] = {
  30. "bid": float(child.find("Bid").text),
  31. "ask": float(child.find("Ask").text),
  32. "high": float(child.find("High").text),
  33. "low": float(child.find("Low").text),
  34. "@ last": time(child.find("Last").text),
  35. "direction": int(child.find("Direction").text),
  36. }
  37. self.valuesChecked.emit(self.sample)
To copy to clipboard, switch view to plain text mode 

I simply call
signalSource = SignalSource("myXmlUrl")
inside the main debug module at module scope.

No timer firing action, so I never get to take a sample :'(