Remove unzip functiionality
This commit is contained in:
parent
19c7eb37de
commit
36db389e3c
|
@ -8,6 +8,9 @@ from pathlib import Path
|
||||||
import personal_data.csv_import
|
import personal_data.csv_import
|
||||||
import personal_data.main
|
import personal_data.main
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class Result:
|
class Result:
|
||||||
|
@ -25,13 +28,13 @@ def parse_results(response) -> list[Result]:
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for tr in soup.select('table tbody tr'):
|
for tr in soup.select('table tbody tr'):
|
||||||
if tr.get_text().strip() == 'Nothing found.':
|
|
||||||
continue
|
|
||||||
|
|
||||||
cells = tr.select('td')
|
cells = tr.select('td')
|
||||||
|
|
||||||
title = cells[0].get_text().strip()
|
title = cells[0].get_text().strip()
|
||||||
id = cells[0].a['href'].removeprefix('viewsimfile.php?simfileid=')
|
link = cells[0].a
|
||||||
|
if link is None:
|
||||||
|
continue
|
||||||
|
id = link['href'].removeprefix('viewsimfile.php?simfileid=')
|
||||||
levels = cells[1].get_text().strip()
|
levels = cells[1].get_text().strip()
|
||||||
results.append(Result(title , int(id), levels))
|
results.append(Result(title , int(id), levels))
|
||||||
return results
|
return results
|
||||||
|
@ -52,6 +55,7 @@ def search_for_song(song_data) -> Result | None:
|
||||||
})
|
})
|
||||||
if results := parse_results(response):
|
if results := parse_results(response):
|
||||||
return results[0]
|
return results[0]
|
||||||
|
logger.warning('No results for %s', song_data['song.name_eng'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def download_song(song_data, output_dir: Path):
|
def download_song(song_data, output_dir: Path):
|
||||||
|
@ -60,14 +64,16 @@ def download_song(song_data, output_dir: Path):
|
||||||
return
|
return
|
||||||
|
|
||||||
path_zip = output_dir/f'zenius-{song_result.id}-{song_result.title}.zip'
|
path_zip = output_dir/f'zenius-{song_result.id}-{song_result.title}.zip'
|
||||||
|
if path_zip.exists():
|
||||||
|
logger.warning('Skipping existing file')
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.warning('Downloading to %s', path_zip)
|
||||||
|
|
||||||
url = f'https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid={song_result.id}'
|
url = f'https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid={song_result.id}'
|
||||||
|
|
||||||
cmd = ['curl', '-L', '--fail', url, '-o', path_zip]
|
cmd = ['curl', '-L', '--fail', url, '-o', path_zip]
|
||||||
result = subprocess.run(cmd, check=True, capture_output=True)
|
subprocess.run(cmd, check=True, capture_output=True)
|
||||||
|
|
||||||
with zipfile.ZipFile(path_zip, 'r') as zip_ref:
|
|
||||||
zip_ref.extractall(output_dir)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
csv_path = Path('./output/myanimelist_songs.csv')
|
csv_path = Path('./output/myanimelist_songs.csv')
|
||||||
|
@ -76,6 +82,7 @@ def main():
|
||||||
|
|
||||||
songs = personal_data.csv_import.load_csv_file(csv_path)
|
songs = personal_data.csv_import.load_csv_file(csv_path)
|
||||||
for song in songs:
|
for song in songs:
|
||||||
|
logger.warning('Trying to download %s', song['song.name_eng'])
|
||||||
download_song(song, output_path)
|
download_song(song, output_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user