Feat: download in main file

This commit is contained in:
2025-01-06 23:18:33 +03:00
parent fa05f39b24
commit 5b68cd7c01
7 changed files with 74 additions and 4 deletions

28
main.py
View File

@@ -1,9 +1,15 @@
import csv
import sys
import time
from concurrent.futures import ThreadPoolExecutor
from enum import Enum
from typing import List
from anixarttierlist import group_by_common_part
import numpy as np
from tqdm import tqdm
from anixarttierlist import (add_url_to_file, download_image, get_image_url,
prepare)
class TableColumns(Enum):
@@ -13,6 +19,21 @@ class TableColumns(Enum):
ALT_NAME = 3
def get_urls(names: List[List[str]]) -> List[str]:
for group in tqdm(names):
for name in tqdm(group):
url = get_image_url(name)
if url != '':
add_url_to_file(url)
download_image(url, name)
time.sleep(0.68)
def download_imgs(urls: List[str]):
with ThreadPoolExecutor(max_workers=5) as executor:
executor.map(download_image, urls)
def main(file: str):
anime_list_before_group: List[str] = []
with open(file, 'r', newline='') as csvfile:
@@ -24,7 +45,9 @@ def main(file: str):
anime_list_before_group.append(
row[TableColumns.JAP_NAME.value])
# anime_list: List[str] = group_by_common_part(anime_list_before_group) # TODO: find the best algorithm for that
print(anime_list_before_group)
np_anime_list = np.array(anime_list_before_group)
res = np.array_split(np_anime_list, np.ceil(len(np_anime_list) / 5))
get_urls(res)
if __name__ == '__main__':
@@ -32,4 +55,5 @@ if __name__ == '__main__':
if len(argv) != 2:
print('Error! Run program with file name: \'python main.py file.csv\'')
sys.exit(1)
prepare()
sys.exit(main(argv[1]))