def calendar_events(): events = g_cal.get_events() if events: return json.jsonify(status="events", events=events) if not events: auth_results = g_cal.authenticate() if auth_results: return json.jsonify(status="auth", code=auth_results[0], url=auth_results[1]) else: events = g_cal.get_events() return json.jsonify(status="events", events=events)
def main(): logging.basicConfig(filename='ei_cal.log') #print('Getting Work Schedule') creds = g_cal.get_creds() ''' if len(g_cal.get_events(creds)) == 0: print('No Work!') else: print(g_cal.get_events(creds)) ''' logging.info('Getting work events') try: all_events = g_cal.get_events(creds) except socket.timeout as e: all_events = [] logging.exception(e) logging.info('Getting weather') API_KEY = weather.get_API_KEY('darksky.json') latitude, longitude = weather.get_lat_long('darksky.json') forecast = weather.get_forecast(API_KEY, latitude, longitude) weather_now = weather.get_weather_now(forecast) weather_tmrw = weather.get_weather_tmrw(forecast) epd = epd7in5.EPD() epd.init() epd.Clear() screen_w = epd.width screen_h = epd.height image = Image.new('1', (screen_w, screen_h), 255) logging.info('Drawing calendar') draw = ImageDraw.Draw(image) #center divider line day_view_divider = screen_w*5/9 draw.line([(day_view_divider,0),(day_view_divider,screen_h)], fill=0, width=2) #draw calendar divider line cal_divider = screen_h/2 draw.line([(0,cal_divider),(day_view_divider,cal_divider)], fill=0, width=2) #draw weather divider line title_divider = (screen_h - cal_divider)/5 weather_divider = day_view_divider/2 draw.line([(weather_divider, title_divider), (weather_divider, cal_divider)], fill=0, width=2) #draw weather icons icon_divider = title_divider + (cal_divider-title_divider)*3/4 draw_weather_icons(draw, weather_now, 0, title_divider, weather_divider, icon_divider) draw_weather_icons(draw, weather_tmrw, weather_divider, title_divider, day_view_divider, icon_divider) #draw.line([(0, icon_divider),(day_view_divider, icon_divider)], fill=0, width=2) #write weather info today_weather_info(draw, weather_now, 0, icon_divider, weather_divider, cal_divider) tmrw_weather_info(draw, weather_tmrw, weather_divider, icon_divider, day_view_divider, cal_divider) #get today as a datetime object today = datetime.date.today() #draw the date title font24 = ImageFont.truetype('./fonts/mononoki-Regular.ttf', 24) title(draw, today, font24, day_view_divider, title_divider) #draw the calendar in the lower left draw_cal.draw_cal(draw, screen_w, screen_h, day_view_divider, cal_divider, today) #draw the two day view on the right draw_cal.draw_two_day_view(draw, screen_w, screen_h, day_view_divider, 7, 17, today, all_events) logging.info('Send to e-ink screen') epd.display(epd.getbuffer(image)) logging.info('Go to sleep') epd.sleep()