mirror of
https://github.com/python-escpos/python-escpos
synced 2025-08-24 09:03:34 +00:00
Drop Py37, improve typing and docstrings (#544)
Drops Py3.7, improves typing and adds a mypy config, improves the docstrings and isorts the imports. * configure isort * sort with isort * add github action * enable flake8-docstrings * fix docstrings * add mypy env * no implicit optional * add type for raw * add some type hints
This commit is contained in:
@@ -1,28 +1,29 @@
|
||||
#!/usr/bin/python
|
||||
"""Weather forecast example.
|
||||
|
||||
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 https://adamwhitcroft.com/climacons/
|
||||
Check out his github: https://github.com/AdamWhitcroft/climacons
|
||||
"""
|
||||
|
||||
|
||||
# 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 https://adamwhitcroft.com/climacons/
|
||||
# Check out his github: https://github.com/AdamWhitcroft/climacons
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
import calendar
|
||||
import urllib
|
||||
import json
|
||||
import time
|
||||
import os
|
||||
import time
|
||||
import urllib
|
||||
from datetime import datetime
|
||||
|
||||
from escpos.printer import Usb
|
||||
|
||||
""" Setting up the main pathing """
|
||||
"""Set up the main pathing."""
|
||||
this_dir, this_filename = os.path.split(__file__)
|
||||
GRAPHICS_PATH = os.path.join(this_dir, "graphics/climacons/")
|
||||
|
||||
@@ -38,13 +39,14 @@ LONG = "114.189945" # Your Location
|
||||
|
||||
|
||||
def forecast_icon(idx):
|
||||
"""Get right icon for forecast."""
|
||||
icon = data["daily"]["data"][idx]["icon"]
|
||||
image = GRAPHICS_PATH + icon + ".png"
|
||||
return image
|
||||
|
||||
|
||||
# Dumps one forecast line to the printer
|
||||
def forecast(idx):
|
||||
"""Dump one forecast line to the printer."""
|
||||
date = datetime.fromtimestamp(int(data["daily"]["data"][idx]["time"]))
|
||||
day = calendar.day_name[date.weekday()]
|
||||
lo = data["daily"]["data"][idx]["temperatureMin"]
|
||||
@@ -73,6 +75,7 @@ def forecast(idx):
|
||||
|
||||
|
||||
def icon():
|
||||
"""Get icon."""
|
||||
icon = data["currently"]["icon"]
|
||||
image = GRAPHICS_PATH + icon + ".png"
|
||||
return image
|
||||
|
Reference in New Issue
Block a user