-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MoYoez
committed
Sep 10, 2023
1 parent
1a15f9a
commit 6902377
Showing
5 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import difflib | ||
from pathlib import Path | ||
|
||
|
||
load_songname_list = [] | ||
load_dict = {} | ||
|
||
load_data = Path().absolute() / "info.csv" | ||
|
||
|
||
with open(load_data, "r", encoding="utf-8") as f: | ||
reader = f.readlines() | ||
i = 0 | ||
for row in reader: | ||
split_data = row.split("\\") | ||
# Generate a dict | ||
song_id = split_data[0] | ||
song_name = split_data[1] | ||
# load dict | ||
load_dict.update({song_name: song_id}) | ||
load_songname_list.append(split_data[1]) | ||
i + 1 | ||
|
||
|
||
def search_song(parmas: str): | ||
best_match = None | ||
best_ratio = 0 | ||
for i in range(len(load_songname_list)): | ||
get_name = load_songname_list[i] | ||
# use fuzzy | ||
similarity_ratio = difflib.SequenceMatcher(None, parmas, get_name).ratio() | ||
if similarity_ratio > best_ratio: | ||
best_ratio = similarity_ratio | ||
best_match = get_name | ||
best_song_id = load_dict[best_match] | ||
return best_match, best_ratio, best_song_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
Flask==2.3.2 | ||
pycryptodome==3.18.0 | ||
Requests==2.31.0 | ||
Requests==2.31.0 |