Advertisement
ReachingForCode

Untitled

Feb 11th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import praw
  2. #import time
  3. #import urllib.request
  4. import secretfile2 #import private data
  5.  
  6. print("Logging into Reddit")
  7.  
  8. #Create bot with login and private key
  9.  
  10. bot= praw.Reddit(user_agent=secretfile2.agent, client_id=secretfile2.cid, client_secret=secretfile2.csecret, username=secretfile2.uname, password=secretfile2.passwd)
  11.  
  12. print(bot.user.me())
  13.  
  14. #code to verify logging in correctly
  15.  
  16. checkedstatus = bot.read_only
  17. if checkedstatus == False:
  18. print("Write enabled")
  19. else:
  20. print("Write not enabled")
  21. exit()
  22.  
  23. #if passing here it is connecting correctly
  24.  
  25.  
  26.  
  27.  
  28.  
  29. #run process
  30. def run():
  31. print("-------------------------------------------")
  32. print("Loading reference data")
  33.  
  34. try:
  35. global subreddit_name
  36. #Create List of Subreddits to source content
  37. subreddit_name = read_file('subreddit.txt')
  38. print("Subreddit name: ", subreddit_name)
  39. except:
  40. print("Subreddit name couldn't be loaded")
  41. exit()
  42.  
  43. try:
  44. global post_title
  45. #load title
  46. post_title = read_file('title.txt')
  47. print("Title of post: ", post_title)
  48. except:
  49. print("Title couldn't be loaded")
  50. exit()
  51.  
  52. try:
  53. global post_body
  54. #load body
  55. post_body = read_file('body.txt')
  56. print("Body of post: ", post_body)
  57. except:
  58. print("Post body could not be loaded")
  59. exit()
  60.  
  61. try:
  62. #post to sub
  63. # bot.subreddit(subreddit_name).submit(title=post_title, selftext=post_body)
  64. bot.subreddit(subreddit_name).submit(title=post_title, selftext=post_body, url=None, flair_id=None, flair_text=None, resubmit=True, send_replies=False)
  65. except:
  66. print("Post could not be made for reasons")
  67.  
  68.  
  69. def read_file(filename1):
  70. list1=[]
  71. with open(filename1, 'r') as f1:
  72. list1=list(f1.read().split('\n'))
  73. return list1
  74.  
  75.  
  76.  
  77. if __name__ == '__main__':
  78. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement