Spaces:
Running
Running
Commit
•
b26dd30
1
Parent(s):
151619b
Update songscope.py
Browse files- songscope.py +39 -2
songscope.py
CHANGED
@@ -3,14 +3,51 @@ import requests
|
|
3 |
from bs4 import BeautifulSoup
|
4 |
import time
|
5 |
import random
|
6 |
-
!python -m pip install levenshtein
|
7 |
-
import Levenshtein
|
8 |
import nltk
|
9 |
!python -m pip install git+https://github.com/elmoiv/azapi.git
|
10 |
import azapi
|
11 |
from nltk.sentiment import SentimentIntensityAnalyzer
|
12 |
nltk.download("vader_lexicon")
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def random_delay(min_val: float, max_val: float, print_delay: bool = False):
|
15 |
"""
|
16 |
Inserts a random delay between website pings to simulate human-like behavior.
|
|
|
3 |
from bs4 import BeautifulSoup
|
4 |
import time
|
5 |
import random
|
6 |
+
# !python -m pip install levenshtein
|
7 |
+
# import Levenshtein
|
8 |
import nltk
|
9 |
!python -m pip install git+https://github.com/elmoiv/azapi.git
|
10 |
import azapi
|
11 |
from nltk.sentiment import SentimentIntensityAnalyzer
|
12 |
nltk.download("vader_lexicon")
|
13 |
|
14 |
+
# jaro distance from scratch because importing or installing the module didn't work
|
15 |
+
def homemade_jaro(s1, s2):
|
16 |
+
if not s1 or not s2:
|
17 |
+
return 0.0
|
18 |
+
|
19 |
+
len_s1, len_s2 = len(s1), len(s2)
|
20 |
+
|
21 |
+
match_distance = max(len_s1, len_s2) // 2 - 1
|
22 |
+
|
23 |
+
s1_matches, s2_matches = [False] * len_s1, [False] * len_s2
|
24 |
+
matches, transpositions = 0, 0
|
25 |
+
|
26 |
+
for i, c1 in enumerate(s1):
|
27 |
+
start, end = max(0, i - match_distance), min(i + match_distance + 1, len_s2)
|
28 |
+
for j, c2 in enumerate(s2[start:end], start=start):
|
29 |
+
if c1 == c2 and not s2_matches[j]:
|
30 |
+
s1_matches[i] = s2_matches[j] = True
|
31 |
+
matches += 1
|
32 |
+
break
|
33 |
+
|
34 |
+
if matches == 0:
|
35 |
+
return 0.0
|
36 |
+
|
37 |
+
k = 0
|
38 |
+
for i, matched in enumerate(s1_matches):
|
39 |
+
if matched:
|
40 |
+
while not s2_matches[k]:
|
41 |
+
k += 1
|
42 |
+
if s1[i] != s2[k]:
|
43 |
+
transpositions += 1
|
44 |
+
k += 1
|
45 |
+
|
46 |
+
transpositions //= 2
|
47 |
+
|
48 |
+
return (matches / len_s1 + matches / len_s2 + (matches - transpositions) / matches) / 3.0
|
49 |
+
|
50 |
+
|
51 |
def random_delay(min_val: float, max_val: float, print_delay: bool = False):
|
52 |
"""
|
53 |
Inserts a random delay between website pings to simulate human-like behavior.
|