Spaces:
Paused
Paused
Update wordlist.py
Browse files- wordlist.py +28 -33
wordlist.py
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import urllib.request
|
| 3 |
-
import urllib.error
|
| 4 |
import config
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
if len(parts) == 2:
|
| 29 |
-
word = parts[0].strip()
|
| 30 |
-
if config.MIN_WORD_LEN <= len(word) <= config.MAX_WORD_LEN and word.isalpha():
|
| 31 |
-
try:
|
| 32 |
-
count = int(parts[1].strip())
|
| 33 |
-
data.append((word, count))
|
| 34 |
-
except ValueError:
|
| 35 |
-
continue
|
| 36 |
-
|
| 37 |
-
data.sort(key=lambda x: x[1], reverse=True)
|
| 38 |
-
return [word for word, count in data]
|
|
|
|
| 1 |
+
# ββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
# FILE: wordlist.py
|
| 3 |
+
# ββββββββββββββββββββββββββββββββββββββββ
|
| 4 |
+
|
| 5 |
import asyncio
|
| 6 |
import urllib.request
|
|
|
|
| 7 |
import config
|
| 8 |
|
| 9 |
+
def _download_and_filter() -> list[str]:
|
| 10 |
+
try:
|
| 11 |
+
req = urllib.request.Request(config.WORDLIST_URL)
|
| 12 |
+
with urllib.request.urlopen(req) as response:
|
| 13 |
+
data = response.read().decode('utf-8')
|
| 14 |
+
|
| 15 |
+
words = []
|
| 16 |
+
for line in data.splitlines():
|
| 17 |
+
line = line.strip()
|
| 18 |
+
if not line:
|
| 19 |
+
continue
|
| 20 |
+
parts = line.split('\t')
|
| 21 |
+
if not parts:
|
| 22 |
+
continue
|
| 23 |
+
w = parts[0].strip().lower()
|
| 24 |
+
if w.isalpha() and config.MIN_WORD_LEN <= len(w) <= config.MAX_WORD_LEN:
|
| 25 |
+
words.append(w)
|
| 26 |
+
return words
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print(f"Error fetching wordlist: {e}")
|
| 29 |
+
return []
|
| 30 |
|
| 31 |
+
async def fetch_word_list() -> list[str]:
|
| 32 |
+
loop = asyncio.get_running_loop()
|
| 33 |
+
return await loop.run_in_executor(None, _download_and_filter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|