From d858c1ca5f0365b000e7ddd114ac050d5229de23 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Fri, 3 Jun 2022 23:42:41 +0200 Subject: [PATCH 1/6] 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"] = [] From 5555b80bc8c39e90309e6edb8bb4f021f5bcc058 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 01:00:08 +0200 Subject: [PATCH 2/6] Removed IDE files from git tracking Removed IDE files from git tracking Removed IDE files from git tracking --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 4 +++- .idea/.gitignore | 3 --- .idea/RedditVideoMakerBot.iml | 14 -------------- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 8 files changed, 3 insertions(+), 42 deletions(-) delete mode 100644 .DS_Store delete mode 100644 .idea/.gitignore delete mode 100644 .idea/RedditVideoMakerBot.iml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index d9fbee9a2d2bee2e47c875e2dc0b7508612c6686..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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{ diff --git a/.gitignore b/.gitignore index b541305..28b6807 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ assets/ .env reddit-bot-351418-5560ebc49cac.json -__pycache__ \ No newline at end of file +__pycache__ +.idea/ +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/RedditVideoMakerBot.iml b/.idea/RedditVideoMakerBot.iml deleted file mode 100644 index 8e5446a..0000000 --- a/.idea/RedditVideoMakerBot.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 653ebc1..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 1fd5644..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From d59fb5bdf28b1158845f094cb25913262e3bea45 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 09:53:23 +0200 Subject: [PATCH 3/6] Changed THREAD to THREAD_LINK inside .env.template --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 9e2218f..c2a2fcf 100644 --- a/.env.template +++ b/.env.template @@ -11,4 +11,4 @@ SUBREDDIT="askReddit" # 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 +THREAD_LINK="" \ No newline at end of file From f51cbbce4d95a3427eb14f22fe59f6135052f5c0 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sun, 5 Jun 2022 11:10:03 +0200 Subject: [PATCH 4/6] The script asks the user for the thread link in the console --- .env.template | 5 ++--- reddit/subreddit.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.env.template b/.env.template index 25936d2..9385e68 100644 --- a/.env.template +++ b/.env.template @@ -12,6 +12,5 @@ SUBREDDIT="askReddit" THEME="" -# Link of the thread -# (e.g. https://www.reddit.com/r/memes/comments/sbr31o/discordggrmemes_the_official_rmemes_discord_server/) -THREAD_LINK="" \ No newline at end of file +#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. +RANDOM_THREAD="no" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c2f6547..b83b0e3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,3 +1,6 @@ +from webbrowser import get + +from click import style from utils.console import print_markdown, print_step, print_substep import praw import random @@ -34,12 +37,12 @@ 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 the user specifies that he doesnt want a random thread, or if he doesn't insert the "RANDOM_THREAD" variable at all, ask the thread link + if not os.getenv("RANDOM_THREAD") or os.getenv("RANDOM_THREAD") == "no": + print_substep("Insert the full thread link:", style="bold green") + thread_link = input() print_step(f"Getting the inserted thread...") - - thread_id = os.getenv("THREAD_LINK").split("/")[6] + thread_id = thread_link.split("/")[6] submission = reddit.submission(thread_id) else: # Otherwise, picks a random thread from the inserted subreddit From aa67002b903bf7db3c7ab933c6e9471481518b68 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sun, 5 Jun 2022 17:15:39 +0200 Subject: [PATCH 5/6] Modified readme and removed a useless line of code --- README.md | 21 +++++++++++---------- reddit/subreddit.py | 3 +-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index dbb0250..f9d8c12 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ All done WITHOUT video editing or asset compiling. Just pure ✨programming magi Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca) [ + @@ -20,13 +21,13 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Disclaimers 🚨 -- This is purely for fun purposes. -- **At the moment**, this repository won't attempt to upload this content through this bot. It will give you a file that you will then have to upload manually. This is for the sake of avoiding any sort of community guideline issues. +- This is purely for fun purposes. +- **At the moment**, this repository won't attempt to upload this content through this bot. It will give you a file that you will then have to upload manually. This is for the sake of avoiding any sort of community guideline issues. ## Requirements -- Python 3.6+ -- Playwright (this should install automatically during installation) +- Python 3.6+ +- Playwright (this should install automatically during installation) ## Installation 👩‍💻 @@ -38,7 +39,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 6. Enjoy 😎 If you want to see more detailed guide, please refer to the official [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). -*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! +\*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! ## Contributing & Ways to improve 📈 @@ -46,8 +47,8 @@ In its current state, this bot does exactly what it needs to do. However, lots o I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute! -- [ ] Allowing users to choose a reddit thread instead of being randomized. -- [ ] Allowing users to choose a background that is picked instead of the Minecraft one. -- [x] Allowing users to choose between any subreddit. -- [ ] Allowing users to change voice. -- [ ] Creating better documentation and adding a command line interface. +- [x] Allowing users to choose a reddit thread instead of being randomized. +- [ ] Allowing users to choose a background that is picked instead of the Minecraft one. +- [x] Allowing users to choose between any subreddit. +- [ ] Allowing users to change voice. +- [ ] Creating better documentation and adding a command line interface. diff --git a/reddit/subreddit.py b/reddit/subreddit.py index e74b8a1..16bbb79 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -39,8 +39,7 @@ def get_subreddit_threads(): print_substep("Insert the full thread link:", style="bold green") thread_link = input() print_step(f"Getting the inserted thread...") - thread_id = thread_link.split("/")[6] - submission = reddit.submission(thread_id) + submission = reddit.submission(url=thread_link) else: # Otherwise, picks a random thread from the inserted subreddit if os.getenv("SUBREDDIT"): From e86c2bce041db04aa0f5971fea0021e5c7568d1e Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Sun, 5 Jun 2022 14:06:51 -0400 Subject: [PATCH 6/6] Removed unused imports. --- reddit/subreddit.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 16bbb79..a518d24 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,10 +1,8 @@ -from webbrowser import get - -from click import style from utils.console import print_markdown, print_step, print_substep from dotenv import load_dotenv import os, random, praw, re + def get_subreddit_threads(): global submission """ @@ -13,7 +11,6 @@ def get_subreddit_threads(): load_dotenv() - if os.getenv("REDDIT_2FA", default="no").casefold() == "yes": print( "\nEnter your two-factor authentication code from your authenticator app.\n" @@ -48,7 +45,11 @@ def get_subreddit_threads(): # ! Prompt the user to enter a subreddit try: subreddit = reddit.subreddit( - re.sub(r"r\/", "", input("What subreddit would you like to pull from? ")) + re.sub( + r"r\/", + "", + input("What subreddit would you like to pull from? "), + ) ) except ValueError: subreddit = reddit.subreddit("askreddit") @@ -64,14 +65,14 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: - if not top_level_comment.stickied: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + if not top_level_comment.stickied: + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) except AttributeError as e: pass