Beispiel #1
0
	def ParseSource(self):
		Debug('Entering JSONSource.ParseSource()')
		jfile = open(self.LocalSource, 'r')
		try:
			Debug('Attempting to load jfile...')
			json_dict = json.load(jfile)
		except Exception as ex:
			Error("Unable to load jfile.\n" + str(jfile))
			exit()
		jfile.close()
		
		self.Arrivals.clear()
		self.Departures.clear()
		
		for arrival in json_dict['arrivals']:
			self.Arrivals.append(
				Data.BusArrival( arrival['company'],
								 arrival['city'],
								 arrival['time'],
								 arrival['status']
								 )
			)
		
		for departure in json_dict['departures']:
			self.Departures.append(
				Data.BusDeparture( departure['company'],
								   departure['city'],
								   departure['time'],
								   departure['status'],
								   departure['gate'],
								   departure['busnum']
								   )
			)
Beispiel #2
0
	def ParseSource(self):
		data = ET.parse(self.LocalSource)
		root = data.getroot()
		
		self.Arrivals.clear()
		self.Departures.clear()
		dep = root.get('departures')
		arv = root.get('arrivals')
		
		for type in root:
			for bus in type:
				busdata = None
				list = None
				if type.tag == 'departures':
					busdata = Data.BusDeparture()
					list = self.Departures
				else:
					busdata = Data.BusArrival()
					list = self.Arrivals
				for cell in bus:
					if cell.tag == "company":
						busdata.Company = cell.text.title()
					elif cell.tag == "city":
						busdata.City = cell.text.title()
					elif cell.tag == "time":
						busdata.Time = cell.text.strip()
					elif cell.tag == "status":
						busdata.Status = cell.text.title()
					elif cell.tag == "gate":
						busdata.Gate = cell.text
					elif cell.tag == "busnum":
						busdata.Number = cell.text
					else:
						Warn("Found unexpected element in XML: " + cell.tag)
				list.append(busdata)
Beispiel #3
0
	def SourceUpdate(self):
		del self.Arrivals[:]
		del self.Departures[:]
		
		derp = "a b c d e f g h i j k l m n o p q r s t u v w x y z".upper().split(" ")
		
		arrivals = Data.BusList()
		departures = Data.BusList()
		
		for i in range(10):
			arrivals.append_bus(Data.BusArrival("Company " + derp[i], "City " + derp[:i], str(i) + ":00pm", random.randint(1, 4)))
		
		for i in range(10):
			departures.append_bus(Data.BusDeparture("Company " + derp[i], "City " + derp[:i], str(i) + ":00pm", random.randint(1, 4), random.randint(1, 12), random.randint(1, 9999)))
Beispiel #4
0
	def __init__(self, width = 1280, height = 720):
		config = Settings.Config()
		if config.DisplayFullscreen is False:
			os.environ['SDL_VIDEO_CENTERED'] = '1'
			self.screen = pygame.display.set_mode((width, height))
		else:
			self.screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF)
			
		pygame.init()
		
		self.Background = TileImage("img/bg-dark.gif", self.screen)	
		self.screen.blit(self.Background, (0,0))
		pygame.mouse.set_visible(False)
		pygame.display.flip()
		
		checks = UpdateChecks()
		checks.AddTimer('page_delay', config.PageInterval)
		checks.AddTimer('source_update', config.UpdateInterval)
		checks.Update('page_delay')
		
		checks.AddState('dirty_source', True)
		checks.AddState('dirty_screen', True)
		checks.AddState('dirty_page', False)
		checks.AddState('error', False)
		
		self.DrawArrivals = True
		if config.DisplayScreen == 'departures':
			self.DrawArrivals = False
			
		self.CurrentPage = 1
		self.RowsPerPage = 10	# 12 rows minus the header
		self.FirstRow = 0		# First row to draw
		
		# FIXME: proper error handling and checking needed here.
		if config.SourceURI[-4:] == '.xml':
			self.Source = ds.JSONSource()
			Debug('XML source found.')
		else:
			self.Source = ds.XMLSource()
			Debug('JSON source found.')
			
		self.CachedList = Data.BusList()
		self.List = Data.BusList()
		self.ArrivalHeader = HeaderRow(Data.BusArrival("Company", "City", "Time", "Status"))
		self.DepartureHeader = HeaderRow(Data.BusDeparture("Company", "City", "Time", "Status", "Gate", "Bus #"))
		
		self.ErrorScreen = None