Skip to content

Commit 1a266dd

Browse files
authored
Merge pull request #9 from rajtilakjee/implement/typer
Modify main.py to introduce Typer
2 parents fff46f2 + 8a54998 commit 1a266dd

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pytesseract
66
numpy
77
pillow
88
python-dotenv
9+
typer
File renamed without changes.

src/main.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from __future__ import annotations
22

33
import os
4+
from typing import Annotated
5+
from typing import Optional
46

7+
import typer
58
from dotenv import load_dotenv
69
from utils.blogger import Blogger
710
from utils.downloader import Downloader
@@ -15,15 +18,38 @@
1518
load_dotenv()
1619
api_key = os.getenv("GEMMA_API_KEY")
1720

21+
__version__ = "2.0.0"
1822

19-
if __name__ == "__main__":
20-
url = input("Enter YouTube URL: ")
21-
path_to_tesseract = input(
22-
"Please enter the path where Tesseract is installed in your system: ",
23-
)
23+
24+
def version_callback(value: bool):
25+
if value:
26+
print(f"Simone CLI Version: {__version__}")
27+
raise typer.Exit()
28+
29+
30+
def main(
31+
url: Annotated[
32+
str,
33+
typer.Option(
34+
help="URL of the YouTube video. Should be within quotes.",
35+
rich_help_panel="Customization and Utils",
36+
),
37+
],
38+
path: Annotated[
39+
str,
40+
typer.Option(
41+
help="Path where Tesseract is installed in your system. Should be within quotes.",
42+
rich_help_panel="Customization and Utils",
43+
),
44+
],
45+
version: Annotated[
46+
Optional[bool],
47+
typer.Option("--version", callback=version_callback),
48+
] = None,
49+
):
2450

2551
print("Downloading audio and video...")
26-
downloads = Downloader(url)
52+
downloads = Downloader(f"{url}")
2753
downloads.audio()
2854
downloads.video()
2955

@@ -43,7 +69,7 @@
4369
frames = Framer("video.mp4")
4470
frame = frames.get_video_frames()
4571

46-
scores = Scorer(frame, keyword, path_to_tesseract)
72+
scores = Scorer(frame, keyword, f"{path}")
4773
score = scores.score_frames()
4874

4975
print("Saving screenshots...")
@@ -57,3 +83,7 @@
5783
os.remove("video.mp4")
5884

5985
print("Blog post and 3 screenshots have been generated!")
86+
87+
88+
if __name__ == "__main__":
89+
typer.run(main)

0 commit comments

Comments
 (0)