Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import sys
- import time
- from random import shuffle
- import requests
- #from PIL import Image
- from requests.adapters import HTTPAdapter
- username = sys.argv[1]
- password = input("password:")
- s = requests.Session()
- s.mount('https://www.reddit.com', HTTPAdapter(max_retries=5))
- s.headers["User-Agent"] = "PlacePlacer"
- r = s.post("https://www.reddit.com/api/login/{}".format(username),
- data={"user": username, "passwd": password, "api_type": "json"})
- s.headers['x-modhash'] = r.json()["json"]["data"]["modhash"]
- blue = 13
- gelb = 8
- schwarz = 3
- rot = 5
- def repairStars():
- for x in range(180):
- right_color = schwarz
- for y in range(53):
- tile = (x+187,y+809)
- if y+809 > 828:
- right_color = rot
- if y+809 > 845:
- right_color = gelb
- if place_pixel(tile[0], tile[1], right_color): return(true) # only one fix at a time, sadly
- return(false) # no star to fix, yay!
- 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…
- pass
- starPositions = [ # the position of the tip of the stars
- (406, 815),
- (416, 818),
- (423, 825),
- (426, 834),
- (424, 843),
- (417, 851),
- (406, 854),
- (395, 851),
- (387, 844),
- (385, 834),
- (388, 825),
- (395, 818),
- ]
- shuffle(starPositions)
- def genStarLst(x, y):
- l = [
- [x, y],
- [x, y+1],
- [x, y+2],
- [x-2, y+1],
- [x+2, y+1],
- [x+1, y+2],
- [x-1, y+2],
- [x+1, y+3],
- [x-1, y+3],
- [x-2, y+4],
- [x+2, y+4],
- ]
- shuffle(l)
- return l
- def place_pixel(ax, ay, new_color):
- print("Probing absolute pixel {},{}".format(ax, ay))
- while True:
- r = s.get("http://reddit.com/api/place/pixel.json?x={}&y={}".format(ax, ay), timeout=5)
- if r.status_code == 200:
- data = r.json()
- break
- else:
- print("ERROR: ", r, r.text)
- time.sleep(2)
- old_color = data["color"] if "color" in data else 0
- print("OLD COLOR:",old_color)
- if old_color == new_color:
- print("Color #{} at {},{} already exists (placed by {}), skipping".format(new_color, ax, ay, data[
- "user_name"] if "user_name" in data else "<nobody>"))
- else:
- print("Placing color #{} at {},{}".format(new_color, ax, ay))
- r = s.post("https://www.reddit.com/api/place/draw.json",
- data={"x": str(ax), "y": str(ay), "color": str(new_color)})
- secs = float(r.json()["wait_seconds"])
- if "error" not in r.json():
- print("Placed color - waiting {} seconds".format(secs))
- else:
- print("Cooldown already active - waiting {} seconds".format(int(secs)))
- time.sleep(secs + 1)
- if "error" in r.json():
- place_pixel(ax, ay, new_color)
- while True:
- repairStars()
Add Comment
Please, Sign In to add comment