Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

Suggestion in Python Project


  • This topic is locked This topic is locked
No replies to this topic

#1 ankitdixit

ankitdixit

  •  Avatar image
  • Members
  • 2 posts
  • OFFLINE
  •  
  • Local time:02:13 AM

Posted 28 July 2022 - 06:33 AM

Hello All, I am working on reddit bot types of project and looking for source code of this project. Have mentioned one source code below, Please check this code and suggest me, Can I take this code or go with other github source? I have taken this reference from here

 

Basically, We all have used Reddit for one purpose or the other. The famous question-answer app can now also have a bot linked to it. The bot will automate comments on the posts based on specified criteria.

  • Pick a subreddit to scan
  • Designate a specific comment to search for
  • Set your bot’s reply
  • Create a config.py file with your Reddit account details and Reddit.py file with the bot requirements
  • Pre-requisites: Python, Praw, and A reddit account
import praw
import config
import time
import os

def bot_login():
    print "Logging in..."
    r = praw.Reddit(username = config.username,
                password = config.password,
                client_id = config.client_id,
                client_secret = config.client_secret,
                user_agent = "The Reddit Commenter v1.0")
    print "Logged in!"

    return r

def run_bot(r, comments_replied_to):
    print "Searching last 1,000 comments"

    for comment in r.subreddit('test').comments(limit=1000):
        if "sample user comment" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
            print "String with \"sample user comment\" found in comment " + comment.id
            comment.reply("Hey, I like your comment!")
            print "Replied to comment " + comment.id

            comments_replied_to.append(comment.id)

            with open ("comments_replied_to.txt", "a") as f:
                f.write(comment.id + "\n")

    print "Search Completed."

    print comments_replied_to

    print "Sleeping for 10 seconds..."
    #Sleep for 10 seconds...        
    time.sleep(10)

def get_saved_comments():

if not os.path.isfile("comments_replied_to.txt"):
        comments_replied_to = []
    else:
        with open("comments_replied_to.txt", "r") as f:
            comments_replied_to = f.read()
            comments_replied_to = comments_replied_to.split("\n")
            comments_replied_to = filter(None, comments_replied_to)

    return comments_replied_to

r = bot_login()
comments_replied_to = get_saved_comments()
print comments_replied_to

while True:
    run_bot(r, comments_replied_to)

Thanks in Advance!



BC AdBot (Login to Remove)

 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users