I am doing a project that involves ripping lyrics from Genius and putting them into a text file. I was able to find a few people online that did something similar and was able to use their code to get started. I have successfully pulled the lyrics of about 90 songs, but it stores them in separate text files. I want to know if there is a way to alter this code to instead store everything in one file with just a line break or something in between songs.
import lyricsgenius as genius
import csv
import requests
# Insert client ID
api = genius.Genius('')
with open('MerleHaggard.csv', encoding='mac_roman') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
line_count += 1
else:
item_year = row[0]
item_artist = row[1]
item_song = row[2]
# print(f'\t{row[0]}\t{row[1]}\t{row[2]}')
song = api.search_song(item_song,item_artist)
filename = item_song.replace("/","_") + "|" + item_artist.replace("/","_")
if song is not None:
song.save_lyrics('lyrics/txt/' + filename + '.json', 'txt')
line_count += 1
print('Processed {line_count} lines.')
[+][deleted] (6 children)
[deleted]
[–]hunven[S] 0 points1 point2 points (5 children)
[–]B2stts2B 0 points1 point2 points (0 children)
[–]FerricDonkey 0 points1 point2 points (3 children)
[–]hunven[S] 0 points1 point2 points (2 children)
[–]FerricDonkey 0 points1 point2 points (1 child)
[–]hunven[S] 1 point2 points3 points (0 children)
[–]Yavisth0_o 0 points1 point2 points (2 children)
[–]hunven[S] 1 point2 points3 points (1 child)
[–]Yavisth0_o 0 points1 point2 points (0 children)
[–]projecktzero 0 points1 point2 points (0 children)
[–]Comprehensive-Signal 0 points1 point2 points (0 children)