Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import time
  4. import datetime
  5. import praw
  6. from termcolor import colored
  7. from pushsafer import init, Client
  8. import urllib3
  9. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  10.  
  11. def log(string, ts=True):
  12. f = open("apex.log", "a")
  13. if ts:
  14. f.write('{:%d.%m.%Y %H:%M:%S}'.format(datetime.datetime.now()) + " " + string + "\n")
  15. else:
  16. f.write(string + "\n")
  17. f.flush()
  18. f.close()
  19.  
  20. log("---NEW-SESSION---", False)
  21. log("Starting program")
  22. try:
  23.  
  24. init("")
  25. except Exception as e:
  26. log("Error connecting to push service: " + str(e))
  27. raise SystemExit
  28.  
  29. try:
  30. reddit = praw.Reddit(client_id="", client_secret="", user_agent="test", username="", password="")
  31. except Exception as e:
  32. log("Error connecting to reddit: " + str(e))
  33. raise SystemExit
  34.  
  35. subreddit = reddit.subreddit("apexlegends")
  36.  
  37. already_posted = []
  38. counter = 0
  39.  
  40. log("Starting loop")
  41. while True:
  42. try:
  43. new = subreddit.new(limit=20)
  44. except Exception as e:
  45. log("Error receiving new data: " + str(e))
  46. toCheck = ['battlepass',
  47. 'battle pass',
  48. 'patch']
  49.  
  50. for post in new:
  51. for string in toCheck:
  52. if post.title.lower().find(string) != -1:
  53. if post.id not in already_posted:
  54. already_posted.append(post.id)
  55. Client("").send_message(post.selftext,post.title, "15480", "1", "47", "1", "http://chaoticoz.de/log", "Check logs", "0", "", "", "","","","","")
  56. log("Notification sent. Title: " + post.title)
  57. counter = 0
  58. if counter ==11:
  59. counter = 0
  60. log("60 seconds passed, nothing new")
  61. counter +=1
  62.  
  63. time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement