Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create setup TUI and improve overall UX #125

Merged
merged 27 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f4b7ff7
.gitignore: Add pycaches
blockarchitech Jun 1, 2022
39a6918
Create setup TUI and improve overall UX
blockarchitech Jun 2, 2022
74363f0
README Updates
blockarchitech Jun 2, 2022
1e42fd2
make readme look better
blockarchitech Jun 2, 2022
3c4eac4
maybe a *little* bit better
blockarchitech Jun 2, 2022
e4ed7aa
Clarification for setup.
blockarchitech Jun 2, 2022
e03f529
README: got some of the stages mixed up.
blockarchitech Jun 2, 2022
16664e0
Reviews: Various Changes
blockarchitech Jun 2, 2022
52302cc
gitignore - new files
blockarchitech Jun 2, 2022
44edf4a
Merge branch 'master' of https://github.com/elebumm/RedditVideoMakerB…
blockarchitech Jun 2, 2022
9c3e932
Merge branch 'elebumm-master'
blockarchitech Jun 2, 2022
4506339
ACCEPT: Incoming Change (main.py)
blockarchitech Jun 2, 2022
d8def59
ACCEPT: Incoming change. (README.md)
blockarchitech Jun 2, 2022
b1c9872
README: Automatic install
blockarchitech Jun 2, 2022
3b26c0e
main.py: Add REDDIT_2FA to env variable check.
blockarchitech Jun 2, 2022
e18bb12
REQUIREMENTS.TXT: Accept Incoming Change
blockarchitech Jun 2, 2022
51d561b
Removed an extra line in main.py; added 2fa to setup.py
blockarchitech Jun 2, 2022
6b8b966
Accept Incoming Change
blockarchitech Jun 2, 2022
b11b804
Merge branch 'master' into master
blockarchitech Jun 3, 2022
20217be
resolve gitignore conflict
blockarchitech Jun 3, 2022
f4121ab
Merge branch 'master' into master
blockarchitech Jun 3, 2022
7ab4ced
Merge branch 'master' into master
blockarchitech Jun 4, 2022
6b747af
Merge branch 'master' into master
blockarchitech Jun 5, 2022
49da171
Add OPACITY, SUBREDDIT, and THEME.
blockarchitech Jun 5, 2022
c6ab604
Fixed a couple of issues..
elebumm Jun 5, 2022
f011a41
Merge branch 'master' into master
callumio Jun 5, 2022
3693dce
Update main.py
blockarchitech Jun 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
assets/
reddit/__pycache__/
utils/__pycache__/
.env
reddit-bot-351418-5560ebc49cac.json
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
## Installation 👩‍💻

1. Clone this repository
2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files.
3. Run `pip3 install -r requirements.txt`
4. Run `python3 main.py`
5. ...
2. Run `pip3 install -r requirements.txt`
3.
3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process.

3b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files.

4. (only if you did manual setup) Run `python3 main.py`
6. Enjoy 😎

## Contributing & Ways to improve 📈
Expand Down
48 changes: 47 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,61 @@
# Main
from utils.console import print_markdown
from utils.console import print_step
from utils.console import print_substep
from rich.console import Console
import time
import os
from reddit.askreddit import get_askreddit_threads
from video_creation.background import download_background, chop_background_video
from video_creation.voices import save_text_to_mp3
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.final_video import make_final_video

from utils.loader import Loader
from dotenv import load_dotenv
console = Console()
print_markdown(
"### Thanks for using this tool! 😊 [Feel free to contribute to this project on GitHub!](https://lewismenelaws.com). If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue."
)

"""

Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard.
If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard.

"""

client_id=os.getenv("REDDIT_CLIENT_ID")
client_secret=os.getenv("REDDIT_CLIENT_SECRET")
username=os.getenv("REDDIT_USERNAME")
password=os.getenv("REDDIT_PASSWORD")

console.log("[bold green]Checking environment variables...")
time.sleep(1)

if client_id == "" or client_secret == "" or username == "" or password == "":
blockarchitech marked this conversation as resolved.
Show resolved Hide resolved

console.log("[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up.")
time.sleep(0.5)
console.log("[red]We can also launch the easy setup wizard. type yes to launch it, or no to quit the program.")
setup_ask = input("Launch setup wizard? > ")
if setup_ask=="yes":
console.log("[bold green]Here goes nothing! Launching setup wizard...")
time.sleep(0.5)
os.system("python3 setup.py")
else:
if setup_ask=="no":
console.print("[red]Exiting...")
time.sleep(0.5)
exit()
else:
console.print("[red]I don't understand that. Exiting...")
time.sleep(0.5)
exit()


exit()

console.log("[bold green]Enviroment Variables are set! Continuing...")
time.sleep(3)


Expand Down
7 changes: 5 additions & 2 deletions reddit/askreddit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from rich import Console
from utils.console import print_markdown, print_step, print_substep
import praw
import random
from dotenv import load_dotenv
import os

console = Console()

