Skip to content

Instantly share code, notes, and snippets.

@LuRsT
Last active May 6, 2019 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuRsT/0548819475bb8c66105426f5f625af53 to your computer and use it in GitHub Desktop.
Save LuRsT/0548819475bb8c66105426f5f625af53 to your computer and use it in GitHub Desktop.
Getting reuter news in a raspberry pi using Pimoroni wHAT
#!/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