Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- #import time
- #import urllib.request
- import secretfile2 #import private data
- print("Logging into Reddit")
- #Create bot with login and private key
- bot= praw.Reddit(user_agent=secretfile2.agent, client_id=secretfile2.cid, client_secret=secretfile2.csecret, username=secretfile2.uname, password=secretfile2.passwd)
- print(bot.user.me())
- #code to verify logging in correctly
- checkedstatus = bot.read_only
- if checkedstatus == False:
- print("Write enabled")
- else:
- print("Write not enabled")
- exit()
- #if passing here it is connecting correctly
- #run process
- def run():
- print("-------------------------------------------")
- print("Loading reference data")
- try:
- global subreddit_name
- #Create List of Subreddits to source content
- subreddit_name = read_file('subreddit.txt')
- print("Subreddit name: ", subreddit_name)
- except:
- print("Subreddit name couldn't be loaded")
- exit()
- try:
- global post_title
- #load title
- post_title = read_file('title.txt')
- print("Title of post: ", post_title)
- except:
- print("Title couldn't be loaded")
- exit()
- try:
- global post_body
- #load body
- post_body = read_file('body.txt')
- print("Body of post: ", post_body)
- except:
- print("Post body could not be loaded")
- exit()
- try:
- #post to sub
- # bot.subreddit(subreddit_name).submit(title=post_title, selftext=post_body)
- bot.subreddit(subreddit_name).submit(title=post_title, selftext=post_body, url=None, flair_id=None, flair_text=None, resubmit=True, send_replies=False)
- except:
- print("Post could not be made for reasons")
- def read_file(filename1):
- list1=[]
- with open(filename1, 'r') as f1:
- list1=list(f1.read().split('\n'))
- return list1
- if __name__ == '__main__':
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement