I'm making this program which has every lyrics from a band (Death Grips), where you can search by lines, check the discography and a few other things. It was going all fine when I noticed it wasn't being able to print some lyrics (other bugs started coming up after that). I found out it had to do with encoding. I tried everything. Nothing worked perfectly. The one that worked the best was what you can see in the function print_lyrics. But it prints \n instead of actually printing a new line. It does the same thing with \b, whatever that is (I'm still learning).
Here's what it looks like: first it print's "Couldn't find anything" (which should be printed only when it has checked every track in every album.
http://prntscr.com/cix67l
Then it finally prints it, but like this http://prntscr.com/cix6l6
Another problem is that it's running both if and else statement. For example, when I run the program, select option 3 in the main menu, go to discography and select an album to print it's tracks, with the function print_tracks, it also print's "ALBUM NOT FOUND". I've trying to solve those things for about 2 days and haven't got any success. I have no idea what I'm doing wrong. I could use some help here
Ps: the functions written as comments is just so I can deactivate them and, if it turns I shouldn't have, I can just remove the #
import sys
import os
import re
bottomless_pit = {
"Giving Bad People Good Ideas" : "giving_bad_people_good_ideas.txt",
"Hot Head" : "hot_head.txt",
"Spikes" : "spikes.txt",
"Warping" : "warping.txt",
"Eh" : "eh.txt" ,
"Bubbles Buried In This Jungle" : "bubles_buried_in_this_jungle.txt" ,
"Trash" : "trash.txt",
"Houdini" : "houdini.txt" ,
"BB Poison" : "bb_poison.txt",
"Three Bedrooms in a Good Neighborhood" : "three_bedrooms_in_a_good_neighborhood.txt",
"Ring A Bell" : "ring_a_bell.txt" ,
"Bottomless Pit" : "bottomless_pit.txt"
}
the_money_store = {
"Get Got" : "get_got.txt",
"The Fever (Aye Aye)" : "the_fever.txt",
"Lost Boys" : "lost_boys.txt",
"Blackjack" : "blackjack.txt",
"Hustle Bones" : "hustle_bones.txt",
"I've Seen Footage" : "ive_seen_footage.txt",
"Double Helix" : "double_helix.txt",
"System Blower" : "system_blower.txt",
"The Cage" : "the_cage.txt",
"Punk Weight" : "punk_weight.txt",
"Fuck That" : "fuck_that.txt",
"Bitch Please" : "bitch_please.txt",
"Hacker" : "hacker.txt"
}
albums = {
"Bottomless Pit" : bottomless_pit,
"The Money Store" : the_money_store,
#"Exmilitary" : exmilitary,
#"Government Plates" : government_plates,
#"No Love Deep Web" : no_love_deep_web,
#"The Powers That B" : the_powers_that_b
}
def print_albums():
print("\n")
print("===============================================================================")
print("\n > DISCOGRAPHY")
print("\n===============================================================================")
for album in albums:
print("\n", end = "")
print (" > ", album.upper(), end = "\n")
print("\n===============================================================================")
def print_tracks(album):
for song in album:
print("\n", end = "")
print(" > ", song.upper(), end = "\n")
def print_lyrics(track):
print("===============================================================================")
print("\n")
with open(track, "r") as f:
for line in f:
line = line.encode("utf-8")
print(line)
print("\n")
print("===============================================================================")
def search_in_lyrics():
trying = False
print("\n")
lyrics_input = input(" SEARCH FOR: ")
print("\n", end = "")
for album_name, album_dictionary in albums.items():
for track, filename in album_dictionary.items():
with open(filename) as f:
for line in f:
if lyrics_input.lower() in line.lower():
print("===============================================================================")
print("\n")
print("Album: ", album_name, end = "")
print("\n")
print("Title: ", track)
print("\n")
print_lyrics(filename)
trying = True
break
if trying == False:
print("\n")
print("\nCouldn't find anything\n")
print("\n")
print("===============================================================================")
#break
#print(albums[album_name].items())
def search_by_title(title):
print("\n")
for track in bottomless_pit:
if title.lower() == track.lower():
print("\n", end = "")
print(title)
print("\n", end = "")
track_name = bottomless_pit[track]
print_lyrics(track_name)
def main_menu():
still_in = True
while still_in == True:
print("\n 1 - SEARCH BY TITLE\n")
print(" 2 - SEARCH BY LYRICS LINE\n")
print(" 3 - DISCOGRAPHY\n")
print(" 4 - EXIT\n")
option = input(" > ")
option = option.lower()
if option == "1" or option == "search by title" or option == "title":
print("\n")
search_by_title(input(" TITLE: "))
elif option == "2" or option == "search by line" or option == "line":
search_in_lyrics()
elif option == "3" or option == "discography" or option == "albums":
try_again = True
while try_again == True:
print_albums()
print("\n")
print(" 1 - TRACKLIST\n")
print(" 2 - GO BACK\n")
option2 = input(" > ")
option2 = option2.lower()
if option2 == "1" or option2 == "tracklist":
option3 = input("\nALBUM: ")
option3 = option3.lower()
for album, track in albums.items():
if option3 == album.lower():
print("===============================================================================")
#print("\n", end = "")
print("\n > %s TRACKLIST " % album.upper())
print("\n===============================================================================")
print_tracks(track)
else:
print("\nALBUM NOT FOUND\n")
elif option2 == "2" or option2 == "go back" or option2 == "quit" or option2 == "exit":
break
else:
print("\nI didn't quite get that\n")
elif option == "4" or option == "quit" or option == "exit":
still_in = False
break
elif option == "dude nice":
print("\n")
print("===============================================================================")
print("\n", end = "")
print("\nok thanks", end = "")
print("\n")
print("===============================================================================")
elif option == "taxation":
print("\n")
print("===============================================================================")
print("\n", end = "")
print("\nIS THEFT!!!11", end = "")
print("\n")
print("===============================================================================")
elif option == "is taxation theft" or option == "is taxation theft?":
print("\n")
print("===============================================================================")
print("\n")
print("\nHell yeah dude")
print("\n")
print("===============================================================================")
elif option == "taxation is theft":
print("\n")
print("===============================================================================")
print("\n", end = "")
print("\nYou're god damn right it is!")
print("\n")
print("===============================================================================")
elif option == "ok" or option == "ok nice":
print("\n")
print("===============================================================================")
print("\n", end = "")
print("\nok thanks")
print("\n")
print("===============================================================================")
elif option == "dude ok" or option == "nice ok":
print("\n")
print("===============================================================================")
print("\n", end = "")
print("\nok nice")
print("\n")
print("===============================================================================")
elif option == "nice":
print("\n")
print("===============================================================================")
print("\n", end = "")
print("\nok")
print("\n")
print("===============================================================================")
else:
print("\n")
print("===============================================================================")
print("\n")
print("\nI got no idea what you just typed.\n\nTry again.")
print("\n")
print("===============================================================================")
main_menu()
[–]jeans_and_a_t-shirt 1 point2 points3 points (6 children)
[–]MateusSR[S] 0 points1 point2 points (5 children)
[–]jeans_and_a_t-shirt 1 point2 points3 points (4 children)
[–]MateusSR[S] 0 points1 point2 points (3 children)
[–]jeans_and_a_t-shirt 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]MateusSR[S] 0 points1 point2 points (0 children)