Guest User

DEUTSCHLAND

a guest
Apr 2nd, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. import math
  2. import sys
  3. import time
  4. from random import shuffle
  5.  
  6. import requests
  7. #from PIL import Image
  8. from requests.adapters import HTTPAdapter
  9.  
  10. username = sys.argv[1]
  11. password = input("password:")
  12.  
  13. s = requests.Session()
  14. s.mount('https://www.reddit.com', HTTPAdapter(max_retries=5))
  15. s.headers["User-Agent"] = "PlacePlacer"
  16. r = s.post("https://www.reddit.com/api/login/{}".format(username),
  17.            data={"user": username, "passwd": password, "api_type": "json"})
  18. s.headers['x-modhash'] = r.json()["json"]["data"]["modhash"]
  19.  
  20.  
  21.  
  22. blue   = 13
  23. gelb = 8
  24. schwarz = 3
  25. rot = 5
  26.  
  27.  
  28.  
  29. def repairStars():
  30.  
  31.    
  32.  
  33.     for x in range(180):
  34.         right_color = schwarz
  35.         for y in range(53):
  36.             tile = (x+187,y+809)
  37.             if y+809 > 828:
  38.                 right_color = rot
  39.             if y+809 > 845:
  40.                 right_color = gelb
  41.  
  42.             if place_pixel(tile[0], tile[1], right_color): return(true) # only one fix at a time, sadly
  43.  
  44.     return(false) # no star to fix, yay!
  45.  
  46.  
  47.  
  48. def fillBackground(): # haven’t took time to code it, now, for me, it’s sleep time, so I won’t write it. If anyone would like to…
  49.     pass
  50.  
  51.  
  52.  
  53. starPositions = [ # the position of the tip of the stars
  54.             (406, 815),
  55.             (416, 818),
  56.             (423, 825),
  57.             (426, 834),
  58.             (424, 843),
  59.             (417, 851),
  60.             (406, 854),
  61.             (395, 851),
  62.             (387, 844),
  63.             (385, 834),
  64.             (388, 825),
  65.             (395, 818),
  66.         ]
  67. shuffle(starPositions)
  68.  
  69.  
  70. def genStarLst(x, y):
  71.     l = [
  72.                 [x, y],
  73.                 [x, y+1],
  74.                 [x, y+2],
  75.                 [x-2, y+1],
  76.                 [x+2, y+1],
  77.                 [x+1, y+2],
  78.                 [x-1, y+2],
  79.                 [x+1, y+3],
  80.                 [x-1, y+3],
  81.                 [x-2, y+4],
  82.                 [x+2, y+4],
  83.          ]
  84.     shuffle(l)
  85.     return l
  86.  
  87.  
  88.  
  89. def place_pixel(ax, ay, new_color):
  90.     print("Probing absolute pixel {},{}".format(ax, ay))
  91.  
  92.     while True:
  93.         r = s.get("http://reddit.com/api/place/pixel.json?x={}&y={}".format(ax, ay), timeout=5)
  94.         if r.status_code == 200:
  95.             data = r.json()
  96.             break
  97.         else:
  98.             print("ERROR: ", r, r.text)
  99.         time.sleep(2)
  100.  
  101.     old_color = data["color"] if "color" in data else 0
  102.     print("OLD COLOR:",old_color)
  103.     if old_color == new_color:
  104.         print("Color #{} at {},{} already exists (placed by {}), skipping".format(new_color, ax, ay, data[
  105.             "user_name"] if "user_name" in data else "<nobody>"))
  106.     else:
  107.         print("Placing color #{} at {},{}".format(new_color, ax, ay))
  108.         r = s.post("https://www.reddit.com/api/place/draw.json",
  109.                    data={"x": str(ax), "y": str(ay), "color": str(new_color)})
  110.  
  111.         secs = float(r.json()["wait_seconds"])
  112.         if "error" not in r.json():
  113.             print("Placed color - waiting {} seconds".format(secs))
  114.         else:
  115.             print("Cooldown already active - waiting {} seconds".format(int(secs)))
  116.         time.sleep(secs + 1)
  117.  
  118.         if "error" in r.json():
  119.             place_pixel(ax, ay, new_color)
  120.  
  121.  
  122.  
  123. while True:
  124.     repairStars()
Add Comment
Please, Sign In to add comment