Guest User

/r/place deutschland

a guest
Apr 2nd, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.20 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.     right_color = schwarz
  32.  
  33.     for x in range(80):
  34.         for y in range(53):
  35.             tile = (x+223,y+809)
  36.             if y+809 > 828:
  37.                 right_color = rot
  38.             if y+809 > 845:
  39.                 right_color = gelb
  40.  
  41.             if place_pixel(tile[0], tile[1], right_color): return(true) # only one fix at a time, sadly
  42.  
  43.     return(false) # no star to fix, yay!
  44.  
  45.  
  46.  
  47. 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…
  48.     pass
  49.  
  50.  
  51.  
  52. starPositions = [ # the position of the tip of the stars
  53.             (406, 815),
  54.             (416, 818),
  55.             (423, 825),
  56.             (426, 834),
  57.             (424, 843),
  58.             (417, 851),
  59.             (406, 854),
  60.             (395, 851),
  61.             (387, 844),
  62.             (385, 834),
  63.             (388, 825),
  64.             (395, 818),
  65.         ]
  66. shuffle(starPositions)
  67.  
  68.  
  69. def genStarLst(x, y):
  70.     l = [
  71.                 [x, y],
  72.                 [x, y+1],
  73.                 [x, y+2],
  74.                 [x-2, y+1],
  75.                 [x+2, y+1],
  76.                 [x+1, y+2],
  77.                 [x-1, y+2],
  78.                 [x+1, y+3],
  79.                 [x-1, y+3],
  80.                 [x-2, y+4],
  81.                 [x+2, y+4],
  82.          ]
  83.     shuffle(l)
  84.     return l
  85.  
  86.  
  87.  
  88. def place_pixel(ax, ay, new_color):
  89.     print("Probing absolute pixel {},{}".format(ax, ay))
  90.  
  91.     while True:
  92.         r = s.get("http://reddit.com/api/place/pixel.json?x={}&y={}".format(ax, ay), timeout=5)
  93.         if r.status_code == 200:
  94.             data = r.json()
  95.             break
  96.         else:
  97.             print("ERROR: ", r, r.text)
  98.         time.sleep(2)
  99.  
  100.     old_color = data["color"] if "color" in data else 0
  101.     print("OLD COLOR:",old_color)
  102.     if old_color == new_color:
  103.         print("Color #{} at {},{} already exists (placed by {}), skipping".format(new_color, ax, ay, data[
  104.             "user_name"] if "user_name" in data else "<nobody>"))
  105.     else:
  106.         print("Placing color #{} at {},{}".format(new_color, ax, ay))
  107.         r = s.post("https://www.reddit.com/api/place/draw.json",
  108.                    data={"x": str(ax), "y": str(ay), "color": str(new_color)})
  109.  
  110.         secs = float(r.json()["wait_seconds"])
  111.         if "error" not in r.json():
  112.             print("Placed color - waiting {} seconds".format(secs))
  113.         else:
  114.             print("Cooldown already active - waiting {} seconds".format(int(secs)))
  115.         time.sleep(secs + 1)
  116.  
  117.         if "error" in r.json():
  118.             place_pixel(ax, ay, new_color)
  119.  
  120.  
  121.  
  122. while True:
  123.     repairStars()
Add Comment
Please, Sign In to add comment