I am trying to follow reddit u/busterroni's video on how to make a reddit bot, but while his program runs fine, mine keeps getting hung up on "filename" on the line below that says...
usernames = get_usernames(filename)
...under main(). Can anyone tell me what the issue is? BTW I am at 12:11 in the video in case that helps at all.
import praw
import sys
def main():
reddit = authenticate()
usernames = get_usernames(filename) #ERROR
print(usernames)
def authenticate():
print('Authenticating...')
reddit = praw.Reddit(
'notifier',
user_agent="BlueWizard3's joketest v0.1")
print('Authenticated as {}'.format(reddit.user.me()))
return reddit
def get_usernames(filename):
try:
with open(filename, 'r') as f:
usernames = f.read()
usernames = usernames.split('\n')
usernames = filter(None, usernames)
except IOError:
print('Error: file ', filename, " not found in the current directory.")
quit()
return usernames
main()
def send_message(r, username, subject, body):
try:
r.redditor(username).message(subject, body)
except praw.exceptions.APIException as e:
if 'USER_DOESNT_EXIST' in e.args[0]:
print(e.args[0])
if len(sys.argv) != 4:
print('usage: notifier.py file "subject" "body"')
filename = sys.argv[1] # ADDED
subject = sys.argv[2] # ADDED
body = sys.argv[3] # ADDED
for username in usernames:
send_message(r, username, subject, body)
First time posting on Stack Overflow so please be patient.