Last active
April 2, 2017 14:56
-
-
Save fgaz/c0dac17e6165674baf33d2e683e614a1 to your computer and use it in GitHub Desktop.
Mantain italy's flag in /r/place
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# needs python 2 | |
import urllib | |
import urllib2 | |
import time | |
import json | |
import random | |
# italy flag position: | |
xmin = 107 | |
xmax = 139 | |
ymin = 326 | |
offense=2 # 1 = defend first 2+ = attack more, proportionally to the number | |
delay_minutes=10 # MAKE SURE THIS IS >= the actual delay | |
# protected pixels. the pixel in this list will not be overwritten | |
# example: protected = [(1,1),(1,2),(2,1),(2,2)] will protect a 2x2 square in the top left corner of the canvas | |
waldo_face = [(138,390),(138,394),(138,395),(138,396),(138,397),(138,398),(138,399),(138,400),(138,401),(138,402),(138,403),(138,404),(138,405),(137,399),(137,400),(137,401),(137,402)] | |
waldo_arm = [] | |
waldo = waldo_face + waldo_arm | |
rainbow = [(108,398),(108,399),(108,400),(108,401),(108,402),(108,403),(108,404),(108,405),(108,406),(108,407),(108,408),(109,399),(109,400),(109,401),(109,402),(109,403),(109,404),(109,405),(109,406),(109,407),(109,408),(109,409),(110,400),(110,401),(110,402),(110,403),(110,404),(110,405),(110,406),(110,407),(110,408),(110,409),(110,410),(111,401),(111,402),(111,403),(111,404),(111,405),(111,406),(111,407),(111,408),(111,409),(111,410),(111,411),(112,402),(112,403),(112,404),(112,405),(112,406),(112,407),(112,408),(112,409),(112,410),(112,411),(112,412),(113,403),(113,404),(113,405),(113,406),(113,407),(113,408),(113,409),(113,410),(113,411),(113,412),(113,413),(114,404),(114,405),(114,406),(114,407),(114,408),(114,409),(114,410),(114,411),(114,412),(114,413),(114,414),(115,405),(115,406),(115,407),(115,408),(115,409),(115,410),(115,411),(115,412),(115,413),(115,414),(115,415),(116,406),(116,407),(116,408),(116,409),(116,410),(116,411),(116,412),(116,413),(116,414),(116,415),(116,416),(117,407),(117,408),(117,409),(117,410),(117,411),(117,412),(117,413),(117,414),(117,415),(117,416),(117,417),(118,408),(118,409),(118,410),(118,411),(118,412),(118,413),(118,414),(118,415),(118,416),(118,417),(118,418),(119,409),(119,410),(119,411),(119,412),(119,413),(119,414),(119,415),(119,416),(119,417),(119,418),(119,419),(120,410),(120,411),(120,412),(120,413),(120,414),(120,415),(120,416),(120,417),(120,418),(120,419),(120,420),(121,411),(121,412),(121,413),(121,414),(121,415),(121,416),(121,417),(121,418),(121,419),(121,420),(121,421),(122,412),(122,413),(122,414),(122,415),(122,416),(122,417),(122,418),(122,419),(122,420),(122,421),(122,422),(123,413),(123,414),(123,415),(123,416),(123,417),(123,418),(123,419),(123,420),(123,421),(123,422),(123,423),(124,414),(124,415),(124,416),(124,417),(124,418),(124,419),(124,420),(124,421),(124,422),(124,423),(124,424),(125,415),(125,416),(125,417),(125,418),(125,419),(125,420),(125,421),(125,422),(125,423),(125,424),(125,425),(126,416),(126,417),(126,418),(126,419),(126,420),(126,421),(126,422),(126,423),(126,424),(126,425),(126,426),(127,417),(127,418),(127,419),(127,420),(127,421),(127,422),(127,423),(127,424),(127,425),(127,426),(127,427),(128,418),(128,419),(128,420),(128,421),(128,422),(128,423),(128,424),(128,425),(128,426),(128,427),(128,428)] # generated from foldMap (\(x,y) -> (x,) <$> [y..y+10]) $ zip [108..128] [398..] (haskell) | |
# some are probably missing here: | |
rainbow_portal = [(129,417),(130,418),(130,419),(129,420),(130,420),(131,420),(129,421),(130,421),(131,421),(128,422),(129,422),(130,422),(131,422),(127,423),(128,423),(129,423),(130,423),(131,423)] | |
rainbowroad = rainbow + rainbow_portal | |
protected = waldo + rainbowroad | |
def get_target_color(x): | |
if(x>=107 and x<=108): return 3 # left border: black | |
if(x>=109 and x<=118): return 10 # first stripe: green | |
if(x>=119 and x<=128): return 0 # second stripe: white | |
if(x>=129 and x<=138): return 5 # third stripe: red | |
if(x>=139 and x<=139): return 3 # right border: black | |
print "Build the Italy Flag" | |
print "Getting user agent list for anonymity (please wait)" | |
user_agent_list=list(set([ua for ua in urllib.urlopen("https://raw.githubusercontent.com/sqlmapproject/sqlmap/master/txt/user-agents.txt").read().splitlines() if not ua.startswith("#")])) | |
accounts = [] | |
sessions = {} | |
print "For each account you want to use, enter it in like username:password" | |
print "When you're done, type 'done'" | |
user_input = "" | |
while (user_input != "done"): | |
user_input = raw_input("Account-> ") | |
if user_input.lower() != "done": | |
accounts.append(user_input) | |
opener = urllib2.build_opener() | |
opener.addheaders = [('User-Agent', random.choice(user_agent_list))] | |
for account in accounts: | |
username = account.split(":")[0] | |
password = account.split(":")[1] | |
data = urllib.urlencode({'op': 'login-main', 'user': username, 'passwd': password, 'api_type': 'json'}) | |
resp = opener.open('https://www.reddit.com/api/login/'+urllib.quote(username), data).read() | |
sessions[username] = json.loads(resp)["json"]["data"]["cookie"] | |
print "Running Build the Italy Flag" | |
while True: | |
# Fill the void | |
for session in sessions.keys(): | |
cookie = sessions[session] | |
x = random.randint(xmin,xmax) | |
y = ymin-1 | |
target_color = get_target_color(x) | |
color = target_color | |
while color == target_color: | |
# Find a wrong square | |
y = y+random.randint(1,offense) | |
if (x,y) in protected: | |
continue | |
resp = opener.open("https://www.reddit.com/api/place/pixel.json?x="+str(x)+"&y="+str(y)).read() | |
try: | |
color = int(json.loads(resp)["color"]) | |
except Exception, e: | |
#print "Exception" | |
#print resp | |
color = target_color | |
print "Found a non-flag color at", x, y | |
data = urllib.urlencode({'x': x, 'y': y, 'color': target_color}) | |
newopener = urllib2.build_opener() | |
newopener.addheaders = [('User-Agent', random.choice(user_agent_list))] | |
newopener.addheaders.append(('Cookie', 'reddit_session='+cookie)) | |
modhash = json.loads(newopener.open("https://reddit.com/api/me.json").read())["data"]["modhash"] | |
newopener.addheaders.append(('x-modhash', modhash)) | |
next=newopener.open("https://www.reddit.com/api/place/draw.json", data).read() | |
print next | |
finalresp = newopener.open("https://www.reddit.com/api/place/pixel.json?x="+str(x)+"&y="+str(y)).read() | |
if session in finalresp: | |
print "Added successfully" | |
else: | |
print finalresp | |
time.sleep(delay_minutes*60+5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment