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_ID=""
REDDIT_CLIENT_SECRET="" REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME="" REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
# Valid options are "yes" and "no" for the variable below # Valid options are "yes" and "no" for the variable below
REDDIT_2FA="" 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() load_dotenv()
print_step("Getting AskReddit threads...")
if os.getenv("REDDIT_2FA").lower() == "yes": if os.getenv("REDDIT_2FA").lower() == "yes":
print( print(
@ -35,24 +34,36 @@ def get_subreddit_threads():
username=os.getenv("REDDIT_USERNAME"), username=os.getenv("REDDIT_USERNAME"),
password=passkey, password=passkey,
) )
# If the user inserts a thread link, pick that one
if os.getenv("THREAD_LINK"):
if os.getenv("SUBREDDIT"): print_step(f"Getting the inserted thread...")
subreddit = reddit.subreddit(os.getenv("SUBREDDIT"))
thread_id = os.getenv("THREAD_LINK").split("/")[6]
submission = reddit.submission(thread_id)
else: else:
# ! Prompt the user to enter a subreddit # Otherwise, picks a random thread from the inserted subreddit
try: if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit( subreddit_name = os.getenv("SUBREDDIT")
input("What subreddit would you like to pull from? ") print_step(f"Getting a random thread from r/{subreddit_name}")
) subreddit = reddit.subreddit(subreddit_name)
except ValueError: else:
subreddit = reddit.subreddit("askreddit") # ! Prompt the user to enter a subreddit
print_substep("Subreddit not defined. Using AskReddit.") try:
subreddit = reddit.subreddit(
input("What subreddit would you like to pull from? ")
)
except ValueError:
subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.")
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title} :thumbsup:") print_substep(f"Video will be: {submission.title} :thumbsup:")
try: try:
content["thread_url"] = submission.url content["thread_url"] = submission.url
content["thread_title"] = submission.title content["thread_title"] = submission.title
content["comments"] = [] content["comments"] = []

Loading…
Cancel
Save