~fkfd/one_top_song

one_top_song/data/mkjson.py -rw-r--r-- 712 bytes
26ca7fbcFrederick Yin Remove "ripped" (Redecorate) 10 days ago
                                                                                
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
import json
import re
import os

lyrics = {}

for fn in os.listdir("all"):
    f = open(f"all/{fn}")
    # keep a list of every different line in this track
    lyrics[fn.replace(".txt", "")] = set(f.read().splitlines())
    f.close()

f = open("list")
words = f.read().splitlines()
f.close()

output = []

for w in words:
    track, word = tuple(w.split("\t"))
    # look for word (case insensitive) in lyrics[track]
    lines = [line for line in lyrics[track] if re.search(r"\b" + word + r"\b", line, re.I)]
    output.append(
        {
            "track": track,
            "word": word,
            "lines": lines,
        }
    )

with open("words.json", "w") as f:
    json.dump(output, f)
    f.close()