In [1]:
import htmltag as HT
import random
from htmltag import table, td, tr

In [2]:
# Constants
maxImgs = 20

In [3]:
def genImageID(begin,stop):
    count = 0
    listNum = []
    start= begin
    end = stop
    while count < maxImgs:
        num = random.randrange(start,end)
        if num in listNum: continue
        listNum.append(num)
        count += 1
        
    return listNum

In [4]:
imageID = genImageID(1,100)
links = ["http://pachy.cs.uic.edu:5000/api/image/src/"+str(i)+"/?resize_pix_w=500" for i in imageID[0:maxImgs]]
imgTags = []
radioShare = HT.input
for url in links:
    imgTags.append(HT.img(src = url,alt = "Unavailable"))

In [8]:
# logic to create the radio buttons
hiddenField = []
shareRadio = []
notShareRadio = []

for i in range(maxImgs):
    hiddenField.append(HT.input(type='hidden',name=imageID[i],value=imageID[i]))
    shareRadio.append(HT.input(type='radio',value='share',name=imageID[i]) + "Share")
    notShareRadio.append(HT.input(type='radio',value='noShare',name=imageID[i]) + "Do Not Share")

In [9]:
tdTags = []
for i in range(maxImgs):
    tdTags.append(HT.td(HT.center(HT.HTML(hiddenField[i]),HT.HTML(shareRadio[i]),HT.HTML(notShareRadio[i])),HT.HTML(imgTags[i])))

trTags = []
for i in range(0,maxImgs,2):
    trTags.append(HT.tr(HT.HTML(tdTags[i]),HT.HTML(tdTags[i+1])))

In [21]:
bodyTxt = HT.table(HT.HTML('  \n'.join(trTags)),border="1")

In [22]:
print(bodyTxt)


<table border="1"><tr><td><center><input type="hidden" value="68" name="68"><input type="radio" value="share" name="68">Share<input type="radio" value="noShare" name="68">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/68/?resize_pix_w=500" alt="Unavailable"></td><td><center><input type="hidden" value="17" name="17"><input type="radio" value="share" name="17">Share<input type="radio" value="noShare" name="17">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/17/?resize_pix_w=500" alt="Unavailable"></td></tr>  
<tr><td><center><input type="hidden" value="26" name="26"><input type="radio" value="share" name="26">Share<input type="radio" value="noShare" name="26">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/26/?resize_pix_w=500" alt="Unavailable"></td><td><center><input type="hidden" value="77" name="77"><input type="radio" value="share" name="77">Share<input type="radio" value="noShare" name="77">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/77/?resize_pix_w=500" alt="Unavailable"></td></tr>  
<tr><td><center><input type="hidden" value="16" name="16"><input type="radio" value="share" name="16">Share<input type="radio" value="noShare" name="16">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/16/?resize_pix_w=500" alt="Unavailable"></td><td><center><input type="hidden" value="24" name="24"><input type="radio" value="share" name="24">Share<input type="radio" value="noShare" name="24">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/24/?resize_pix_w=500" alt="Unavailable"></td></tr>  
<tr><td><center><input type="hidden" value="11" name="11"><input type="radio" value="share" name="11">Share<input type="radio" value="noShare" name="11">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/11/?resize_pix_w=500" alt="Unavailable"></td><td><center><input type="hidden" value="80" name="80"><input type="radio" value="share" name="80">Share<input type="radio" value="noShare" name="80">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/80/?resize_pix_w=500" alt="Unavailable"></td></tr>  
<tr><td><center><input type="hidden" value="47" name="47"><input type="radio" value="share" name="47">Share<input type="radio" value="noShare" name="47">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/47/?resize_pix_w=500" alt="Unavailable"></td><td><center><input type="hidden" value="72" name="72"><input type="radio" value="share" name="72">Share<input type="radio" value="noShare" name="72">Do Not Share</center><img src="http://pachy.cs.uic.edu:5000/api/image/src/72/?resize_pix_w=500" alt="Unavailable"></td></tr></table>

In [23]:
headFile = open("files/header.txt","r")
tailFile = open("files/tail.txt","r")
outputFile = open("files/sampleMTurk.question","w")

for line in headFile:
    outputFile.write(line)
    
outputFile.write(bodyTxt)

for line in tailFile:
    outputFile.write(line)

headFile.close()
tailFile.close()
outputFile.close()

In [114]:


In [ ]: