69 lines
2.7 KiB
Python
69 lines
2.7 KiB
Python
|
import pythonbible as bible
|
||
|
import random, argparse, datetime
|
||
|
import pandas as pd
|
||
|
|
||
|
def generate_readplan(start_date):
|
||
|
book_groups = bible.BOOK_GROUPS
|
||
|
reading_list = []
|
||
|
|
||
|
# Drop OLD TESTAMENT and NEW TESTAMENT from book_groups
|
||
|
all_books = list(set(book_groups['Old Testament'])) + list(set(book_groups['New Testament']))
|
||
|
book_groups.pop('Old Testament', 'New Testament')
|
||
|
|
||
|
# Randomly order book groups
|
||
|
book_groups = dict(sorted(book_groups.items(), key=lambda x: random.random()))
|
||
|
|
||
|
for group in book_groups.keys():
|
||
|
reading_list.extend(book_groups[group])
|
||
|
reading_list = list(set(reading_list))
|
||
|
|
||
|
# Find missing books in reading_list
|
||
|
missing_books = list(set(all_books) - set(reading_list))
|
||
|
|
||
|
# Randomly order missing books
|
||
|
missing_books = sorted(missing_books, key=lambda x: random.random())
|
||
|
|
||
|
# Insert missing books in reading_list
|
||
|
for book in missing_books:
|
||
|
reading_list.insert(random.randint(0, len(reading_list)), book)
|
||
|
|
||
|
total_chapters = sum([bible.get_number_of_chapters(reading_list[i]) for i in range(len(reading_list))])
|
||
|
chapters_per_day = total_chapters // 365 + 1
|
||
|
|
||
|
df = pd.DataFrame(columns=['Book', 'Chapters'])
|
||
|
for book in reading_list:
|
||
|
df = pd.concat([df, pd.DataFrame({'Book': [book.title], 'Chapters': [bible.get_number_of_chapters(book)]})])
|
||
|
|
||
|
# Generate a reading plan, by reading 4 chapters per day, until the reading list is empty. Read 4 chapters per day
|
||
|
reading_plan_df = pd.DataFrame(columns=['Date', 'Book', 'Start Chapter', 'End Chapter'])
|
||
|
date = pd.Timestamp(start_date) # Start date
|
||
|
|
||
|
for row in df.iterrows():
|
||
|
book = row[1]['Book']
|
||
|
chapters = row[1]['Chapters']
|
||
|
start_chapter = 1
|
||
|
end_chapter = min(chapters, start_chapter + chapters_per_day - 1)
|
||
|
|
||
|
while start_chapter <= chapters:
|
||
|
reading_plan_df = pd.concat([reading_plan_df, pd.DataFrame({'Date': [date], 'Book': [book], 'Start Chapter': [start_chapter], 'End Chapter': [end_chapter]})])
|
||
|
date += pd.Timedelta(days=1)
|
||
|
start_chapter = end_chapter + 1
|
||
|
end_chapter = min(chapters, start_chapter + chapters_per_day - 1)
|
||
|
|
||
|
# Set date as index
|
||
|
reading_plan_df.set_index('Date', inplace=True)
|
||
|
|
||
|
return reading_plan_df
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
# Add start date as argument
|
||
|
parser = argparse.ArgumentParser()
|
||
|
parser.add_argument('--start_date', help='Start date of the reading plan (YYYY-MM-DD)', required=False, type=str)
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
if not args.start_date:
|
||
|
args.start_date = datetime.datetime.now().strftime('%Y-%m-%d')
|
||
|
|
||
|
reading_list = generate_readplan(start_date=args.start_date)
|
||
|
reading_list.to_csv(f'reading_plan_{args.start_date}.csv', index=True)
|