Skip to content

Commit 625d126

Browse files
authored
Add files via upload
1 parent edb437a commit 625d126

10 files changed

+125
-0
lines changed

botsRgood.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://chatbotslife.com/how-to-build-a-reddit-bot-c890efb330c1

comments.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#submissions.comments
2+
3+
#need a submission object and then can scan that objects comments after
4+

infinite_loops.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if you have an infinite loop in your code
2+
keep pressing ctrl-c to force stop the execution
3+
4+
Dont want to spam post stuff to the reddit board
5+

linux_setup.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Both Python2 and Python3 are installed on most Linux distros by default
2+
3+
Do all of this in a terminal.
4+
5+
PIP is not usually installed on Linux
6+
sudo apt install python3-pip
7+
8+
pip3 uses the python3 installer
9+
sudo pip3 install praw
10+
11+
test to see is praw installed
12+
python3
13+
14+
>> import praw
15+
16+
if no error message comes up then it is installed.

posts_replied_to.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dlk3nt

praw.ini

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
[bot1]
3+
client_id = cccccc
4+
client_secret = ccccc
5+
password = cccc
6+
username = cccc
7+
user_agent=skynet001
8+
9+
10+
11+

reddit_account.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Creating an account or using your old account.
2+
3+
Go to our subreddit r/ulcompsoc
4+
5+
registering for dev credentials
6+
7+
redirect_url = 127.0.0.1
8+
9+
This is not important as you are running a script from the terminal.
10+
11+
Explaining oauth is another challenge in itself.

reply.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/python
2+
import praw
3+
import pdb
4+
import re
5+
import os
6+
#what are the 3 other imports needed for.
7+
8+
reddit = praw.Reddit('bot1')
9+
10+
subreddit = reddit.subreddit("ulcompsoc")
11+
12+
if not os.path.isfile("posts_replied_to.txt"):
13+
posts_replied_to = []
14+
else:
15+
with open("posts_replied_to.txt") as f:
16+
posts_replied_to = f.read()
17+
posts_replied_to = posts_replied_to.split("\n")
18+
posts_replied_to = list(filter(None, posts_replied_to))
19+
20+
subreddit = reddit.subreddit("ulcompsoc")
21+
for submission in subreddit.hot(limit=2):
22+
if submission.id not in posts_replied_to:
23+
if re.search("compsoc loves python", submission.title, re.IGNORECASE):
24+
submission.reply("Skynet0001 says Hello!")
25+
print("Bot replying to : ", submission.title)
26+
posts_replied_to.append(submission.id)
27+
28+
with open("posts_replied_to.txt", "w") as f:
29+
for post_id in posts_replied_to:
30+
f.write(post_id + "\n")
31+
32+

running_scripts.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
3+
naviagate to the directory that you want in the terminal
4+
5+
if on windows type > dir
6+
if on GNU/Linux ;^) or Mac type > ls
7+
8+
to see where the terminal is currently pointed.
9+
10+
To navigate to other directories type > cd the_folder
11+
so if you are in home and want to move to Documents
12+
cd Documents
13+
14+
When you are in the directory with your script. Type
15+
16+
python3 your_script.py
17+
18+
experiment with using python your_script.py and guess why it does work or it doesnt work.
19+
20+
This depends on if python2 is also installed.
21+
If its not python on its own will work
22+
23+
do both python and python3 have the same result?
24+
25+
26+
27+
===
28+
29+
Windows - open the python script in idle
30+
The above steps would have worked for you but theres an alternative
31+
To open idle, press the windows key and type idle open and code from there
32+
To run press f5

scrape.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/python
2+
import praw
3+
4+
reddit = praw.Reddit('bot1')
5+
6+
subreddit = reddit.subreddit("ulcompsoc")
7+
8+
for submission in subreddit.hot(limit=2):
9+
print("Title: ", submission.title)
10+
print("Text: ", submission.selftext)
11+
print("Score: ", submission.score)
12+
print("---------------------------------\n")

0 commit comments

Comments
 (0)