Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Run as a cron job daily or as an event:
- # For example: 'python3 otdih.py > output_file.asc'
- # Be sure to install bs4 and unidecode
- # -*- coding: utf-8 -*-
- import os, sys, textwrap
- import requests
- from bs4 import BeautifulSoup
- from unidecode import unidecode
- def getOTD():
- r = requests.get('https://www.timeanddate.com/on-this-day/')
- soup = BeautifulSoup(r.content, 'html.parser')
- s = soup.find('ul', class_='list--big')
- dates = s.find_all('strong')
- content = s.find_all('li')
- otd = soup.title.text
- dateList = []
- eventList = []
- for text in dates:
- cleanDates = text.get_text()
- if int(len(cleanDates)) < 4:
- padding = 4 - int(len(cleanDates))
- cleanDates = ' ' * padding + cleanDates
- dateList.append(cleanDates)
- for line in content:
- dateline = line.find('h3', class_='otd-title')
- stripDate = dateline.find('strong'); stripDate.extract()
- eventList.append(unidecode(dateline.text[1:]))
- # Change the colors or text below to match your board
- print('|CL|CR|17|12 >> |14' + otd + '|12 << |16\n')
- i = 0
- while i <= int(len(cleanDates)):
- dateHeadline = textwrap.fill('|15' + dateList[i] + '|07: ' + eventList[i] + '\n', initial_indent='', subsequent_indent=' ', width=50)
- print(dateHeadline + '\n')
- i += 1
- data = '|01Data from www.timeanddate.com'.center(48)
- print(data + '\n|PA')
- getOTD()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement