-
Notifications
You must be signed in to change notification settings - Fork 2
/
todays_readings.py
49 lines (37 loc) · 1.45 KB
/
todays_readings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pandas as pd
import numpy as np
import os
from bs4 import BeautifulSoup
import requests
import datetime as datetime
date = datetime.datetime.now().date()
datelist = pd.date_range(datetime.datetime.today(), periods=1).tolist()
def scrape_readings(currentDate):
page = requests.get('http://www.usccb.org/bible/readings/{}.cfm'.format(currentDate.date().strftime('%m%d%y')))
soup = BeautifulSoup(page.content, "html.parser")
h3 = soup.find_all('h3')
h4 = soup.find_all('h4')
return h3, h4, soup
def print_readings(currentDate,
h4
):
# print date
print('\n{}'.format(currentDate.date().strftime('%A %Y-%m-%d')))
# print feast
print(str(h3[2].contents[0]))
# print readings
for i in range(len(h4)):
reading = str(h4[i].contents[0]).strip().replace('Or',' (or)').replace('Responsorial ','')
verse = str(h4[i].contents[1].contents[0]).replace('\n','')
if reading != 'Alleluia' and len(reading)>0:
print('{0:10} {1}'.format(reading, verse))
for currentDate in datelist:
h3, h4, soup = scrape_readings(currentDate)
try:
print_readings(currentDate,h4)
except:
print('\n{}: ERROR'.format(currentDate.date().strftime('%a %Y-%m-%d')))
print('\n')
# run this automatically
## run: touch ~/.bash_profile; open ~/.bash_profile
## add: alias readings='cd Documents/GitHub/USCCB_daily_readings/; python todays_readings.py'