This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
64 lines (46 loc) · 1.94 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
64
"""
This script creates CLI to start the program
Command to run this script:
$python3 main.py 'https://www.scoopwhoop.com/
entertainment/memes-from-dd-ramayan/' 5
$python3 main.py 'https://www.scoopwhoop.com/
entertainment/memes-from-dd-ramayan/'
For more help: python3 main.py -h
"""
import argparse
import logging
import os
from error.stampifier_error import StampifierError
from stampifier import Stampifier
STAMP_DIRECTORY = 'output/'
HTML_EXTENSION = '.html'
LOGGER = logging.getLogger(__name__)
def get_user_input():
"""This method implements Command Line Interface"""
parser = argparse.ArgumentParser(description='Stampify the webpage')
parser.add_argument('url', type=str, nargs=1,
help='An URL of the webpage to stampify.')
parser.add_argument('page_count', type=int, nargs='?', default=8,
help='Maximum number of stamp pages to generate.')
parser.add_argument('-enable_animations', dest='enable_animations',
action='store_const', const=True, default=False,
help='To enable animations')
args = parser.parse_args()
return args.url[0], args.page_count, args.enable_animations
if __name__ == '__main__':
_url, maximum_pages, _enable_animations = get_user_input()
_stampifier = Stampifier(_url, maximum_pages, _enable_animations)
try:
stampifier_output = _stampifier.stampify()
stamp_file = stampifier_output.stamp_title.replace(' ', '_') \
+ HTML_EXTENSION
if stampifier_output.stamp_html:
# Save the generated_stamp to file
os.makedirs(STAMP_DIRECTORY, exist_ok=True)
f = open(STAMP_DIRECTORY + stamp_file, 'w')
f.write(stampifier_output.stamp_html)
f.close()
except StampifierError as err:
LOGGER.debug(err.message)
except (IOError, OSError) as err:
LOGGER.debug(err)