Advertisement
Guest User

Grab "Today in History"

a guest
May 12th, 2022
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. # Run as a cron job daily or as an event:
  2. # For example: 'python3 otdih.py > output_file.asc'
  3. # Be sure to install bs4 and unidecode
  4.  
  5. # -*- coding: utf-8 -*-
  6.  
  7. import os, sys, textwrap
  8. import requests
  9. from bs4 import BeautifulSoup
  10. from unidecode import unidecode
  11.  
  12.  
  13. def getOTD():
  14. r = requests.get('https://www.timeanddate.com/on-this-day/')
  15. soup = BeautifulSoup(r.content, 'html.parser')
  16. s = soup.find('ul', class_='list--big')
  17. dates = s.find_all('strong')
  18. content = s.find_all('li')
  19. otd = soup.title.text
  20.  
  21. dateList = []
  22. eventList = []
  23.  
  24. for text in dates:
  25. cleanDates = text.get_text()
  26. if int(len(cleanDates)) < 4:
  27. padding = 4 - int(len(cleanDates))
  28. cleanDates = ' ' * padding + cleanDates
  29. dateList.append(cleanDates)
  30.  
  31. for line in content:
  32. dateline = line.find('h3', class_='otd-title')
  33. stripDate = dateline.find('strong'); stripDate.extract()
  34. eventList.append(unidecode(dateline.text[1:]))
  35.  
  36. # Change the colors or text below to match your board
  37.  
  38. print('|CL|CR|17|12 >> |14' + otd + '|12 << |16\n')
  39.  
  40. i = 0
  41. while i <= int(len(cleanDates)):
  42. dateHeadline = textwrap.fill('|15' + dateList[i] + '|07: ' + eventList[i] + '\n', initial_indent='', subsequent_indent=' ', width=50)
  43. print(dateHeadline + '\n')
  44. i += 1
  45. data = '|01Data from www.timeanddate.com'.center(48)
  46. print(data + '\n|PA')
  47.  
  48. getOTD()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement