Skip to content

Instantly share code, notes, and snippets.

Created April 3, 2017 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/75e0c1132b3bbb9fcff34fc656a8b96a to your computer and use it in GitHub Desktop.
Save anonymous/75e0c1132b3bbb9fcff34fc656a8b96a to your computer and use it in GitHub Desktop.
This program will fix the qr code in the top left on reddit.com/r/place Can be adjusted to work for other projects
# values can be adjusted for other projects. PM me for more info on reddit (/u/nomis6432)
correct_board = (( 3,3,3,3,3,3,3,0,0,0,3,0,3,3,0,0,0,0,3,3,3,0,3,3,3,3,3,3,3),
(3,0,0,0,0,0,3,0,3,0,0,0,0,0,3,0,3,3,0,3,3,0,3,0,0,0,0,0,3),
(3,0,3,3,3,0,3,0,0,0,3,0,0,0,0,0,3,0,0,0,0,0,3,0,3,3,3,0,3),
(3,0,3,3,3,0,3,0,0,3,0,0,3,0,0,0,0,0,3,0,3,0,3,0,3,3,3,0,3),
(3,0,3,3,3,0,3,0,0,3,0,0,3,3,3,0,0,3,0,0,0,0,3,0,3,3,3,0,3),
(3,0,0,0,0,0,3,0,3,0,0,3,3,3,0,3,0,3,0,3,3,0,3,0,0,0,0,0,3),
(3,3,3,3,3,3,3,0,3,0,3,0,3,0,3,0,3,0,3,0,3,0,3,3,3,3,3,3,3),
(0,0,0,0,0,0,0,0,3,3,0,0,0,3,0,0,3,0,0,3,3,0,0,0,0,0,0,0,0),
(0,0,0,0,3,3,3,3,0,3,3,0,0,3,0,0,0,0,0,3,0,0,3,3,0,0,0,3,0),
(0,0,0,0,0,0,0,3,3,3,0,0,3,3,3,0,3,3,3,0,0,3,3,0,3,0,3,3,0),
(0,0,0,0,0,3,3,3,0,3,3,3,3,0,3,3,3,3,3,3,0,0,3,3,3,0,3,0,3),
(3,3,3,3,3,0,0,0,0,0,3,0,0,3,0,3,3,0,0,0,3,0,0,0,0,3,0,0,3),
(3,3,3,0,0,0,3,0,3,0,0,0,0,3,3,3,3,3,0,3,0,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(in seconds)
last_draw_time = -1*cooldown
sleep_time_between_checks = 0 #time between checks (in seconds) if you get frequent "request failed" increase this.
sleep_time_after_failed_request = 3 #cooldown after failed request (in seconds).
user_name="" # enter your user name here
password="" # enter your password here
import requests
from time import sleep
# this class is made by /u/PurdueME06
class Place(object):
def __init__(self, user, passwd, greedy=False):
"""
user: reddit username
pass: reddit password
greedy: keep trying to perform request
"""
self.session = requests.session()
self.session.headers.update({"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 OPR/43.0.2442.1144"})
self.greedy = greedy
payload= {'op': 'login',
'user': user,
'passwd': passwd}
self.session.post("https://www.reddit.com/post/login", data=payload)
sleep(1)
self.last = self.session.get("https://reddit.com/api/me.json")
self.modhash = self.last.json()["data"]["modhash"]
self.session.headers.update({"x-modhash": self.modhash})
def _get(self, x, y):
payload = {"x": x,
"y": y}
return self.session.get("https://www.reddit.com/api/place/pixel.json", params=payload)
def get(self, x=0, y=0):
"""get the color information at a given pixel
x: x-coordinates
y: y-coordinates
"""
self.last = self._get(x,y)
if self.greedy:
while self.last.status_code == 429:
sleep(1)
self.last = self._get(x,y)
return self.last.json()
def _draw(self, x=0, y=0, color=0):
payload = {"x": x,
"y": y,
"color": color}
return self.session.post("https://www.reddit.com/api/place/draw.json", data=payload)
def draw(self, x=0, y=0, color=0):
"""draw a color at given coordinates
x: x-coordinates
y: y-coordinates
color: color to draw at coordinates
"""
self.last = self._draw(x,y)
if self.greedy:
while self.last.status_code == 429:
json = self.last.json()
if "wait_seconds" in json:
wait=json["wait_seconds"]
print("Waiting: {}s".format(wait))
sleep(wait)
else:
sleep(1)
self.last = self._draw(x,y)
return self.last.json()
print("logging in...")
try:
p = Place(user_name,password)
except:
print("login failed. try again in a few seconds and \ncheck if you entered the right username and password.")
quit()
from random import randint
from timeit import default_timer as timer
def change_color(x,y):
p.draw(x + start_x, y + start_y, correct_board[y][x])
print("changed color " + str(curr_bord) + " on position " + str(x + start_x) + "," + str(
y + start_y) + " to color " + str(correct_board[y][x]))
print("searching...")
while 1:
x = randint(0,lenght_x)
y = randint(0,lenght_y)
try:
curr_bord = p.get(x+start_x,y+start_y)["color"]
sleep(sleep_time_between_checks) # increase this if you get frequent errors during the process.
if curr_bord != correct_board[y][x]:
new_draw_time = timer()
if new_draw_time - last_draw_time < cooldown:
print("waiting " + str(int(cooldown - new_draw_time + last_draw_time)) + " seconds to draw new color...")
sleep(int(cooldown - new_draw_time + last_draw_time))
# checks if the color hasn't changed in the mean time.
curr_bord = p.get(x + start_x, y + start_y)["color"]
if curr_bord != correct_board[y][x]:
change_color(x, y)
last_draw_time = timer()
else:
print("color has already been fixed.")
else:
change_color(x, y)
last_draw_time = timer()
print("searching...")
else:
print("color on position " + str(x + start_x) + "," + str(y + start_y) + " is correct: color " + str(
correct_board[y][x]))
except:
print("request failed.")
print("waiting "+str(sleep_time_between_checks)+" seconds to restart...")
sleep(sleep_time_after_failed_request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment