Guest User

buzzBuzz

a guest
Apr 2nd, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. import math
  2. import sys
  3. import time
  4. import random
  5.  
  6. import requests
  7. from requests.adapters import HTTPAdapter
  8.  
  9. username = sys.argv[1]
  10. password = sys.argv[2]
  11.  
  12. buzzPixDict = {
  13.     (380,321) : 13,
  14.     (381,321) : 13,
  15.     (404,357) : 1
  16. }
  17.  
  18. def get_current_pixel(x,y):
  19.     r = s.get("http://reddit.com/api/place/pixel.json?x={}&y={}".format(x, y), timeout=5)
  20.     data = "";
  21.     if r.status_code == 200:
  22.         data = r.json()
  23.     else:
  24.         print("ERROR: ", r, r.text)
  25.    
  26.     old_color = data["color"] if "color" in data else -1
  27.     return old_color
  28.  
  29. def check_replace(x,y, new_color):
  30.     old_color = get_current_pixel(x,y);
  31.  
  32.    
  33.     if old_color == new_color:
  34.         print("Pixel is correct, skipping")
  35.     elif (old_color != -1):
  36.         print("Placing color #{} at {},{}".format(new_color, x, y))
  37.         r = s.post("https://www.reddit.com/api/place/draw.json",
  38.                    data={"x": str(x), "y": str(y), "color": str(new_color)})
  39.  
  40.         secs = float(r.json()["wait_seconds"])
  41.         if "error" not in r.json():
  42.             print("Placed color - waiting {} seconds".format(secs))
  43.         else:
  44.             print("Cooldown already active - waiting {} seconds".format(int(secs)))
  45.         time.sleep(secs + 2)
  46.  
  47.         if "error" in r.json():
  48.             check_replace(x, y, new_color)
  49.  
  50.  
  51. s = requests.Session()
  52. s.mount('https://www.reddit.com', HTTPAdapter(max_retries=5))
  53. s.headers["User-Agent"] = "PlacePlacer"
  54. r = s.post("https://www.reddit.com/api/login/{}".format(username),
  55.            data={"user": username, "passwd": password, "api_type": "json"})
  56. s.headers['x-modhash'] = r.json()["json"]["data"]["modhash"]
  57.  
  58. while True:
  59.     for k in buzzPixDict:
  60.         print(check_replace(k[0],k[1],buzzPixDict[k]))
Add Comment
Please, Sign In to add comment