diff --git a/AUTHORS b/AUTHORS index d0ab9b0..f5f64a5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -15,6 +15,7 @@ ldos Manuel F Martinez Michael Billington Michael Elsdörfer +mrwunderbar666 Nathan Bookham Patrick Kanzler Qian Linfeng diff --git a/examples/graphics/climacons/clear-day.png b/examples/graphics/climacons/clear-day.png new file mode 100644 index 0000000..b0cadc9 Binary files /dev/null and b/examples/graphics/climacons/clear-day.png differ diff --git a/examples/graphics/climacons/clear-night.png b/examples/graphics/climacons/clear-night.png new file mode 100644 index 0000000..13a6911 Binary files /dev/null and b/examples/graphics/climacons/clear-night.png differ diff --git a/examples/graphics/climacons/cloudy.png b/examples/graphics/climacons/cloudy.png new file mode 100644 index 0000000..867f232 Binary files /dev/null and b/examples/graphics/climacons/cloudy.png differ diff --git a/examples/graphics/climacons/fog.png b/examples/graphics/climacons/fog.png new file mode 100644 index 0000000..c90bc6f Binary files /dev/null and b/examples/graphics/climacons/fog.png differ diff --git a/examples/graphics/climacons/partly-cloudy-day.png b/examples/graphics/climacons/partly-cloudy-day.png new file mode 100644 index 0000000..d33b56b Binary files /dev/null and b/examples/graphics/climacons/partly-cloudy-day.png differ diff --git a/examples/graphics/climacons/partly-cloudy-night.png b/examples/graphics/climacons/partly-cloudy-night.png new file mode 100644 index 0000000..66eaa88 Binary files /dev/null and b/examples/graphics/climacons/partly-cloudy-night.png differ diff --git a/examples/graphics/climacons/rain.png b/examples/graphics/climacons/rain.png new file mode 100644 index 0000000..34f844f Binary files /dev/null and b/examples/graphics/climacons/rain.png differ diff --git a/examples/graphics/climacons/readme.md b/examples/graphics/climacons/readme.md new file mode 100644 index 0000000..d610a00 --- /dev/null +++ b/examples/graphics/climacons/readme.md @@ -0,0 +1,10 @@ +# Climacons by Adam Whitcroft + +75 climatically categorised pictographs for web and UI design by [@adamwhitcroft](http://www.twitter.com/#!/adamwhitcroft). + +Visit the [Climacons](http://adamwhitcroft.com/climacons/) website for more information. + +Visit [Adam Whitcroft on GitHub](https://github.com/AdamWhitcroft) + +## License +You are free to use any of the Climacons Icons (the "icons") in any personal or commercial work without obligation of payment (monetary or otherwise) or attribution, however a credit for the work would be appreciated. **Do not** redistribute or sell and **do not** claim creative credit. Intellectual property rights are not transferred with the download of the icons. \ No newline at end of file diff --git a/examples/graphics/climacons/sleet.png b/examples/graphics/climacons/sleet.png new file mode 100644 index 0000000..1cf5315 Binary files /dev/null and b/examples/graphics/climacons/sleet.png differ diff --git a/examples/graphics/climacons/snow.png b/examples/graphics/climacons/snow.png new file mode 100644 index 0000000..fabc4d6 Binary files /dev/null and b/examples/graphics/climacons/snow.png differ diff --git a/examples/graphics/climacons/wind.png b/examples/graphics/climacons/wind.png new file mode 100644 index 0000000..f410f7f Binary files /dev/null and b/examples/graphics/climacons/wind.png differ diff --git a/examples/weather.py b/examples/weather.py new file mode 100644 index 0000000..fe9f0af --- /dev/null +++ b/examples/weather.py @@ -0,0 +1,127 @@ +#!/usr/bin/python + + +# Adapted script from Adafruit +# Weather forecast for Raspberry Pi w/Adafruit Mini Thermal Printer. +# Retrieves data from DarkSky.net's API, prints current conditions and +# forecasts for next two days. +# Weather example using nice bitmaps. +# Written by Adafruit Industries. MIT license. +# Adapted and enhanced for escpos library by MrWunderbar666 + +# Icons taken from http://adamwhitcroft.com/climacons/ +# Check out his github: https://github.com/AdamWhitcroft/climacons + + +from __future__ import print_function +from datetime import datetime +import calendar +import urllib +import json +import time +import os + +from escpos.printer import Usb + +""" Setting up the main pathing """ +this_dir, this_filename = os.path.split(__file__) +GRAPHICS_PATH = os.path.join(this_dir, "graphics/climacons/") + +# Adapt to your needs +printer = Usb(0x0416, 0x5011, profile="POS-5890") + +# You can get your API Key on www.darksky.net and register a dev account. +# Technically you can use any other weather service, of course :) +API_KEY = "YOUR API KEY" + +LAT = "22.345490" # Your Location +LONG = "114.189945" # Your Location + + +def forecast_icon(idx): + icon = data['daily']['data'][idx]['icon'] + image = GRAPHICS_PATH + icon + ".png" + return image + + +# Dumps one forecast line to the printer +def forecast(idx): + date = datetime.fromtimestamp(int(data['daily']['data'][idx]['time'])) + day = calendar.day_name[date.weekday()] + lo = data['daily']['data'][idx]['temperatureMin'] + hi = data['daily']['data'][idx]['temperatureMax'] + cond = data['daily']['data'][idx]['summary'] + print(date) + print(day) + print(lo) + print(hi) + print(cond) + time.sleep(1) + printer.set( + font='a', + height=2, + align='left', + bold=False, + double_height=False) + printer.text(day + ' \n ') + time.sleep(5) # Sleep to prevent printer buffer overflow + printer.text('\n') + printer.image(forecast_icon(idx)) + printer.text('low ' + str(lo)) + printer.text(deg) + printer.text('\n') + printer.text(' high ' + str(hi)) + printer.text(deg) + printer.text('\n') + # take care of pesky unicode dash + printer.text(cond.replace(u'\u2013', '-').encode('utf-8')) + printer.text('\n \n') + + +def icon(): + icon = data['currently']['icon'] + image = GRAPHICS_PATH + icon + ".png" + return image + + +deg = ' C' # Degree symbol on thermal printer, need to find a better way to use a proper degree symbol + +# if you want Fahrenheit change units= to 'us' +url = "https://api.darksky.net/forecast/" + API_KEY + "/" + LAT + "," + LONG + \ + "?exclude=[alerts,minutely,hourly,flags]&units=si" # change last bit to 'us' for Fahrenheit +response = urllib.urlopen(url) +data = json.loads(response.read()) + +printer.print_and_feed(n=1) +printer.control("LF") +printer.set(font='a', height=2, align='center', bold=True, double_height=True) +printer.text("Weather Forecast") +printer.text("\n") +printer.set(align='center') + + +# Print current conditions +printer.set(font='a', height=2, align='center', bold=True, double_height=False) +printer.text('Current conditions: \n') +printer.image(icon()) +printer.text("\n") + +printer.set(font='a', height=2, align='left', bold=False, double_height=False) +temp = data['currently']['temperature'] +cond = data['currently']['summary'] +printer.text(temp) +printer.text(' ') +printer.text(deg) +printer.text(' ') +printer.text('\n') +printer.text('Sky: ' + cond) +printer.text('\n') +printer.text('\n') + +# Print forecast +printer.set(font='a', height=2, align='center', bold=True, double_height=False) +printer.text('Forecast: \n') +forecast(0) +forecast(1) +printer.cut +printer.control("LF")