-
Notifications
You must be signed in to change notification settings - Fork 1
/
crawlddit.py
58 lines (41 loc) · 1.61 KB
/
crawlddit.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
#!/usr/bin/python3
from argparse import ArgumentParser
from utils.downloader import Downloader
from domainparsers.reddit import Reddit
__author__ = 'petarGitNik'
__copyright__ = 'Copyright (c) 2017 petarGitNik [email protected]'
__version__ = 'v0.1.0'
__license__ = 'MIT'
__email__ = '[email protected]'
__status__ = 'Development'
def parse_arguments():
"""
Parse input arguments of the program. Two positional arguments are
mandatory: 'URL' and destination 'directory'. 'verbose' is optional.
Example:
crawlddit.py -v https://www.reddit.com/r/MemeEconomy/ ./memes
For more information type:
crawlddit.py --help
"""
parser = ArgumentParser(description='reddit /r downloader')
parser.add_argument('-v', '--verbose',
help='display download progress and information',
action='store_true')
parser.add_argument('-p', help='crawl P number of pages', type=int)
parser.add_argument('URL', help='source link')
parser.add_argument('directory', help='destination directory')
args = parser.parse_args()
return (args.verbose, args.p, args.URL, args.directory)
if __name__ == '__main__':
verbose, pages, url, destination = parse_arguments()
if verbose: print('Fetching available links...')
reddit = Reddit(url, pages)
reddit.get_all_posts()
images = reddit.images
if verbose: print(
'{}/{} images available for download.'.format(
reddit.count_downloadable_images() , len(images)
)
)
downloader = Downloader(reddit, destination, verbose)
downloader.download_files()