Allowing the user to choose a thread by inserting the thread link

pull/238/head
Domiziano Scarcelli 3 years ago
parent 6fc5d2a737
commit d858c1ca5f

BIN
.DS_Store vendored

Binary file not shown.

@ -1,10 +1,14 @@
REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME=""
REDDIT_PASSWORD=""
# Valid options are "yes" and "no" for the variable below
REDDIT_2FA=""
SUBREDDIT="askReddit"
SUBREDDIT=""
# Link of the thread
# (e.g. https://www.reddit.com/r/memes/comments/sbr31o/discordggrmemes_the_official_rmemes_discord_server/)
THREAD=""

3
.idea/.gitignore vendored

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (RedditVideoMakerBot)" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/RedditVideoMakerBot.iml" filepath="$PROJECT_DIR$/.idea/RedditVideoMakerBot.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -13,7 +13,6 @@ def get_subreddit_threads():
load_dotenv()
print_step("Getting AskReddit threads...")
if os.getenv("REDDIT_2FA").lower() == "yes":
print(
@ -35,9 +34,19 @@ def get_subreddit_threads():
username=os.getenv("REDDIT_USERNAME"),
password=passkey,
)
# If the user inserts a thread link, pick that one
if os.getenv("THREAD_LINK"):
print_step(f"Getting the inserted thread...")
thread_id = os.getenv("THREAD_LINK").split("/")[6]
submission = reddit.submission(thread_id)
else:
# Otherwise, picks a random thread from the inserted subreddit
if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit(os.getenv("SUBREDDIT"))
subreddit_name = os.getenv("SUBREDDIT")
print_step(f"Getting a random thread from r/{subreddit_name}")
subreddit = reddit.subreddit(subreddit_name)
else:
# ! Prompt the user to enter a subreddit
try:
@ -50,9 +59,11 @@ def get_subreddit_threads():
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title} :thumbsup:")
try:
content["thread_url"] = submission.url
content["thread_title"] = submission.title
content["comments"] = []

Loading…
Cancel
Save