Skip to content

Commit

Permalink
Code style: black
Browse files Browse the repository at this point in the history
  • Loading branch information
engineervix committed Oct 3, 2019
1 parent c00c9f9 commit 2484aa1
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 145 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bible-Playlist-Generator

[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)

[![python3](https://img.shields.io/badge/python-3.6%20%7C%203.7-brightgreen.svg)](https://python3statement.org/#sections50-why) [![CircleCI](https://circleci.com/gh/engineervix/Bible-Playlist-Generator/tree/master.svg?style=svg)](https://circleci.com/gh/engineervix/Bible-Playlist-Generator/tree/master) [![Coverage Status](https://coveralls.io/repos/github/engineervix/Bible-Playlist-Generator/badge.svg)](https://coveralls.io/github/engineervix/Bible-Playlist-Generator)
[![python3](https://img.shields.io/badge/python-3.6%20%7C%203.7-brightgreen.svg)](https://python3statement.org/#sections50-why) [![CircleCI](https://circleci.com/gh/engineervix/Bible-Playlist-Generator/tree/master.svg?style=svg)](https://circleci.com/gh/engineervix/Bible-Playlist-Generator/tree/master) [![Coverage Status](https://coveralls.io/repos/github/engineervix/Bible-Playlist-Generator/badge.svg)](https://coveralls.io/github/engineervix/Bible-Playlist-Generator) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

This python script generates an m3u playlist of 10 Bible Chapters (represented by 10 mp3 files) to be listened to on any given day _x_, according to [**Professor Grant Horner's Bible-Reading System**](http://www.thevinefellowship.com/10Lists.pdf). The audio Bible is as downloaded from the [_Faith Comes by Hearing®_ website](http://www.bible.is/audiodownloader).

Expand Down
121 changes: 68 additions & 53 deletions bible_playlist_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

try:
import colorama

colorama.init()
except ImportError:
colorama = None
Expand All @@ -38,16 +39,15 @@ def log(string, color, font="mini", figlet=False):
if not figlet:
print(colored(string, color))
else:
print(colored(figlet_format(
string, font=font), color))
print(colored(figlet_format(string, font=font), color))
else:
print(string)


def log_traceback(ex):
"""Logs Errors"""
tb_lines = traceback.format_exception(ex.__class__, ex, ex.__traceback__)
tb_text = ''.join(tb_lines)
tb_text = "".join(tb_lines)
log(tb_text, "red")


Expand All @@ -56,7 +56,7 @@ def ten_lists():
the_ten_lists = []

list_dir = os.path.join(os.getcwd(), "data")
filelist = glob.glob(os.path.join(list_dir, '*.txt'))
filelist = glob.glob(os.path.join(list_dir, "*.txt"))

for fname in sorted(filelist):
with open(fname) as fn:
Expand All @@ -70,15 +70,15 @@ def reading_list(day, bible_dir):
The generated reading (or listening) list for the given day.
bible_dir is the directory containing the mp3 files.
"""
list_1 = ten_lists()[0] # len(list_1) = 89
list_2 = ten_lists()[1] # len(list_2) = 187
list_3 = ten_lists()[2] # len(list_3) = 78
list_4 = ten_lists()[3] # len(list_4) = 65
list_5 = ten_lists()[4] # len(list_5) = 62
list_6 = ten_lists()[5] # len(list_6) = 150
list_7 = ten_lists()[6] # len(list_7) = 31
list_8 = ten_lists()[7] # len(list_8) = 249
list_9 = ten_lists()[8] # len(list_9) = 250
list_1 = ten_lists()[0] # len(list_1) = 89
list_2 = ten_lists()[1] # len(list_2) = 187
list_3 = ten_lists()[2] # len(list_3) = 78
list_4 = ten_lists()[3] # len(list_4) = 65
list_5 = ten_lists()[4] # len(list_5) = 62
list_6 = ten_lists()[5] # len(list_6) = 150
list_7 = ten_lists()[6] # len(list_7) = 31
list_8 = ten_lists()[7] # len(list_8) = 249
list_9 = ten_lists()[8] # len(list_9) = 250
list_10 = ten_lists()[9] # len(list_10) = 28

listening_list = []
Expand All @@ -89,60 +89,59 @@ def reading_list(day, bible_dir):
try:
# for indexing purposes, since the first index is represented by 0
index = day - 1
current_reading_list = [bible_list[index]
for bible_list in ten_lists()]
current_reading_list = [bible_list[index] for bible_list in ten_lists()]
for chapter in current_reading_list:
listening_list.append(bible_dir + chapter)
return listening_list

except IndexError:
if len(ten_lists()[6]) >= day > len(ten_lists()[9]):
current_reading_list = [bible_list[index]
for bible_list in ten_lists()[:-1]]
current_reading_list = [
bible_list[index] for bible_list in ten_lists()[:-1]
]
for chapter in current_reading_list:
listening_list.append(bible_dir + chapter)
index = day - 1 - len(ten_lists()[9])
listening_list.append(bible_dir + list_10[index])
return listening_list

if len(ten_lists()[4]) >= day > len(ten_lists()[6]):
current_reading_list = [bible_list[index]
for bible_list in ten_lists()[:-4]]
current_reading_list = [
bible_list[index] for bible_list in ten_lists()[:-4]
]
for chapter in current_reading_list:
listening_list.append(bible_dir + chapter)
index = day - 1 - len(ten_lists()[6])
listening_list.append(bible_dir + list_7[index])
listening_list.append(bible_dir + list_8[day-1])
listening_list.append(bible_dir + list_9[day-1])
listening_list.append(bible_dir + list_8[day - 1])
listening_list.append(bible_dir + list_9[day - 1])
index = day - 1 - len(ten_lists()[9])
while index >= len(ten_lists()[9]):
index = index - len(ten_lists()[9])
listening_list.append(bible_dir + list_10[index])
return listening_list

if len(ten_lists()[3]) >= day > len(ten_lists()[4]):
current_reading_list = [bible_list[index]
for bible_list in ten_lists()[:4]]
current_reading_list = [bible_list[index] for bible_list in ten_lists()[:4]]
for chapter in current_reading_list:
listening_list.append(bible_dir + chapter)
index = day - 1 - len(ten_lists()[4])
listening_list.append(bible_dir + list_5[index])
listening_list.append(bible_dir + list_6[day-1])
listening_list.append(bible_dir + list_6[day - 1])
index = day - 1 - len(ten_lists()[6])
while index >= len(ten_lists()[6]):
index = index - len(ten_lists()[6])
listening_list.append(bible_dir + list_7[index])
listening_list.append(bible_dir + list_8[day-1])
listening_list.append(bible_dir + list_9[day-1])
listening_list.append(bible_dir + list_8[day - 1])
listening_list.append(bible_dir + list_9[day - 1])
index = day - 1 - len(ten_lists()[9])
while index >= len(ten_lists()[9]):
index = index - len(ten_lists()[9])
listening_list.append(bible_dir + list_10[index])
return listening_list

if len(ten_lists()[2]) >= day > len(ten_lists()[3]):
current_reading_list = [bible_list[index]
for bible_list in ten_lists()[:3]]
current_reading_list = [bible_list[index] for bible_list in ten_lists()[:3]]
for chapter in current_reading_list:
listening_list.append(bible_dir + chapter)
index = day - 1 - len(ten_lists()[3])
Expand All @@ -151,12 +150,12 @@ def reading_list(day, bible_dir):
while index >= len(ten_lists()[4]):
index = index - len(ten_lists()[4])
listening_list.append(bible_dir + list_5[index])
listening_list.append(bible_dir + list_6[day-1])
listening_list.append(bible_dir + list_6[day - 1])
index = day - 1 - len(ten_lists()[6])
while index >= len(ten_lists()[6]):
index = index - len(ten_lists()[6])
listening_list.append(bible_dir + list_7[index])
listening_list.append(bible_dir + list_8[day-1])
listening_list.append(bible_dir + list_8[day - 1])
listening_list.append(bible_dir + list_9[day - 1])
index = day - 1 - len(ten_lists()[9])
while index >= len(ten_lists()[9]):
Expand All @@ -165,8 +164,7 @@ def reading_list(day, bible_dir):
return listening_list

if len(ten_lists()[0]) >= day > len(ten_lists()[2]):
current_reading_list = [bible_list[index]
for bible_list in ten_lists()[:2]]
current_reading_list = [bible_list[index] for bible_list in ten_lists()[:2]]
for chapter in current_reading_list:
listening_list.append(bible_dir + chapter)
index = day - 1 - len(ten_lists()[2])
Expand Down Expand Up @@ -385,10 +383,12 @@ def create_m3u(day, bible_dir):
try:
with open(m3u_filename, "a") as m3u:
m3u.write("#EXTM3U\n")
m3u.write('\n'.join(reading_list(day, bible_dir)))
m3u.write("\n".join(reading_list(day, bible_dir)))
except Exception as ex:
log("✗ Oops! Something went wrong while attempting to " +
"create a playlist.", "red")
log(
"✗ Oops! Something went wrong while attempting to " + "create a playlist.",
"red",
)
log_traceback(ex)
else:
success_msg = f"✓ playlist for day {str(day)} successfully created."
Expand All @@ -398,7 +398,7 @@ def create_m3u(day, bible_dir):
def create_mp3_dir(day, bible_dir):
"""Copies the generated mp3 files into separate directory"""
# Now we copy the files into a new folder
out_dir = "day"+str(day).zfill(3)
out_dir = "day" + str(day).zfill(3)

try:
if not os.path.exists(out_dir):
Expand All @@ -408,46 +408,61 @@ def create_mp3_dir(day, bible_dir):
tmp = list(i.strip())
copy("".join(tmp), out_dir)
except Exception as ex:
log("✗ Oops! Something went wrong while attempting to copy files",
"red")
log("✗ Oops! Something went wrong while attempting to copy files", "red")
log_traceback(ex)
else:
log("✓ Copying of the Bible Chapters into the " +
out_dir + " directory was successful.", "green")
log(
"✓ Copying of the Bible Chapters into the "
+ out_dir
+ " directory was successful.",
"green",
)

# We now change the ID3 tag information (track number)
# We also rename the files in the destination directory
track_number = 1

try:
for i in reading_list(day, bible_dir):
tmp = list(i.strip().replace(bible_dir, out_dir+'/', 1))
tmp = list(i.strip().replace(bible_dir, out_dir + "/", 1))
f = "".join(tmp)
audiofile = eyed3.load(f)
audiofile.tag.track_num = track_number
audiofile.tag.save()
filename = f.replace(out_dir+'/', '')
filename = f.replace(out_dir + "/", "")
# add a filename prefix with leading zeroes
f_new = out_dir+'/'+str(track_number).zfill(3) + filename[4:]
f_new = out_dir + "/" + str(track_number).zfill(3) + filename[4:]
os.rename(f, f_new)
track_number += 1
except Exception as ex:
log("Oops! Something went wrong while processing the mp3 files", "red")
log_traceback(ex)
else:
log("✓ ID3 tag info for the generated files in this "
"directory has been updated.", "green")
log(
"✓ ID3 tag info for the generated files in this "
"directory has been updated.",
"green",
)
log("✓ The files have been renamed in a sequential order.", "green")
log("\n-----Soli Deo Gloria-----\n", "cyan")


@click.command()
@click.option('--day', '-d', required=True, type=click.IntRange(1),
prompt="Please enter the day of the reading plan, as in, " +
"eg. day 1, or day 32",
help='the day of the reading plan, as in, eg. day 1, or day 32')
@click.option('--folder', '-f', default="ENGESVC2DA", show_default=True,
help='the folder containing the Bible mp3 files')
@click.option(
"--day",
"-d",
required=True,
type=click.IntRange(1),
prompt="Please enter the day of the reading plan, as in, " + "eg. day 1, or day 32",
help="the day of the reading plan, as in, eg. day 1, or day 32",
)
@click.option(
"--folder",
"-f",
default="ENGESVC2DA",
show_default=True,
help="the folder containing the Bible mp3 files",
)
def cmd(day, folder):
"""
Bible Playlist Generator » generates a playlist of 10 Bible Chapters
Expand All @@ -456,12 +471,12 @@ def cmd(day, folder):

log("Bible Playlist Generator", color="magenta", figlet=True)
log("Welcome to the Bible Playlist Generator", "cyan")
click.secho(f"\nCreating a playlist for day {str(day)} ...", fg='white')
click.secho(f"\nCreating a playlist for day {str(day)} ...", fg="white")

create_m3u(day, folder)
create_mp3_dir(day, folder)


if __name__ == '__main__':
if __name__ == "__main__":
# pylint: disable=no-value-for-parameter
cmd()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pytest-cov==2.7.1
tqdm==4.36.1

# python style
black
autopep8==1.4.4
doc8==0.8.0
flake8==3.7.8
Expand Down
Loading

0 comments on commit 2484aa1

Please sign in to comment.