Last active
May 6, 2019 19:17
-
-
Save LuRsT/0548819475bb8c66105426f5f625af53 to your computer and use it in GitHub Desktop.
Getting reuter news in a raspberry pi using Pimoroni wHAT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from PIL import Image, ImageFont, ImageDraw | |
from bs4 import BeautifulSoup | |
from font_hanken_grotesk import HankenGroteskMedium | |
from inky import InkyWHAT | |
import requests | |
def main(): | |
print("""Inky wHAT: News from Reuters""") | |
# Config for display | |
inky_display = InkyWHAT("red") | |
scale_size = 2.20 | |
padding = 15 | |
inky_display.set_border(inky_display.RED) | |
font = ImageFont.truetype(HankenGroteskMedium, int(10 * scale_size)) | |
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) | |
drawer = ImageDraw.Draw(img) | |
height = 10 | |
trim_string = lambda s: s.strip() | |
for new in map(trim_string, grab_ten_news()): | |
drawer.text((10, height), new, inky_display.BLACK, font=font) | |
height += 26 | |
inky_display.set_image(img) | |
inky_display.show() | |
def grab_ten_news(): | |
link = 'http://www.reuters.com/news/' | |
page = requests.get(link) | |
soup = BeautifulSoup(page.text, 'html.parser') | |
counter = 0 | |
news = [] | |
for new in soup.find_all("h3", class_="story-title"): | |
if new.string is not None and counter < 10: | |
counter += 1 | |
news.append(new.string) | |
return news | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment