-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (56 loc) · 1.55 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
65
66
67
68
69
70
# build-in modules
import os
# third-party modules
import click
from dotenv import load_dotenv
from InquirerPy import inquirer
from src import controller
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
@click.command()
@click.option(
'--url',
'-u',
help='Medium.com URL',
multiple=True,
default=[]
)
@click.option(
'--md',
'-m',
help='Save as Markdown',
is_flag=True,
default=False
)
@click.option(
'--pdf',
'-p',
help='Save as PDF',
is_flag=True,
default=False
)
def main(url: list[str], md, pdf):
"""
This is a CLI tool that scrapes an article
from medium.com and saves it as a PDF or
Markdown file.
"""
urls = list(url)
if len(url) == 0:
medium_com_url = inquirer.text(message="Enter a medium.com URL:").execute()
urls.append(medium_com_url)
confirm = inquirer.confirm(message="Do you want to add more articles?", default=True).execute()
while confirm:
new_medium_com_url = inquirer.text(message="Enter a medium.com URL:").execute()
urls.append(new_medium_com_url)
confirm = inquirer.confirm(message="Do you want to add more articles?", default=True).execute()
extensions = ""
if md:
extensions = "md"
elif pdf:
extensions = "pdf"
else:
extensions = inquirer.select(message="Choose a file format:", choices=['pdf', 'md']).execute()
controller.content_bot(urls, extensions, OPENAI_API_KEY)
if __name__ == '__main__':
main(url=[], md=False, pdf=False)