timeout=5 passed=False while not passed: #fetching unique UUID for hit to be created in MTurk guid=row[2] mturk_hittype_id=row[8] operation="CreateHIT" parameters2={ "HITTypeId":mturk_hittype_id, 'Question':'<ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd"><ExternalURL>'+web_endpoint+'</ExternalURL><FrameHeight>1600</FrameHeight></ExternalQuestion>', 'LifetimeInSeconds':settings["lifetimeinseconds"], "MaxAssignments":settings["max_assignments"], "UniqueRequestToken":guid, } output= mturk.call_turk(operation, parameters2) try: mturk_hit_id=mturk.get_val(output, "HITId") passed=True except: passed=False timeout=timeout*2 print "Sleep for %s seconds " % (timeout) sleep(timeout) logging.info("new HIT created with id: %s" % (mturk_hit_id)) sql="UPDATE hits SET mturk_hit_id=%s, assignments=%s WHERE uuid=%s;" cur2.execute(sql,(mturk_hit_id, settings["max_assignments"], guid)) conn.commit()
operation = "RegisterHITType" settings["vocabularyHITtype"]["Description"] = ( u"Translate 10 words from " + langs_properties[lang]["name"] + u" to English").encode('utf-8') settings["vocabularyHITtype"]["Title"] = (u"Translate 10 words from " + langs_properties[lang]["name"] + u" to English").encode('utf-8') settings["vocabularyHITtype"]["Keywords"] = ( u"translation, vocabulary, dictionary, " + langs_properties[lang]["name"] + u", English, language, research, JHU").encode('utf-8') parameters2 = settings["vocabularyHITtype"] output = mturk.call_turk(operation, parameters2) logging.debug("RegisterHITType response: %s" % (output)) mturk_hittype_id = mturk.get_val(output, "HITTypeId") logging.info("HIT type for language: %s created with id: %s" % (lang, mturk_hittype_id)) sql = "SELECT add_hittype (%s, %s, %s, %s);" cur.execute(sql, ("Vocabulary HIT for " + langs_properties[lang]["name"], mturk_hittype_id, lang_id, "vocabulary 2")) hittype_id2 = cur.fetchone()[0] conn.commit() langs_properties[lang]["hittype_id"] = hittype_id2 sql = "SELECT id from hittypes where language_id=%s and typename='vocabulary';" cur.execute(sql, (lang_id, ))