User:Eleanorg/1.3/Dissolute Image/Code1: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
==Make database of pixels== | ==Make database of pixels== | ||
Splits up image into pixels with imageMagick, then inserts each one as a hash in a Mongo database | Splits up image into pixels (and their associated info) with imageMagick, then inserts each one as a hash in a Mongo database. | ||
<source lang="python"> | <source lang="python"> | ||
Line 13: | Line 13: | ||
#--------- create database -----------------------# | #--------- create database --------------------------------# | ||
connection = Connection() | connection = Connection() | ||
Line 21: | Line 21: | ||
#--------- determine image dimensions-----------------------# | #--------- determine image dimensions-----------------------# | ||
image = " | image = "thatwouldbetelling!" | ||
sizeQuery = "identify -format '%w %h' " + image # system command gets image dimensions with ImageMagick | sizeQuery = "identify -format '%w %h' " + image # system command gets image dimensions with ImageMagick | ||
size = os.popen(sizeQuery, 'r').read() # captures output of system call | size = os.popen(sizeQuery, 'r').read() # captures output of system call | ||
Line 28: | Line 28: | ||
columns = int(width) | columns = int(width) | ||
rows = int(height) | rows = int(height) | ||
#print columns | |||
#print rows | |||
##--------- assign pixel details to database-----------------# | |||
#--------- assign pixel details to database-----------------# | |||
def getcolors (): | def getcolors (): | ||
ID = 0 | |||
for row in range (0, rows): # for each row in the image... | for row in range (0, rows): # for each row in the image... | ||
for column in range (0, columns): # for each column in the row... | for column in range (0, columns): # for each column in the row... | ||
ID = ID + 1 | |||
colorQuery = "convert " + image + " -format '%[pixel:p{" + str(column) + "," + str(row) + "}]' info:-" | colorQuery = "convert " + image + " -format '%[pixel:p{" + str(column) + "," + str(row) + "}]' info:-" | ||
colorResult = os.popen(colorQuery, 'r').read() # makes & captures output of system call | colorResult = os.popen(colorQuery, 'r').read() # makes & captures output of system call | ||
rgbResult = re.sub("\n", "", colorResult) # strips newline character from end of sys call result | |||
pat = r"(\d\d\d),(\d\d\d),(\d\d\d)," # use dirty dirty regex to manually convert rgb result to a tuple | |||
collection.insert( | for m in re.finditer(pat,rgbResult): | ||
r = int((m.group(1))) | |||
getcolors() | g = int((m.group(2))) | ||
b = int((m.group(3))) | |||
RGB = r,g,b | |||
hexa = "".join(map(chr, RGB)).encode('hex') # converts tuple from rgb form to hex value | |||
color = re.sub(hexa, "#"+hexa, hexa) # replaces hex value with the same value plus a leading # | |||
pixelHash = {'ID': ID, 'xpos': str(column), 'ypos': str(row), 'color': color, 'url':"" } | |||
collection.insert(pixelHash) # insert this pixel into the db | |||
getcolors() | |||
</source> | </source> | ||
==Give user an unadopted pixel== | ==Give user an unadopted pixel== | ||
Finds all the pixels in the db with no url associated. Picks one at random and gives it to the user, with an input form for them to enter the url where they have put it. | Finds all the pixels in the db with no url associated. Picks one at random and gives it to the user, with an input form for them to enter the url where they have put it. | ||
<source lang="python"> | <source lang="python"> | ||
#!/usr/bin/python | #!/usr/bin/python | ||
#-*- coding:utf-8 -*- | #-*- coding:utf-8 -*- | ||
import cgi | |||
import cgitb; cgitb.enable() | |||
import pymongo, random | import pymongo, random | ||
from pymongo import Connection | from pymongo import Connection | ||
Line 60: | Line 75: | ||
connection = Connection() | connection = Connection() | ||
myDB = connection[' | myDB = connection['pixelDbQuery1'] | ||
Line 75: | Line 90: | ||
#--------- generate pixel string ------------# | #--------- generate pixel string ------------# | ||
# find all empty | # find all entries where url is empty: | ||
unadopted = [] | unadopted = [] | ||
for entry in myDB.collection.find({"url": ""}): | for entry in myDB.collection.find({"url": ""}): | ||
unadopted.append(entry) # add this pixel's hash as an item to the 'unadopted' dictionary | unadopted.append(entry) # add this pixel's hash as an item to the 'unadopted' dictionary | ||
#print unadopted | |||
howMany = len(unadopted) # find out how many items in 'unadopted' list | howMany = len(unadopted) # find out how many items in 'unadopted' list | ||
#print howMany | |||
random = random.randint(0,howMany) # pick a random number in this range | random = random.randint(0,howMany) # pick a random number in this range | ||
#print random | |||
pixelHash = unadopted[random] # ...and choose the pixel at this index | pixelHash = unadopted[random] # ...and choose the pixel at this index | ||
print pixelHash | #print pixelHash | ||
pixelString = " | pixelString = "ID=" + str(pixelHash['ID']) + ";x=" + pixelHash['xpos'] + ";y=" + pixelHash['ypos'] + ";col=" + pixelHash['color'] | ||
print pixelString | #print pixelString | ||
Line 96: | Line 114: | ||
<title>Adopt a Pixel</title> | <title>Adopt a Pixel</title> | ||
<link <link rel="stylesheet" href="../../pixels.css"> | <link <link rel="stylesheet" href="../../pixels.css"> | ||
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'> | |||
</head> | </head> | ||
<body>""" | <body>""" | ||
Line 104: | Line 123: | ||
print htmlHeader | print htmlHeader | ||
print """ | print """ | ||
<div class=" | <h1>the DISSOLUTE IMAGE</h1> | ||
<div class="main"> | |||
<div class="menu"> | |||
<ul class="menuList"> | |||
<li><a href="pixelsShowImage.cgi">Home</a></li> | |||
<li><a href="../../forbiddenPixels/pixelsAbout.html">About</a></li> | |||
<li>Host a Pixel</li> | |||
</ul> | |||
</div> | |||
</div> | |||
<div class="heading">Host a Pixel</div> | |||
<div class="rightBox" style=""> | |||
<div class="pixelInfo"> | |||
You'll be hosting pixel <strong>""" + str(pixelHash['ID']) + """</strong> out of a total 95600. Enlarged preview: | |||
<div id="pixelPreview" style="background-color: """ + pixelHash['color'] + """"> | |||
</div> | </div> | ||
<div class=" | |||
<div class="pixelDetails"> | |||
Here are the unique details for your pixel: <br /> | |||
</div> | </div> | ||
< | |||
Then tell us the URL of the page where you pasted | <form action="pixelsScrapeAndVerify.cgi" name="inputForm"> | ||
<input name="pixel" class="pixelInput" value=""" + pixelString + """><br /> | |||
<div class="inputBox"> | |||
To host this pixel, just copy & paste the details above<br /> somewhere public on the web, exactly as they appear.<br /> | |||
Then tell us the full URL of the page where you pasted them:<br /> | |||
</div> | </div> | ||
< | </span> | ||
URL: <input name="url" class="urlInput" value=""> | |||
<input type="submit" value="OK"> | <input type="submit" value="OK"> | ||
</form> | |||
<div class=" | |||
<div class=""> | |||
Your pixel will appear in the image for as long as the text remains at this URL. | Your pixel will appear in the image for as long as the text remains at this URL. | ||
</div> | |||
</div> | </div> | ||
</body> | </body> | ||
</html>""" | </html>""" | ||
</source> | </source> | ||
==Verify the url submitted by user== | ==Verify the url submitted by user== | ||
[[User:Eleanorg/1.3/Dissolute Image/Code/verify input | code experiments on verifying user input]] | <!--[[User:Eleanorg/1.3/Dissolute Image/Code/verify input | code experiments on verifying user input]]--> | ||
Scrapes the url given by the user to see if the right pixel can be found there. If yes, that url gets associated with the appropriate pixel in the db so it no longer comes up for adoption. | Scrapes the url given by the user to see if the right pixel can be found there. If yes, that url gets associated with the appropriate pixel in the db so it no longer comes up for adoption. The pixel is then added to the image via a system call to Imagemagick. | ||
<source lang="python"> | <source lang="python"> | ||
#!/usr/bin/python | #!/usr/bin/python | ||
Line 144: | Line 182: | ||
import cgi | import cgi | ||
import os, subprocess, re, urllib2 | import os, subprocess, re, urllib2 | ||
import cgitb; cgitb.enable() | |||
import pymongo | import pymongo | ||
from pymongo import Connection | from pymongo import Connection | ||
# recieves url from inputForm.html scrapes it to check if pixel has been put there correctly | # recieves url from inputForm.html scrapes it to check if pixel has been put there correctly | ||
# if yes = updates db entry for that pixel | # if yes = updates db entry for that pixel | ||
Line 161: | Line 199: | ||
<title>A form talking to a python script</title> | <title>A form talking to a python script</title> | ||
<link <link rel="stylesheet" href="../../pixels.css"> | <link <link rel="stylesheet" href="../../pixels.css"> | ||
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'> | |||
</head> | </head> | ||
<body> | <body> | ||
<h1>the DISSOLUTE IMAGE</h1> | |||
<div class="main"> | |||
<div class="menu"> | |||
<ul class="menuList"> | |||
<li><a href="../mongo/pixelsShowImage.cgi">Home</a></li> | |||
<li><a href="../../forbiddenPixels/pixelsAbout.html">About</a></li> | |||
<li><a href="../cgi-bin/mongo/pixelsShowUnadoptedPixel.cgi">Host a Pixel</a></li> | |||
</ul> | |||
</div> | |||
<div class="rightBox"> | |||
""" | |||
htmlFooter = """ | htmlFooter = """ | ||
</div> | |||
</div> | |||
</body> | </body> | ||
</html>""" | </html>""" | ||
scrapingError = """Sorry, your pixel details couldn't be found at that URL! <br /> | |||
<ul> | |||
<li>Did you paste them exactly as they appear?</li> | |||
<li>Did you give the URL for the specific page or tweet where you pasted them?</li> | |||
<li>Is the page where you pasted them publicly accessible?</li> | |||
</li> | |||
<br /> | |||
Use your browser's back button to try again, or <a href="pixelsShowUnadoptedPixel.cgi">try another pixel</a>. | |||
""" | """ | ||
verifyError = """Sorry, the details you've put online for that pixel seem to be wrong. <br /> | |||
thankyou = """Thanks, URL submitted. <br /> | <ul> | ||
<li>Did you paste the pixel details exactly as they appear?</li> | |||
</ul> | |||
<br /> | |||
Use your browser's back button to try again, or <a href="pixelsShowUnadoptedPixel.cgi">try another pixel</a>.""" | |||
thankyou = """<strong>Thanks, URL submitted.</strong><br /><br /> | |||
Your pixel has been added to the image,<br /> and will remain there as long as you keep your pixel details online.""" | |||
#------------- get URL from input form -------------------# | #------------- get URL from input form -------------------# | ||
form = cgi.FieldStorage() # Grabs whatever input comes from form | form = cgi.FieldStorage() # Grabs whatever input comes from form | ||
string = form.getvalue("pixel") | |||
#url = form.getvalue("url", "http://ox4.org/~nor/trials/hostedString.html") # assigns form's input to var 'url'. url on the right is a default value that will be printed for testing if nothing is recieved from the form | #TODO check if valid url/protocol given. urllib2 bit breaks if not. | ||
url = form.getvalue("url", "http://ox4.org/~nor/trials/hostedString.html") # assigns form's input to var 'url'. url on the right is a default value that will be printed for testing if nothing is recieved from the form | |||
#for testing: | |||
#string = r"ID=65;x=4;y=3;col=red" | |||
#url = "http://ox4.org/~nor/trials/hostedString.html" | |||
#------------- print html header--------------------------# | #------------- print html header--------------------------# | ||
print "Content-Type: text/html" | |||
print | |||
print htmlHeader | |||
Line 203: | Line 268: | ||
myhash = {} | myhash = {} | ||
for s in cap : | for s in cap : | ||
# print s | |||
k,v = s.split('=') # splits each capture on the = into key and value | k,v = s.split('=') # splits each capture on the = into key and value | ||
myhash[k] = v # puts new k/v pair into hash with these values | myhash[k] = v # puts new k/v pair into hash with these values | ||
# return hash so it can be compared with that in the db | # return hash so it can be compared with that in the db | ||
try : | try : | ||
myhash[' | myhash['ID'] and myhash['x'] and myhash['y'] and myhash['col'] | ||
except: | except: | ||
return # missing parameter! return nothing | return # missing parameter! return nothing | ||
return myhash # returns a hash as above, accessed thus: | return myhash # returns a hash as above, accessed thus: split['x'] etc | ||
# | |||
#print splitString(string) | |||
# | # | ||
# | ##------------- scrape and check the url -----------------# | ||
# connect to db for verification, and possible updating | ## if correct string not found, throw error | ||
## if found, print thankyou and update db | |||
#connect to db for verification, and possible updating | |||
connection = Connection() | connection = Connection() | ||
myDB = connection['pixelDbQuery1'] | myDB = connection['pixelDbQuery1'] | ||
collection = myDB.collection | collection = myDB.collection | ||
text = urllib2.urlopen(url).read() # reads page at the specified URL | text = urllib2.urlopen(url).read() # reads page at the specified URL | ||
#print text | ##print text | ||
if not re.search(string, text): # if | # this returns only true or false: | ||
# TODO change regex method to only scrape the first instance of string on a page | |||
if not re.search(string, text): # if string isn't matched within 'text' | |||
print scrapingError # print error message to user | |||
else: | else: | ||
split = splitString(string) | # check if .search has returned an array (ie, if more than one match was found). if so, only look at array[0] OR find a way to only scrape 1st one (.match one?) | ||
split = splitString(string) # calls split string function, passing it the string recieved from the input form, and assigns it to var 'split' | |||
if split: | if split: | ||
idNo = int(split['ID']) # get idNo according to user's string; cast as int to compare with db | |||
idNo = split[' | pixelHash = myDB.collection.find_one({'ID': idNo}) # this grabs a hash with the right id number (if valid), whose index thingies you can access | ||
if pixelHash: | |||
pixelHash = myDB.collection. | # now check if attributes from string recieved (xpos, ypos) match attributes for that ID in DB? | ||
if split['x'] == pixelHash['xpos'] and split['y'] == pixelHash['ypos']: | |||
if pixelHash: | # print "correct x and y value given" | ||
# check if attributes from string recieved (xpos, ypos | collection.update( {'ID': idNo}, {"$set":{'url': url}}) # set pixel with string matching 'pat' to url given by user | ||
# draw a new pixel onto the img with a syscall | |||
color = split['col'] | |||
x = str(split['x']) | |||
y = str(split['y']) | |||
command = """convert ../../forbiddenPixels/images/dissolute1.png -fill '""" + color + """' -draw 'point """ + x + "," + y + """' ../../forbiddenPixels/images/dissolute2.png""" | |||
# print | #print command | ||
os.popen(command, 'r').read() | |||
print thankyou | |||
else: | |||
print verifyError | |||
else: print verifyError | |||
else: | else: | ||
print verifyError | |||
print htmlFooter | |||
</source> | </source> | ||
Revision as of 09:55, 25 June 2012
Make database of pixels
Splits up image into pixels (and their associated info) with imageMagick, then inserts each one as a hash in a Mongo database.
#!/usr/bin/python
#-*- coding:utf-8 -*-
# this script grabs pixel data from imagemagick & creates the mongo database of pixels. to be run once.
import os, re
import pymongo #the library that serves as python interface to mongo database system
from pymongo import Connection
#--------- create database --------------------------------#
connection = Connection()
myDB = connection['pixelDbQuery1']
collection = myDB.collection #tables in Mongo are called 'collections'. variable name on the left can be anything.
#--------- determine image dimensions-----------------------#
image = "thatwouldbetelling!"
sizeQuery = "identify -format '%w %h' " + image # system command gets image dimensions with ImageMagick
size = os.popen(sizeQuery, 'r').read() # captures output of system call
(width, height) = size.split() # splits ImageMagick output into separate column & row no's
columns = int(width)
rows = int(height)
#print columns
#print rows
##--------- assign pixel details to database-----------------#
def getcolors ():
ID = 0
for row in range (0, rows): # for each row in the image...
for column in range (0, columns): # for each column in the row...
ID = ID + 1
colorQuery = "convert " + image + " -format '%[pixel:p{" + str(column) + "," + str(row) + "}]' info:-"
colorResult = os.popen(colorQuery, 'r').read() # makes & captures output of system call
rgbResult = re.sub("\n", "", colorResult) # strips newline character from end of sys call result
pat = r"(\d\d\d),(\d\d\d),(\d\d\d)," # use dirty dirty regex to manually convert rgb result to a tuple
for m in re.finditer(pat,rgbResult):
r = int((m.group(1)))
g = int((m.group(2)))
b = int((m.group(3)))
RGB = r,g,b
hexa = "".join(map(chr, RGB)).encode('hex') # converts tuple from rgb form to hex value
color = re.sub(hexa, "#"+hexa, hexa) # replaces hex value with the same value plus a leading #
pixelHash = {'ID': ID, 'xpos': str(column), 'ypos': str(row), 'color': color, 'url':"" }
collection.insert(pixelHash) # insert this pixel into the db
getcolors()
Give user an unadopted pixel
Finds all the pixels in the db with no url associated. Picks one at random and gives it to the user, with an input form for them to enter the url where they have put it.
#!/usr/bin/python
#-*- coding:utf-8 -*-
import cgi
import cgitb; cgitb.enable()
import pymongo, random
from pymongo import Connection
## grab a random unadopted pixel from the database and give user a unique string for it
connection = Connection()
myDB = connection['pixelDbQuery1']
#--------- some db queries for testing------------#
# print whole db thus:
#for entry in myDB.collection.find():
# print entry
#myDB.collection.update( {"id":"2"}, {"$set":{"url": "ovulation.com"}}) # update url of entry with id '2'
#print myDB.collection.find({"id": "2"})["color"]
#--------- generate pixel string ------------#
# find all entries where url is empty:
unadopted = []
for entry in myDB.collection.find({"url": ""}):
unadopted.append(entry) # add this pixel's hash as an item to the 'unadopted' dictionary
#print unadopted
howMany = len(unadopted) # find out how many items in 'unadopted' list
#print howMany
random = random.randint(0,howMany) # pick a random number in this range
#print random
pixelHash = unadopted[random] # ...and choose the pixel at this index
#print pixelHash
pixelString = "ID=" + str(pixelHash['ID']) + ";x=" + pixelHash['xpos'] + ";y=" + pixelHash['ypos'] + ";col=" + pixelHash['color']
#print pixelString
#--------- print input form with pixel string ------------#
htmlHeader = """<!DOCTYPE html>
<html>
<head>
<title>Adopt a Pixel</title>
<link <link rel="stylesheet" href="../../pixels.css">
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'>
</head>
<body>"""
print "Content-Type: text/html"
print
print htmlHeader
print """
<h1>the DISSOLUTE IMAGE</h1>
<div class="main">
<div class="menu">
<ul class="menuList">
<li><a href="pixelsShowImage.cgi">Home</a></li>
<li><a href="../../forbiddenPixels/pixelsAbout.html">About</a></li>
<li>Host a Pixel</li>
</ul>
</div>
</div>
<div class="heading">Host a Pixel</div>
<div class="rightBox" style="">
<div class="pixelInfo">
You'll be hosting pixel <strong>""" + str(pixelHash['ID']) + """</strong> out of a total 95600. Enlarged preview:
<div id="pixelPreview" style="background-color: """ + pixelHash['color'] + """">
</div>
<div class="pixelDetails">
Here are the unique details for your pixel: <br />
</div>
<form action="pixelsScrapeAndVerify.cgi" name="inputForm">
<input name="pixel" class="pixelInput" value=""" + pixelString + """><br />
<div class="inputBox">
To host this pixel, just copy & paste the details above<br /> somewhere public on the web, exactly as they appear.<br />
Then tell us the full URL of the page where you pasted them:<br />
</div>
</span>
URL: <input name="url" class="urlInput" value="">
<input type="submit" value="OK">
</form>
<div class="">
Your pixel will appear in the image for as long as the text remains at this URL.
</div>
</div>
</body>
</html>"""
Verify the url submitted by user
Scrapes the url given by the user to see if the right pixel can be found there. If yes, that url gets associated with the appropriate pixel in the db so it no longer comes up for adoption. The pixel is then added to the image via a system call to Imagemagick.
#!/usr/bin/python
#-*- coding:utf-8 -*-
import cgi
import os, subprocess, re, urllib2
import cgitb; cgitb.enable()
import pymongo
from pymongo import Connection
# recieves url from inputForm.html scrapes it to check if pixel has been put there correctly
# if yes = updates db entry for that pixel
# if no = throws error
#-------------- error / thank you messages ----------------#
htmlHeader = """<!DOCTYPE html>
<html>
<head>
<title>A form talking to a python script</title>
<link <link rel="stylesheet" href="../../pixels.css">
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'>
</head>
<body>
<h1>the DISSOLUTE IMAGE</h1>
<div class="main">
<div class="menu">
<ul class="menuList">
<li><a href="../mongo/pixelsShowImage.cgi">Home</a></li>
<li><a href="../../forbiddenPixels/pixelsAbout.html">About</a></li>
<li><a href="../cgi-bin/mongo/pixelsShowUnadoptedPixel.cgi">Host a Pixel</a></li>
</ul>
</div>
<div class="rightBox">
"""
htmlFooter = """
</div>
</div>
</body>
</html>"""
scrapingError = """Sorry, your pixel details couldn't be found at that URL! <br />
<ul>
<li>Did you paste them exactly as they appear?</li>
<li>Did you give the URL for the specific page or tweet where you pasted them?</li>
<li>Is the page where you pasted them publicly accessible?</li>
</li>
<br />
Use your browser's back button to try again, or <a href="pixelsShowUnadoptedPixel.cgi">try another pixel</a>.
"""
verifyError = """Sorry, the details you've put online for that pixel seem to be wrong. <br />
<ul>
<li>Did you paste the pixel details exactly as they appear?</li>
</ul>
<br />
Use your browser's back button to try again, or <a href="pixelsShowUnadoptedPixel.cgi">try another pixel</a>."""
thankyou = """<strong>Thanks, URL submitted.</strong><br /><br />
Your pixel has been added to the image,<br /> and will remain there as long as you keep your pixel details online."""
#------------- get URL from input form -------------------#
form = cgi.FieldStorage() # Grabs whatever input comes from form
string = form.getvalue("pixel")
#TODO check if valid url/protocol given. urllib2 bit breaks if not.
url = form.getvalue("url", "http://ox4.org/~nor/trials/hostedString.html") # assigns form's input to var 'url'. url on the right is a default value that will be printed for testing if nothing is recieved from the form
#for testing:
#string = r"ID=65;x=4;y=3;col=red"
#url = "http://ox4.org/~nor/trials/hostedString.html"
#------------- print html header--------------------------#
print "Content-Type: text/html"
print
print htmlHeader
#------------ define splitting function-------------------#
# to split user's string into a hash which can be verified against the one in db
def splitString (stg) :
pat = re.compile("(\w{1,4}=[^;]+);?") # captures each foo=blah pair in the string, separated by ;s
cap = pat.findall(stg) # cap variable contains all four captures - id, x, y, color (if valid)
# put captures into a hash for this pixel
myhash = {}
for s in cap :
# print s
k,v = s.split('=') # splits each capture on the = into key and value
myhash[k] = v # puts new k/v pair into hash with these values
# return hash so it can be compared with that in the db
try :
myhash['ID'] and myhash['x'] and myhash['y'] and myhash['col']
except:
return # missing parameter! return nothing
return myhash # returns a hash as above, accessed thus: split['x'] etc
#print splitString(string)
#
##------------- scrape and check the url -----------------#
## if correct string not found, throw error
## if found, print thankyou and update db
#connect to db for verification, and possible updating
connection = Connection()
myDB = connection['pixelDbQuery1']
collection = myDB.collection
text = urllib2.urlopen(url).read() # reads page at the specified URL
##print text
# this returns only true or false:
# TODO change regex method to only scrape the first instance of string on a page
if not re.search(string, text): # if string isn't matched within 'text'
print scrapingError # print error message to user
else:
# check if .search has returned an array (ie, if more than one match was found). if so, only look at array[0] OR find a way to only scrape 1st one (.match one?)
split = splitString(string) # calls split string function, passing it the string recieved from the input form, and assigns it to var 'split'
if split:
idNo = int(split['ID']) # get idNo according to user's string; cast as int to compare with db
pixelHash = myDB.collection.find_one({'ID': idNo}) # this grabs a hash with the right id number (if valid), whose index thingies you can access
if pixelHash:
# now check if attributes from string recieved (xpos, ypos) match attributes for that ID in DB?
if split['x'] == pixelHash['xpos'] and split['y'] == pixelHash['ypos']:
# print "correct x and y value given"
collection.update( {'ID': idNo}, {"$set":{'url': url}}) # set pixel with string matching 'pat' to url given by user
# draw a new pixel onto the img with a syscall
color = split['col']
x = str(split['x'])
y = str(split['y'])
command = """convert ../../forbiddenPixels/images/dissolute1.png -fill '""" + color + """' -draw 'point """ + x + "," + y + """' ../../forbiddenPixels/images/dissolute2.png"""
#print command
os.popen(command, 'r').read()
print thankyou
else:
print verifyError
else: print verifyError
else:
print verifyError
print htmlFooter