Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Why does this code doesn't work ?

Code
import praw

# #---# Variables #---# #
client_id = ""
client_secret = ""
password = ""
user_agent = ""
username = ""
message_to_reply = "Thank you for the message."
# #-------------------# #

reddit = praw.Reddit(client_id=client_id, client_secret=client_secret,
                     password=password, user_agent=user_agent,
                     username=username)

print("Started.")

while True:
    for message in reddit.inbox.unread(limit=None):
        message.reply(message_to_reply)
        message.mark_read()


What i should edit except account username and password for this code to work and reply on the messages ? What is wrong with this code ?
(Mar 3, 2019 09:24 AM)kookur Wrote:  
Code
import praw

# #---# Variables #---# #
client_id = ""
client_secret = ""
password = ""
user_agent = ""
username = ""
message_to_reply = "Thank you for the message."
# #-------------------# #

reddit = praw.Reddit(client_id=client_id, client_secret=client_secret,
                    password=password, user_agent=user_agent,
                    username=username)

print("Started.")

while True:
   for message in reddit.inbox.unread(limit=None):
       message.reply(message_to_reply)
       message.mark_read()


What i should edit except account username and password for this code to work and reply on the messages ?  What is wrong with this code ?
I have very limited knowledge with Python, but why are you using a continuous loop (while True) and then followed by for loop? Are you trying to keep this code running forever?
Je t'aime
[Image: fpZ5a5g.png]
(Apr 22, 2022 04:39 PM)-Scrub Wrote:  Jokes on you, I'm not smart enough to know what he's talking about.
Add reddit.inbox.mark_read(unread_messages) outside the for loop then a conditional statement stating that if all messages are marked as read, break the while loop as Nachfolger stated
*Approved for UB3R like 5 years ago*
(Mar 3, 2019 11:41 AM)Nachfolger Wrote:  I have very limited knowledge with Python, but why are you using a continuous loop (while True) and then followed by for loop? Are you trying to keep this code running forever?

I think he might want to keep it running in the background to automatically respond to incoming messages. Not sure tho.

@OP: Can you explain what the code is suppose to do and more importantly what exactly isn't working? If you don't want the program to keep running forever, get rid of the while loop entirely.
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn
(Mar 4, 2019 02:26 AM)lockhead Wrote:  I think he might want to keep it running in the background to automatically respond to incoming messages. Not sure tho.

@OP: Can you explain what the code is suppose to do and more importantly what exactly isn't working? If you don't want the program to keep running forever, get rid of the while loop entirely.

Doesn't reddit let you listen to events like Twitter api?

Doing a while true is going to lock the cpu.
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
This in variables
Code
unread_messages = []
And this in ur while loop
Code
for item in reddit.inbox.unread(limit=None):
   if isinstance(item, Message):
       unread_messages.append(item)
reply = reddit.inbox(unread_messages)
reply.reply(message_to_reply)
reddit.inbox.mark_read(unread_messages)
I thought it should work


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by HardStoNJul 19, 2020 05:14 AM 7 288 Jul 19, 2020 05:14 AM
Last Post: DanketyDank
[C] by Sir BillyAug 26, 2019 06:33 PM 1 148 Aug 26, 2019 06:33 PM
Last Post: YouthInAsia
[Python] by caijadJul 20, 2018 03:50 AM 7 188 Jul 20, 2018 03:50 AM
Last Post: Smileツ