def drawDay(self, yPos, xPos, dayData): date = utils.getDateFormat(dayData['dt']) weekday = utils.getWeekDay(dayData['dt']) time = ' ' + utils.getTimeFormat(dayData['dt']) icon = utils.getIcon(dayData['weather'][0]['icon']) temp = '{} °C'.format(dayData['main']['temp']) humidity = 'Hum: {} %'.format(dayData['main']['humidity']) pressure = '{} hPa'.format(dayData['main']['pressure']) #refactor: cenetring weekday try: self.window.addstr( yPos, xPos, date, curses.A_BOLD | curses.color_pair(cg.PAIR_GREEN)) self.window.addstr(yPos + 1, xPos + 4, weekday, curses.A_BOLD | curses.color_pair(cg.PAIR_CYAN)) self.window.addstr(yPos + 2, xPos, time, curses.A_BOLD | curses.color_pair(cg.PAIR_YELLOW)) icons.drawIcon(xPos, yPos + 3, icon, self.window) self.window.addstr(yPos + icons.iconHeight + 4, xPos, temp, curses.color_pair(cg.PAIR_GREEN)) self.window.addstr(yPos + icons.iconHeight + 5, xPos, humidity, curses.color_pair(cg.PAIR_GREEN)) self.window.addstr(yPos + icons.iconHeight + 6, xPos, pressure, curses.color_pair(cg.PAIR_GREEN)) except curses.error: pass
def draw_country_data(data_window, data, country): country_data = data[0] for entry in data: if entry['country'] == country: country_data = entry data_window.clear() max_width = len('Současný prodej: ' + str(country_data['currSell'])) data_window.addstr(0, 0, 'Země: ' + country) data_window.addstr(1, 0, country_data[ 'name'] + ' (' + country_data['shortName'] + ')') data_window.addstr(2, 0, 'Platnost: ' + country_data['validFrom']) data_window.addstr(3, 0, 'Množství: ' + str(country_data['amount'])) data_window.addstr(4, 0, 'Současný výkup: ' + str(country_data['currBuy'])) data_window.addstr(5, 0, 'Současný střed: ' + str(country_data['currMid'])) data_window.addstr(6, 0, 'Současný prodej: ' + str(country_data['currSell'])) data_window.addstr(7, 0, 'Změna: ' + str(country_data['move'])) data_window.addstr(8, 0, 'Kurz ČNB: ' + str(country_data['cnbMid'])) icon = icons.none if country_data['move'] > 0: icon = icons.up elif country_data['move'] < 0: icon = icons.down icons.drawIcon(max_width + 1, 1, icon, data_window) data_window.refresh()
def drawDay(yPos, xPos, dayData, forecastWindow): date = getDateFormat(dayData['dt']) time = ' ' + getTimeFormat(dayData['dt']) icon = getIcon(dayData['weather'][0]['icon']) temp = str(dayData['main']['temp']) + ' °C' humidity = 'Hum: ' + str(dayData['main']['humidity']) + '%' pressure = str(dayData['main']['pressure']) + 'hPa' try: forecastWindow.addstr( yPos, xPos, date, curses.A_BOLD | curses.color_pair(PAIR_GREEN)) forecastWindow.addstr(yPos + 1, xPos, time, curses.A_BOLD | curses.color_pair(PAIR_YELLOW)) icons.drawIcon(xPos, yPos + 2, icon, forecastWindow) forecastWindow.addstr(yPos + icons.iconHeight + 2, xPos, temp, curses.color_pair(PAIR_GREEN)) forecastWindow.addstr(yPos + icons.iconHeight + 3, xPos, humidity, curses.color_pair(PAIR_GREEN)) forecastWindow.addstr(yPos + icons.iconHeight + 4, xPos, pressure, curses.color_pair(PAIR_GREEN)) except curses.error: pass
def drawCurrentData(currentData, currentWindow): winSize = currentWindow.getmaxyx() headline = 'Current weather' temperature = 'Temperature: {} C '.format(currentData['main']['temp']) pressure = 'Pressure: {} hPa '.format(currentData['main']['pressure']) humidity = 'Humidity: {} % '.format(currentData['main']['humidity']) wind = 'Wind: {} ms '.format(currentData['wind']['speed']) sunriseUnix = currentData['sys']['sunrise'] sunsetUnix = currentData['sys']['sunset'] sunrise = 'Sunrise: ' + getTimeFormat(sunriseUnix) sunset = 'Sunset: ' + getTimeFormat(sunsetUnix) date = getDateFormat(sunsetUnix) curWeather = currentData['weather'][0]['description'] icon = getIcon(currentData['weather'][0]['icon']) maxLen = max([len(temperature),len(pressure),len(humidity),len(wind)]) temperature = padEntry(temperature, maxLen, ':', ' ') pressure = padEntry(pressure, maxLen, ':', ' ') humidity = padEntry(humidity, maxLen, ':', ' ') wind = padEntry(wind, maxLen, ':', ' ') rightOffset = winSize[1] - maxLen - 1 leftOffset = 1 currentWindow.clear() drawWindowBorder(currentWindow) try: currentWindow.addstr(1, (winSize[1] - len(headline)) // 2, headline, curses.A_BOLD | curses.color_pair(PAIR_BLUE)) except curses.error: pass try: currentWindow.addstr(2, rightOffset, temperature, curses.color_pair(PAIR_YELLOW)) currentWindow.addstr(3, rightOffset, pressure, curses.color_pair(PAIR_YELLOW)) currentWindow.addstr(4, rightOffset, humidity, curses.color_pair(PAIR_YELLOW)) currentWindow.addstr(5, rightOffset, wind, curses.color_pair(PAIR_YELLOW)) except curses.error: pass try: currentWindow.addstr(2, leftOffset + icons.iconWidth + 1, date, curses.color_pair(PAIR_CYAN)) currentWindow.addstr(3, leftOffset + icons.iconWidth + 1, curWeather, curses.color_pair(PAIR_CYAN)) currentWindow.addstr(4, leftOffset + icons.iconWidth + 1, sunrise, curses.color_pair(PAIR_CYAN)) currentWindow.addstr(5, leftOffset + icons.iconWidth + 1, sunset, curses.color_pair(PAIR_CYAN)) except curses.error: pass try: #currentWindow.addstr(1, rightOffset - icons.iconWidth - 1, 'ikona') #icons.drawIcon(rightOffset - icons.iconWidth - 1,2, icon, currentWindow) icons.drawIcon(leftOffset, 1, icon, currentWindow) except curses.error: pass currentWindow.refresh()
def draw_current_weather(self, current_weather_data): temperature = 'Temperature: {} C '.format( current_weather_data['main']['temp']) pressure = 'Pressure: {} hPa '.format( current_weather_data['main']['pressure']) humidity = 'Humidity: {} % '.format( current_weather_data['main']['humidity']) wind = 'Wind: {} ms '.format(current_weather_data['wind']['speed']) sunriseUnix = current_weather_data['sys']['sunrise'] sunsetUnix = current_weather_data['sys']['sunset'] sunrise = 'Sunrise: ' + utils.getTimeFormat(sunriseUnix) sunset = 'Sunset: ' + utils.getTimeFormat(sunsetUnix) date = utils.getDateFormat(sunsetUnix) curWeather = current_weather_data['weather'][0]['description'] icon = utils.getIcon(current_weather_data['weather'][0]['icon']) maxLen = max([len(temperature), len( pressure), len(humidity), len(wind)]) temperature = utils.padEntry(temperature, maxLen, ':', ' ') pressure = utils.padEntry(pressure, maxLen, ':', ' ') humidity = utils.padEntry(humidity, maxLen, ':', ' ') wind = utils.padEntry(wind, maxLen, ':', ' ') rightOffset = self.columns - maxLen - 1 leftOffset = 1 self.window.clear() self.drawWindowBorder() try: self.window.addstr(2, rightOffset, temperature, curses.color_pair(cg.PAIR_YELLOW)) self.window.addstr(3, rightOffset, pressure, curses.color_pair(cg.PAIR_YELLOW)) self.window.addstr(4, rightOffset, humidity, curses.color_pair(cg.PAIR_YELLOW)) self.window.addstr(5, rightOffset, wind, curses.color_pair(cg.PAIR_YELLOW)) except curses.error: pass try: self.window.addstr(2, leftOffset + icons.iconWidth + 1, date, curses.color_pair(cg.PAIR_CYAN)) self.window.addstr(3, leftOffset + icons.iconWidth + 1, curWeather, curses.color_pair(cg.PAIR_CYAN)) self.window.addstr(4, leftOffset + icons.iconWidth + 1, sunrise, curses.color_pair(cg.PAIR_CYAN)) self.window.addstr(5, leftOffset + icons.iconWidth + 1, sunset, curses.color_pair(cg.PAIR_CYAN)) except curses.error: pass try: icons.drawIcon(leftOffset, 1, icon, self.window) except curses.error: pass self.refresh()
return stdscr def endCurses(): # terminate curses application curses.nocbreak() curses.echo() stdscr.keypad(0) curses.endwin() if __name__ == '__main__': stdscr = initCurses() x = 0 y = 0 for icon in icons.brokenClouds, icons.clear, icons.default, icons.fewClouds, icons.mist, icons.rain,icons.scatteredClouds, icons.snow, icons.storm: icons.drawIcon(x,y, icon, stdscr) x = x + icons.iconWidth + 1 if x > 50: x = 0 y = y + icons.iconHeight + 1 while True: c = stdscr.getch() if c == ord('q'): break endCurses()