Advertisement
Guest User

Last Gasp Generator Generator Generator

a guest
Aug 18th, 2016
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None
  1. def generateLink(lists, numToGen=1, sentenceStart='', useNumbers=False):
  2. output = """javascript:(function(){var output= "";"""
  3. output += """var lists = """ + str(lists).replace("'", "\"")+';'
  4. output += "output += '\\n"+sentenceStart+"\\n\\n';"
  5. output += "for(var x=0; x<" + str(numToGen) + "; x++){"
  6. if useNumbers:
  7. output += "output += (x + 1) + ') ';"
  8. output += "for(var c=0; c<lists.length; c++){"
  9. output += "output += (lists[c][Math.floor(Math.random()*lists[c].length)])+' ';}"
  10. output += "output += '\\n';};"
  11. output += "alert(output);})();"
  12. return output
  13.  
  14. def printReadableCode(jsString):
  15. outString = ''
  16. indent = 0
  17. for char in jsString:
  18. if char == '{':
  19. indent += 1
  20. outString += char + '\n' + '\t'*indent
  21. elif char == '}':
  22. indent -= 1
  23. outString = outString[:-1] + char + '\n' + '\t'*indent
  24. elif char == ';' and not forLoopFlag:
  25. outString += char + '\n' + '\t'*indent
  26. else:
  27. outString += char
  28.  
  29. if char == '(':
  30. forLoopFlag = True
  31. if char == ')':
  32. forLoopFlag = False
  33. print outString
  34.  
  35. def main():
  36. numToGen = 5
  37. useLineNumbers = True
  38. sentenceStart = "A Plague of:"
  39. lists = [["Horses","Dogs","Rats","Bats","Sparrows","Children","Tiny Green Beetles","Tiny Green Children","Worms","Mushrooms","Ooze","Wind"],
  40. ["Trampling","Tainting","Devouring","Attacking","Stealing","Destroying","Eroding","Poisoning","Infecting","Bewitching","Absorbing","Carrying Off"],
  41. ["Crops","Water","Food","Livestock","Restful Sleep","Children","Vows","Friendship","Husbands","Townsfolk","Houses","Everything"]]
  42.  
  43. jsString = generateLink(lists, numToGen, sentenceStart, useLineNumbers)
  44. print jsString
  45. print '---------------------------------'
  46. printReadableCode(jsString)
  47.  
  48.  
  49. if __name__ == "__main__":
  50. main()
Advertisement
RAW Paste Data Copied
Advertisement