forked from kent-lee/deviantart-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (51 loc) · 1.63 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
from argparse import ArgumentParser
import sys, os, time
from lib.deviantart import DeviantArtAPI
from lib.config import Config
from lib import utils, cmd
import re
def download_users(api, config, option, **kwargs):
start_time = time.time()
if option == 'artwork':
result = api.save_users_artworks(config.users, config.save_dir)
elif option == 'ranking':
result = api.save_ranking_artworks(**kwargs)
duration = time.time() - start_time
size_mb = result['size'] / 1048576
print('\nSUMMARY')
print('---------------------------------')
print(f'time elapsed:\t{duration:.4f} seconds')
print(f'total size:\t{size_mb:.4f} MB')
print(f'total artworks:\t{result["count"]} artworks')
print(f'download speed:\t{(size_mb / duration):.4f} MB/s')
def main():
api = DeviantArtAPI()
args = cmd.main_parser()
config = Config(args.f)
if args.l:
config.print()
if args.s:
config.save_dir = args.s
if args.t:
api.threads = args.t
if args.option == 'artwork':
if args.a:
config.add_users(args.a)
if args.d:
config.delete_users(args.d)
if args.c:
config.clear_users(args.c)
download_users(api, config, args.option)
elif args.option == 'ranking':
params = {
'order': args.order,
'type': args.type,
'content': args.content,
'category': args.category,
'limit': args.n,
'dir_path': config.save_dir
}
download_users(api, config, args.option, **params)
config.update()
if __name__ == "__main__":
main()