Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import sys
- import time
- import random
- import struct
- import requests
- from requests.adapters import HTTPAdapter
- with open(sys.argv[1]) as textFile:
- bitmp = [line.split(',') for line in textFile]
- origin = (int(sys.argv[2]), int(sys.argv[3]))
- username = sys.argv[4]
- password = sys.argv[5]
- 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"]
- def get_bad_pixels():
- badpixels = []
- r = s.get("https://www.reddit.com/api/place/board-bitmap", timeout=10)
- boardcols = r.content[4:]
- ay = 0
- for ay in range(len(bitmp)):
- for ax in range(len(bitmp[ay])):
- boardpos = (origin[1] + ay) * 1000 + origin[0] + ax
- boardcol = struct.unpack('B', boardcols[int(boardpos/2)])[0]
- if boardpos % 2 == 0:
- boardcol = boardcol >> 4
- else:
- boardcol = boardcol & 15
- if int(bitmp[ay][ax]) != boardcol:
- badpixels.append((ax,ay))
- return badpixels
- while True:
- badpixels = get_bad_pixels()
- while len(badpixels) == 0:
- time.sleep(60)
- badpixels = get_bad_pixels()
- badpixel = random.choice(badpixels)
- ax = badpixel[0]
- ay = badpixel[1]
- print("Placing color {} at {},{}".format(bitmp[ay][ax], origin[0] + ax, origin[1] + ay))
- r = s.post("https://www.reddit.com/api/place/draw.json",
- data={"x": str(origin[0] + ax), "y": str(origin[1] + ay), "color": bitmp[ay][ax]})
- try:
- secs = float(r.json()["wait_seconds"])
- except:
- print("Exception in script - {}, retrying in 10 secs".format(r.json()))
- secs = 10
- waitTime = int(secs) + 2
- if "error" not in r.json():
- print("Placed color, waiting {} seconds.".format(waitTime))
- else:
- print("Cooldown already active, waiting {} seconds.".format(waitTime))
- while(waitTime > 0):
- time.sleep(1)
- waitTime -= 1
Add Comment
Please, Sign In to add comment