2019-02-03 16:26:30 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
E-Paper Software (main script) for the 3-colour and 2-Colour E-Paper display
|
|
|
|
A full and detailed breakdown for this code can be found in the wiki.
|
|
|
|
If you have any questions, feel free to open an issue at Github.
|
|
|
|
|
|
|
|
Copyright by aceisace
|
|
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
from time import sleep
|
2019-05-06 11:05:10 +02:00
|
|
|
from Assets import path
|
2019-03-13 20:33:20 +01:00
|
|
|
from LoopTimer import LoopTimer
|
2019-02-28 15:17:43 +01:00
|
|
|
import locale
|
2019-02-26 22:09:19 +01:00
|
|
|
from DebugConsole import DebugConsole
|
2019-05-18 09:35:49 +02:00
|
|
|
from settings import datetime_encoding, language, render_to_display, render_to_file, display_colours, location, api_key, owm_paid_subscription, choosen_design, ical_urls, highlighted_ical_urls, rss_feeds, update_interval, calibrate_hours, crypto_coins
|
2019-02-28 15:17:43 +01:00
|
|
|
from MonthOvPanel import MonthOvPanel
|
2019-03-08 17:46:10 +01:00
|
|
|
from DayListPanel import DayListPanel
|
2019-03-17 12:12:58 +01:00
|
|
|
from DayViewPanel import DayViewPanel
|
2019-05-06 11:05:10 +02:00
|
|
|
from MonthViewPanel import MonthViewPanel
|
2019-03-24 21:30:44 +01:00
|
|
|
from AgendaListPanel import AgendaListPanel
|
2019-02-23 19:49:20 +01:00
|
|
|
import OwmForecasts
|
2019-02-26 22:09:19 +01:00
|
|
|
import IcalEvents
|
2019-03-04 20:10:36 +01:00
|
|
|
import RssParserPosts
|
2019-05-19 22:25:59 +02:00
|
|
|
import GeckoCrypto
|
2019-02-03 16:26:30 +01:00
|
|
|
|
2019-05-06 11:05:10 +02:00
|
|
|
all_locales = locale.locale_alias
|
2019-05-10 08:11:13 +02:00
|
|
|
if language.lower() not in all_locales.keys():
|
2019-05-06 11:05:10 +02:00
|
|
|
raise Exception("The locale for \"%s\" is currently not supported! If you need support, please open an issue on github." % language)
|
2019-05-10 08:11:13 +02:00
|
|
|
locale.setlocale(locale.LC_ALL, "%s.%s" % (all_locales[language.lower()].split('.')[0], datetime_encoding))
|
2019-05-06 11:05:10 +02:00
|
|
|
|
2019-02-28 15:17:43 +01:00
|
|
|
debug = DebugConsole()
|
2019-02-25 21:57:22 +01:00
|
|
|
output_adapters = []
|
2019-02-20 20:56:10 +01:00
|
|
|
|
2019-02-25 21:57:22 +01:00
|
|
|
if render_to_file:
|
2019-02-20 20:56:10 +01:00
|
|
|
import ImageFileAdapter
|
2019-04-13 19:17:14 +02:00
|
|
|
epd = ImageFileAdapter.ImageFileAdapter(path)
|
2019-02-25 21:57:22 +01:00
|
|
|
output_adapters.append(epd)
|
|
|
|
|
|
|
|
if render_to_display:
|
|
|
|
if display_colours == "bwr":
|
|
|
|
import Epd7in5bAdapter
|
|
|
|
epd = Epd7in5bAdapter.Epd7in5bAdapter()
|
|
|
|
output_adapters.append(epd)
|
|
|
|
elif display_colours == "bw":
|
|
|
|
import Epd7in5Adapter
|
|
|
|
epd = Epd7in5Adapter.Epd7in5Adapter()
|
|
|
|
output_adapters.append(epd)
|
2019-02-03 16:26:30 +01:00
|
|
|
|
2019-03-08 17:46:10 +01:00
|
|
|
available_panels = {
|
|
|
|
"day-list" : DayListPanel,
|
2019-03-17 12:12:58 +01:00
|
|
|
"month-overview" : MonthOvPanel,
|
2019-03-24 21:30:44 +01:00
|
|
|
"day-view" : DayViewPanel,
|
2019-05-06 11:05:10 +02:00
|
|
|
"agenda-list" : AgendaListPanel,
|
|
|
|
"month-view" : MonthViewPanel
|
2019-03-08 17:46:10 +01:00
|
|
|
}
|
|
|
|
|
2019-03-13 20:33:20 +01:00
|
|
|
loop_timer = LoopTimer(update_interval, run_on_hour=True)
|
|
|
|
|
2019-02-03 16:26:30 +01:00
|
|
|
"""Main loop starts from here"""
|
2019-03-21 22:02:08 +01:00
|
|
|
def main():
|
|
|
|
owm = OwmForecasts.OwmForecasts(location, api_key, paid_api=owm_paid_subscription)
|
2019-04-18 08:30:08 +02:00
|
|
|
events_cal = IcalEvents.IcalEvents(ical_urls, highlighted_ical_urls)
|
|
|
|
rss = RssParserPosts.RssParserPosts(rss_feeds)
|
2019-05-19 22:25:59 +02:00
|
|
|
crypto = GeckoCrypto.GeckoCrypto(crypto_coins)
|
2019-03-21 22:02:08 +01:00
|
|
|
|
2019-02-03 16:26:30 +01:00
|
|
|
while True:
|
2019-03-13 20:33:20 +01:00
|
|
|
loop_timer.begin_loop()
|
|
|
|
start_time = loop_timer.get_current()[0]
|
2019-02-03 16:26:30 +01:00
|
|
|
|
2019-03-13 20:33:20 +01:00
|
|
|
if start_time.hour in calibrate_hours and loop_timer.is_new_hour_loop():
|
|
|
|
debug.print_line("Calibrating outputs")
|
|
|
|
for output in output_adapters:
|
|
|
|
output.calibrate()
|
2019-02-03 16:26:30 +01:00
|
|
|
|
2019-05-18 09:28:29 +02:00
|
|
|
if choosen_design in available_panels.keys():
|
2019-03-13 20:33:20 +01:00
|
|
|
design = available_panels[choosen_design]((epd.width, epd.height))
|
|
|
|
else:
|
|
|
|
raise ImportError("choosen_design must be valid (" + choosen_design + ")")
|
2019-02-03 16:26:30 +01:00
|
|
|
|
2019-03-13 20:33:20 +01:00
|
|
|
debug.print_line("Fetching weather information from open weather map")
|
2019-04-18 08:30:08 +02:00
|
|
|
owm.reload()
|
2019-03-13 20:33:20 +01:00
|
|
|
design.add_weather(owm)
|
2019-02-03 16:26:30 +01:00
|
|
|
|
2019-03-13 20:33:20 +01:00
|
|
|
debug.print_line('Fetching events from your calendar')
|
2019-04-18 08:30:08 +02:00
|
|
|
events_cal.reload()
|
2019-03-13 20:33:20 +01:00
|
|
|
design.add_calendar(events_cal)
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-03-13 20:33:20 +01:00
|
|
|
debug.print_line('Fetching posts from your rss-feeds')
|
2019-04-18 08:30:08 +02:00
|
|
|
rss.reload()
|
2019-03-13 20:33:20 +01:00
|
|
|
design.add_rssfeed(rss)
|
2019-03-04 20:10:36 +01:00
|
|
|
|
2019-05-19 22:25:59 +02:00
|
|
|
debug.print_line('Fetching crypto prices from coin gecko')
|
|
|
|
crypto.reload()
|
|
|
|
design.add_crypto(crypto)
|
|
|
|
|
2019-03-13 21:07:36 +01:00
|
|
|
debug.print_line("\nStarting to render")
|
2019-03-13 20:33:20 +01:00
|
|
|
for i, output in enumerate(output_adapters):
|
2019-04-11 08:06:54 +02:00
|
|
|
try:
|
|
|
|
output.render(design)
|
|
|
|
debug.print_line(str(i + 1) + " of " + str(len(output_adapters)) + " rendered")
|
|
|
|
except BaseException as ex:
|
|
|
|
debug.print_err(ex, "Failed to render output " + str(i + 1) + " of " + str(len(output_adapters)))
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-03-13 20:33:20 +01:00
|
|
|
debug.print_line("=> Finished rendering" + "\n")
|
2019-02-03 16:26:30 +01:00
|
|
|
|
2019-03-13 20:33:20 +01:00
|
|
|
loop_timer.end_loop()
|
|
|
|
sleep_time = loop_timer.time_until_next()
|
2019-02-26 22:09:19 +01:00
|
|
|
|
2019-03-13 20:33:20 +01:00
|
|
|
debug.print_line("This loop took " + str(loop_timer.get_last_duration()) + " to execute.")
|
|
|
|
debug.print_line("Sleeping " + str(sleep_time) + " until next loop.")
|
|
|
|
sleep(sleep_time.total_seconds())
|
2019-02-03 16:26:30 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|