Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import requests
- import time
- import urllib
- current_wait = 0
- save_interval = 60
- last_save = datetime.datetime.now()
- url = "https://www.reddit.com/api/place/draw.json"
- auths = [['mod_hash', 'reddit_session']]
- for auth in auths:
- auth.append(datetime.datetime.now())
- auth.append(current_wait)
- result = []
- hex_chars = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
- def update_map():
- global result
- result = []
- r = requests.get("https://www.reddit.com/api/place/board-bitmap",headers={"cookie":"reddit_session=xd_get_ur_own","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"})
- raw_bitmap = r.content
- for i in range(10000):
- result.append([])
- x = 0
- y = 0
- bitmap = []
- hex_chars = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
- for pixel in raw_bitmap:
- bitmap.append(pixel >> 4)
- bitmap.append(pixel & 0x0F)
- for px in bitmap:
- x += 1
- result[y].append(px)
- if x == 1000:
- x = 0
- y += 1
- def get_pixel(x, y):
- return result[y][x]
- def place_pixel(auth, x, y, color, auth_index):
- global current_wait
- auth["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
- resp = requests.post(url, headers=auth, data={"x":x,"y":y,"color":color})
- rjson = resp.json()
- print("Placing pixel at " + str(x) + ", " + str(y) + " w/ color " + str(color))
- current_wait = rjson["wait_seconds"]
- auths[auth_index][3] = current_wait
- auths[auth_index][2] = datetime.datetime.now()
- time.sleep(1)
- return rjson
- def get_area(min_x, min_y, max_x, max_y):
- min_x += 8
- max_x += 8
- area = []
- return [row[min_x: max_x+1] for row in result[min_y: max_y+1]]
- def print_area(min_x, min_y, max_x, max_y):
- area = get_area(min_x, min_y, max_x, max_y)
- output = ""
- for row in area:
- for c in row:
- output += hex_chars[c]
- output += "\n"
- return output
- def find_auth():
- now = datetime.datetime.now()
- c = 0
- for auth in auths:
- use_when = auth[2] + datetime.timedelta(seconds=auth[3])
- if now > use_when:
- return [auth, c]
- c += 1
- return False
- inner_min_x = 280
- inner_min_y = 85
- inner_max_x = 348
- inner_max_y = 88
- inner_img = [
- "336636333663363336336633666666336633663666666666666636333636366366666",
- "363636366636663636363636366663666366663663636636363336636636363336336",
- "363636663636663636336636363363636363636636363636363636636633366366363",
- "336636333663363336363633663366336633636636363663663336326666366366363"
- ]
- outer_min_x = 278
- outer_min_y = 83
- outer_max_x = 350
- outer_max_y = 90
- outer_img = [
- "3333333333333333333333333333333333333333333333333333333333333333333333333",
- "3666666666666666666666666666666666666666666666666666666666666666666666663",
- "3633663633366336333633663366666633663366366666666666663633363636636666663",
- "3636363636663666363636363636666366636666366363663636333663663636333633663",
- "3636363666363666363633663636336363636363663636363636363663663336636636363",
- "3633663633366336333636363366336633663363663636366366333632666636636636363",
- "3666666666666666666666666666666666666666666666666666666666666666666666663",
- "3333333333333333333333333333333333333333333333333333333333333333333333333"
- ]
- def fix(diffs, img, min_x, min_y):
- for diff in diffs:
- use_auth = find_auth()
- if use_auth:
- place_pixel({"cookie":"reddit_session=" + urllib.parse.quote(use_auth[0][1]), "x-modhash": use_auth[0][0]}, diff[0], diff[1], img[diff[2]][diff[3]], use_auth[1])
- while True:
- update_map()
- if datetime.datetime.now() > last_save + datetime.timedelta(seconds=save_interval):
- last_save = datetime.datetime.now()
- filename = "map_" + last_save.isoformat() + "bmp"
- with open("maps/" + filename, "w") as f:
- to_write = ""
- for row in result:
- for hx in row:
- to_write += hex_chars[hx]
- to_write += "\n"
- inner = get_area(inner_min_x, inner_min_y, inner_max_x, inner_max_y)
- c = inner_min_y
- diff = []
- lolc = 0
- for row in inner:
- #print(print_area(inner_min_x, inner_min_y, inner_max_x, inner_max_y))
- #print("\n".join(inner_img))
- differences = [i for i in range(len(row)) if hex_chars[row[i]] != inner_img[lolc][i]]
- for vandal in differences:
- diff.append([c, vandal+inner_min_x, c-inner_min_y, vandal])
- c += 1
- lolc += 1
- if len(diff) == 0:
- minor_diff = []
- outer = get_area(outer_min_x, outer_min_y, outer_max_x, outer_max_y)
- print("Cur: ")
- print(print_area(outer_min_x, outer_min_y, outer_max_x, outer_max_y))
- out = ""
- for r in outer_img:
- out += r + "\n"
- print("Desired: ")
- print(out)
- c = outer_max_y
- lolc = 0
- for row in outer:
- differences = [i for i in range(len(row)) if hex_chars[row[i]] != outer_img[lolc][i]]
- for vandal in differences:
- minor_diff.append([c, vandal+outer_min_x, c-outer_min_y, vandal])
- c += 1
- lolc += 1
- fix(minor_diff, outer_img, outer_min_x, outer_min_y)
- else:
- fix(diff, inner_img, inner_min_x, inner_min_y)
- time.sleep(15)
Add Comment
Please, Sign In to add comment