Allowing the user to choose a thread by inserting the thread link
This commit is contained in:
1 parent
6fc5d2a737
commit
d858c1ca5f
9 files changed
+71
-15
No files matched your search
+5
-1
@@ -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=""
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
+14
@@ -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>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
Generated
+4
@@ -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>
|
||||
Generated
+8
@@ -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>
|
||||
Generated
+6
@@ -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>
|
||||
+25
-14
@@ -13,7 +13,6 @@ def get_subreddit_threads():
|
||||
|
||||
load_dotenv()
|
||||
|
||||
print_step("Getting AskReddit threads...")
|
||||
|
||||
if os.getenv("REDDIT_2FA").lower() == "yes":
|
||||
print(
|
||||
@@ -35,24 +34,36 @@ 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"):
|
||||
|
||||
if os.getenv("SUBREDDIT"):
|
||||
subreddit = reddit.subreddit(os.getenv("SUBREDDIT"))
|
||||
print_step(f"Getting the inserted thread...")
|
||||
|
||||
thread_id = os.getenv("THREAD_LINK").split("/")[6]
|
||||
submission = reddit.submission(thread_id)
|
||||
else:
|
||||
# ! Prompt the user to enter a subreddit
|
||||
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.")
|
||||
# Otherwise, picks a random thread from the inserted subreddit
|
||||
if 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:
|
||||
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:")
|
||||
try:
|
||||
|
||||
content["thread_url"] = submission.url
|
||||
content["thread_title"] = submission.title
|
||||
content["comments"] = []
|
||||
|
||||
Reference in new issue
Block a user