-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (57 loc) · 2.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Bare bone py
from asyncore import write
from lyrics import fetch_lyrics
from transliterate import transliterate
import csv
import os
# Credits: https://stackoverflow.com/questions/29310792/how-to-save-a-list-as-a-csv-file-with-new-lines
def write_to_file(filename=None, data=[], transliterated=False):
if (os.path.exists(os.path.join(os.getcwd(), 'original'))):
pass
else:
# Make directory to store original lyrics files
os.mkdir(os.path.join(os.getcwd(), 'original'))
if (os.path.exists(os.path.join(os.getcwd(), 'transliterated'))):
pass
else:
# Make directory to store original lyrics files
os.mkdir(os.path.join(os.getcwd(), 'transliterated'))
if not transliterated:
with open('original/' + filename, "w", encoding="utf-8") as f:
wr = csv.writer(f,delimiter="\n")
wr.writerow(data)
else:
with open('transliterated/' + filename, "w", encoding="utf-8") as f:
wr = csv.writer(f,delimiter="\n")
wr.writerow(data)
# Todo: Check khalamgwr nang gou file ya dong na gwiya!
def remove_files():
print("Removing pre-existing files")
if (os.path.exists(os.path.join(os.getcwd(), 'original'))):
files = os.listdir(os.path.join(os.getcwd(), 'original'))
for f in files:
os.remove(os.path.join(os.getcwd(), 'original') + '/'+ f)
else:
pass
if (os.path.exists(os.path.join(os.getcwd(), 'transliterated'))):
files = os.listdir(os.path.join(os.getcwd(), 'transliterated'))
for f in files:
os.remove(os.path.join(os.getcwd(), 'transliterated') + '/' + f)
else:
pass
if __name__ == "__main__":
# remove files
remove_files()
lyrics_list = fetch_lyrics() # list of song-name, lyrics
for l in lyrics_list:
d = dict(l)
# For debugging
# print(d['lyrics'])
# print(transliterate(d['lyrics']))
transliterated_lyrics = transliterate(d['lyrics'])
write_to_file(d['song-name'], d['lyrics'])
write_to_file(d['song-name'], transliterated_lyrics, transliterated=True)
# writing to files
print("Done!")
print("Check Original and Transliterated Directories")
# pass