Skip to content

Commit

Permalink
Insert song title and artist at the beginning of the lyrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
francocruces committed Oct 28, 2017
1 parent 9de46d4 commit da5c6b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions AZScrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def get_lyrics_as_inline_keyboard(query):
id=query,
title="Search for " + query,
description=str(len(buttons)) + " results found",
input_message_content=InputTextMessageContent(message_text='Results for "' + query + '".\n' + str(
len(buttons)) + ' results found.\n' + 'Choose a result to load.'),
input_message_content=InputTextMessageContent(message_text='Results for "*' + query + '*".\n' + str(
len(buttons)) + ' results found.\n' + '_Choose a result to load._',
parse_mode="Markdown"),
reply_markup=InlineKeyboardMarkup(inline_keyboard=buttons)
)]
# TODO: Add a cancel button.
Expand Down Expand Up @@ -104,10 +105,13 @@ def get_lyric_body(url):
time.sleep(2)
print("Getting lyrics body: " + url)
page = urllib.request.urlopen(url)
lyrics = BeautifulSoup(page.read(), 'lxml').html.body.find_all(
"div", class_="col-xs-12 col-lg-8 text-center")[0].find_all("div")[6].get_text()
body = BeautifulSoup(page.read(), 'lxml').html.body.find_all(
"div", class_="col-xs-12 col-lg-8 text-center")[0].find_all("div")
lyrics = body[6].get_text()
artist = body[4].text.replace(" Lyrics", "").replace("\n","")
title = body[3].text.replace(" lyrics", "").replace('"', '')
print("Done: " + url)
return lyrics
return "*" + title + " by " + artist + "*" + lyrics


def get_lyric_body_from_id(an_id):
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def on_callback_query(self, msg):
in_id = msg['inline_message_id']
lyrics = get_lyric_body_from_id(msg['data'])
if len(lyrics) <= MAX_MESSAGE_SIZE:
await self.bot.editMessageText(str(in_id), lyrics)
await self.bot.editMessageText(str(in_id), lyrics, parse_mode="Markdown")
else:
await self.bot.editMessageText(str(in_id), MESSAGE_TOO_LONG_ALERT, parse_mode="Markdown")
while lyrics != "":
Expand Down

0 comments on commit da5c6b3

Please sign in to comment.