From d858c1ca5f0365b000e7ddd114ac050d5229de23 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Fri, 3 Jun 2022 23:42:41 +0200 Subject: [PATCH] Allowing the user to choose a thread by inserting the thread link --- .DS_Store | Bin 0 -> 6148 bytes .env.template | 6 ++- .idea/.gitignore | 3 ++ .idea/RedditVideoMakerBot.iml | 14 +++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ reddit/subreddit.py | 39 +++++++++++------- 9 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/.gitignore create mode 100644 .idea/RedditVideoMakerBot.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d9fbee9a2d2bee2e47c875e2dc0b7508612c6686 GIT binary patch literal 6148 zcmeHK%}T>S5Z<-5Nhm@N3OxqA7OX+k;w8lT0!H+pQWFw17_+5G?V%KM))(?gd>&_Z zH-})rn~0q$yWi~m>}Edb{xHV4zlaYRvl(M1G(?U{i=esHwWWg*xtyb9MYJqtQ6{36 ziTU6hzhG7|f<34y2%b*O)Md63@TO3^pkwvv0 zM%QVwoZ7qRA}_-J%3)ciHMIw;m3urII_~Modg!di zF6c*NcfGdEz5Ro;%jt9Wl8ZM*BnQr=>}agv9h62*ufaUeME(f&I;V~$BnF59Vt^Rf zJO=bxVD>k!bgGybAO?P50QUz68ltDMQYg0$=km;3^&Lj*jy*Rti-*<8oz~N3UEzUbtKx?2Zg)+*3$BF+dD78R)2?jpzRb{AF4n z`OOp>5d*})KVyJ*C&9#rqV(DNtvozy9cT~GP%y4S1qAfQB>)Dvj|`+!`5n|D&eK>a V#97cT(*fxsAPJ$482AMSz5umqOj-Z{ literal 0 HcmV?d00001 diff --git a/.env.template b/.env.template index f00c2ac..9e2218f 100644 --- a/.env.template +++ b/.env.template @@ -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="" \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/RedditVideoMakerBot.iml b/.idea/RedditVideoMakerBot.iml new file mode 100644 index 0000000..8e5446a --- /dev/null +++ b/.idea/RedditVideoMakerBot.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..653ebc1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1fd5644 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..c2f6547 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -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"] = []