def get_askreddit_threads():
"""
Expand All @@ -14,6 +15,7 @@ def get_askreddit_threads():

content = {}
load_dotenv()
console.log("Logging in to reddit...")
reddit = praw.Reddit(
client_id=os.getenv("REDDIT_CLIENT_ID"),
client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
Expand All @@ -25,6 +27,7 @@ def get_askreddit_threads():
threads = askreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title} :thumbsup:")
console.log("Getting video comments...")
try:

content["thread_url"] = submission.url
Expand All @@ -43,4 +46,4 @@ def get_askreddit_threads():
except AttributeError as e:
pass
print_substep("Received AskReddit threads Successfully.", style="bold green")
return content
return content
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rich==12.4.4
six==1.16.0
toml==0.10.1
tqdm==4.64.0
typed-ast==1.4.1
typed-ast==1.5.4 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three.
typing_extensions==4.2.0
update-checker==0.18.0
urllib3==1.26.9
Expand Down
96 changes: 96 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""

Setup Script for RedditVideoMakerBot

"""

# Imports
import os
import time
from utils.console import print_markdown
from utils.console import print_step
from utils.console import print_substep
from rich.console import Console
from utils.loader import Loader
console = Console()

# These lines ensure the user:
# - knows they are in setup mode
# - knows that they are about to erase any other setup files/data.

print_step("Setup Assistant")

print_markdown(
"### You're in the setup wizard. Ensure you're supposed to be here, then type yes to continue. If you're not sure, type no to quit."
)

# This Input is used to ensure the user is sure they want to continue.
ensureSetupIsRequired = input("Are you sure you want to continue? > ")
if ensureSetupIsRequired != "yes":
console.print("[red]Exiting...")
time.sleep(0.5)
exit()
else:
# Again, let them know they are about to erase all other setup data.
console.print("[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no")
overwriteSettings = input("Are you sure you want to continue? > ")
blockarchitech marked this conversation as resolved.
Show resolved Hide resolved
if overwriteSettings != "yes":
console.print("[red]Abort mission! Exiting...")
time.sleep(0.5)
exit()
else:
# Once they confirm, move on with the script.
console.print("[bold green]Alright! Let's get started!")
time.sleep(1)

console.log("Ensure you have the following ready to enter:")
console.log("[bold green]Reddit Client ID")
console.log("[bold green]Reddit Client Secret")
console.log("[bold green]Reddit Username")
console.log("[bold green]Reddit Password")
time.sleep(0.5)
console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.")
console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.")
confirmUserHasCredentials = input("Are you sure you have the credentials? > ")
if confirmUserHasCredentials != "yes":
console.print("[red]I don't understand that.")
console.print("[red]Exiting...")
exit()
else:
console.print("[bold green]Alright! Let's get started!")
time.sleep(1)

"""

Begin the setup process.

"""

console.log("Enter your credentials now.")
cliID = input("Client ID > ")
cliSec = input("Client Secret > ")
user = input("Username > ")
passw = input("Password > ")
console.log("Attempting to save your credentials...")
loader = Loader("Saving Credentials...", "Done!").start()
# you can also put a while loop here, e.g. while VideoIsBeingMade == True: ...
time.sleep(0.5)
console.log("Removing old .env file...")
os.remove(".env")
time.sleep(0.5)
console.log("Creating new .env file...")
with open('.env', 'a') as f:
blockarchitech marked this conversation as resolved.
Show resolved Hide resolved
f.write(f'REDDIT_CLIENT_ID="{cliID}"\n')
time.sleep(0.5)
f.write(f'REDDIT_CLIENT_SECRET="{cliSec}"\n')
time.sleep(0.5)
f.write(f'REDDIT_USERNAME="{user}"\n')
time.sleep(0.5)
f.write(f'REDDIT_PASSWORD="{passw}"\n')

loader.stop()

console.log("[bold green]Setup Complete! Returning...")

# Post-Setup: send message and try to run main.py again.
os.system("python3 main.py")
blockarchitech marked this conversation as resolved.
Show resolved Hide resolved
53 changes: 53 additions & 0 deletions utils/loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""

Okay, have to admit. This code is from StackOverflow. It's so efficient, that it's probably the best way to do it.
Although, it is edited to use less threads.

"""
from itertools import cycle
from shutil import get_terminal_size
from threading import Thread
from time import sleep


class Loader:
def __init__(self, desc="Loading...", end="Done!", timeout=0.1):
"""
A loader-like context manager

Args:
desc (str, optional): The loader's description. Defaults to "Loading...".
end (str, optional): Final print. Defaults to "Done!".
timeout (float, optional): Sleep time between prints. Defaults to 0.1.
"""
self.desc = desc
self.end = end
self.timeout = timeout

self._thread = Thread(target=self._animate, daemon=True)
self.steps = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"]
self.done = False

def start(self):
self._thread.start()
return self

def _animate(self):
for c in cycle(self.steps):
if self.done:
break
print(f"\r{self.desc} {c}", flush=True, end="")
sleep(self.timeout)

def __enter__(self):
self.start()

def stop(self):
self.done = True
cols = get_terminal_size((80, 20)).columns
print("\r" + " " * cols, end="", flush=True)
print(f"\r{self.end}", flush=True)

def __exit__(self, exc_type, exc_value, tb):
# handle exceptions with those variables ^
self.stop()