|
1 | 1 | #!/usr/bin/python |
| 2 | +"""Weather forecast example. |
2 | 3 |
|
| 4 | +Adapted script from Adafruit |
| 5 | +Weather forecast for Raspberry Pi w/Adafruit Mini Thermal Printer. |
| 6 | +Retrieves data from DarkSky.net's API, prints current conditions and |
| 7 | +forecasts for next two days. |
| 8 | +Weather example using nice bitmaps. |
| 9 | +Written by Adafruit Industries. MIT license. |
| 10 | +Adapted and enhanced for escpos library by MrWunderbar666 |
3 | 11 |
|
4 | | -# Adapted script from Adafruit |
5 | | -# Weather forecast for Raspberry Pi w/Adafruit Mini Thermal Printer. |
6 | | -# Retrieves data from DarkSky.net's API, prints current conditions and |
7 | | -# forecasts for next two days. |
8 | | -# Weather example using nice bitmaps. |
9 | | -# Written by Adafruit Industries. MIT license. |
10 | | -# Adapted and enhanced for escpos library by MrWunderbar666 |
| 12 | +Icons taken from https://adamwhitcroft.com/climacons/ |
| 13 | +Check out his github: https://github.com/AdamWhitcroft/climacons |
| 14 | +""" |
11 | 15 |
|
12 | | -# Icons taken from https://adamwhitcroft.com/climacons/ |
13 | | -# Check out his github: https://github.com/AdamWhitcroft/climacons |
14 | 16 |
|
15 | | - |
16 | | -from datetime import datetime |
17 | 17 | import calendar |
18 | | -import urllib |
19 | 18 | import json |
20 | | -import time |
21 | 19 | import os |
| 20 | +import time |
| 21 | +import urllib |
| 22 | +from datetime import datetime |
22 | 23 |
|
23 | 24 | from escpos.printer import Usb |
24 | 25 |
|
25 | | -""" Setting up the main pathing """ |
| 26 | +"""Set up the main pathing.""" |
26 | 27 | this_dir, this_filename = os.path.split(__file__) |
27 | 28 | GRAPHICS_PATH = os.path.join(this_dir, "graphics/climacons/") |
28 | 29 |
|
|
38 | 39 |
|
39 | 40 |
|
40 | 41 | def forecast_icon(idx): |
| 42 | + """Get right icon for forecast.""" |
41 | 43 | icon = data["daily"]["data"][idx]["icon"] |
42 | 44 | image = GRAPHICS_PATH + icon + ".png" |
43 | 45 | return image |
44 | 46 |
|
45 | 47 |
|
46 | | -# Dumps one forecast line to the printer |
47 | 48 | def forecast(idx): |
| 49 | + """Dump one forecast line to the printer.""" |
48 | 50 | date = datetime.fromtimestamp(int(data["daily"]["data"][idx]["time"])) |
49 | 51 | day = calendar.day_name[date.weekday()] |
50 | 52 | lo = data["daily"]["data"][idx]["temperatureMin"] |
@@ -73,6 +75,7 @@ def forecast(idx): |
73 | 75 |
|
74 | 76 |
|
75 | 77 | def icon(): |
| 78 | + """Get icon.""" |
76 | 79 | icon = data["currently"]["icon"] |
77 | 80 | image = GRAPHICS_PATH + icon + ".png" |
78 | 81 | return image |
|
0 commit comments