-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (49 loc) · 1.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
This module provides functionality to read URLs from a file, process
them for downloading Hanime content, and write results back to the file.
Usage:
To use this module, ensure that 'URLs.txt' is present in the same
directory as this script. Execute the script to read URLs, download
content, and clear the URL list upon completion.
"""
from hanime_downloader import process_hanime_download
FILE = 'URLs.txt'
def read_file(filename):
"""
Reads the contents of a file and returns a list of its lines.
Args:
filename (str): The path to the file to be read.
Returns:
list: A list of lines from the file, with newline characters removed.
"""
with open(filename, 'r', encoding='utf-8') as file:
return file.read().splitlines()
def write_file(filename, content=''):
"""
Writes content to a specified file. If content is not provided, the file is
cleared.
Args:
filename (str): The path to the file to be written to.
content (str, optional): The content to write to the file. Defaults to
an empty string.
"""
with open(filename, 'w', encoding='utf-8') as file:
file.write(content)
def process_urls(urls):
"""
Validates and downloads items for a list of URLs.
Args:
urls (list): A list of URLs to process.
"""
for url in urls:
process_hanime_download(url)
def main():
"""
Main function to execute the script.
Reads URLs from a file, processes them, and clears the file at the end.
"""
urls = read_file(FILE)
process_urls(urls)
write_file(FILE)
if __name__ == '__main__':
main()