Advertisement
Alakazard12

Untitled

Nov 17th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. import codecs
  2. import urllib.parse
  3. import urllib.request
  4. import configparser
  5. import os.path
  6. import http
  7. import zlib
  8. import json
  9. import re
  10. import base64
  11. import time
  12. import random
  13.  
  14. url = "www.vocabulary.com"
  15. cookie = ""
  16. secret = ""
  17. config = configparser.ConfigParser()
  18. mchoice = re.compile(r"nonce\=\"([^\"]+)(.|\n)+?word=\"([^\"]+).+?")
  19. lastTime = time.time()
  20.  
  21.  
  22. def rpost(path, body = None, method = "POST"):
  23. global cookie
  24. client = http.client.HTTPSConnection(url, 443)
  25. client.request(method, path, body = body, headers = {
  26. "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0",
  27. "Accept-Language": "en-US,en;q=0.5",
  28. "Accept": "application/json, text/javascript, */*; q=0.01",
  29. "Accept-Encoding": "gzip, deflate, br",
  30. "DNT": "1",
  31. "Cookie": cookie,
  32. "Referer": "https://www.vocabulary.com/lists/1329479/practice",
  33. "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
  34. "Connection": "keep-alive"
  35. })
  36.  
  37. res = client.getresponse()
  38. data = res.read()
  39. if res.getheader("Content-Encoding") == "gzip":
  40. data = zlib.decompress(data, zlib.MAX_WBITS + 16)
  41.  
  42. return data
  43.  
  44.  
  45.  
  46. def answer(a):
  47. global secret
  48. time.sleep(random.randint(1, 6))
  49. params = "a=" + a + "&t=" + "{:.0f}".format(time.time() * 1000) + "&rt=" + "{:.0f}".format((time.time() - lastTime) * 1000) + "&secret=" + urllib.parse.quote(secret, safe = "")
  50. res = rpost("/challenge/saveanswer.json", params)
  51. data = json.loads(res.decode("utf-8"))
  52. secret = data["secret"]
  53.  
  54. def start():
  55. global secret
  56. res = rpost("/challenge/start.json", "secret=" + urllib.parse.quote(secret, safe = "")
  57. data = json.loads(res.decode("utf-8"))
  58. secret = data["secret"]
  59.  
  60.  
  61.  
  62. def handleText(data):
  63. adata = base64.b64decode(data["adata"].encode("utf-8")).decode("utf-8")
  64. adata = codecs.encode(adata, "rot_13")
  65. adata = json.loads(adata)
  66. print("answering with word " + adata["acceptedAnswers"][0])
  67. answer(adata["acceptedAnswers"][0])
  68.  
  69. def handleP(data):
  70. adata = base64.b64decode(data["adata"].encode("utf-8")).decode("utf-8")
  71. adata = codecs.encode(adata, "rot_13")
  72. adata = json.loads(adata)
  73. ans = adata["nonces"][0]
  74. print("answering with word " + ans)
  75. answer(ans)
  76.  
  77. def reset():
  78. rpost("/lists/" + config["Main"]["wordlistid"] + "/reset", method = "GET")
  79. print("RESET")
  80.  
  81. def next():
  82. global secret
  83. res = rpost("/challenge/nextquestion.json", "secret=" + urllib.parse.quote(secret, safe = ""))
  84. print(res.decode("utf-8"))
  85. data = json.loads(res.decode("utf-8"))
  86. secret = data["secret"]
  87.  
  88. # code = base64.b64decode(data["code"].encode("utf-8")).decode("utf-8")
  89. qtype = data["qtype"]
  90. print(qtype)
  91. if qtype == "T": # text box
  92. handleText(data)
  93. elif qtype == "S" or qtype == "P" or qtype == "F" or qtype == "A" or qtype == "D" or qtype == "L" or qtype == "H" or qtype == "I":
  94. handleP(data)
  95. elif qtype == "activityComplete":
  96. reset()
  97. else:
  98. print("COULD NOT ANSWER")
  99.  
  100.  
  101. def main():
  102. global cookie
  103. config["Main"] = {"AWSELB": "blank", "JSESSIONID": "blank", "_asid": "blank", "autologin": "1", "guid": "blank", "tz": "America/New_York", "wordlistid": "1329479"}
  104. if not os.path.isfile("config.ini"):
  105. with open("config.ini", "w") as configfile:
  106. config.write(configfile)
  107.  
  108. config.read("config.ini")
  109. cookie = "tz=" + config["Main"]["tz"] + "; _asid=" + config["Main"]["_asid"] + "; AWSELB=" + config["Main"]["AWSELB"] + "; JSESSIONID=" + config["Main"]["JSESSIONID"] + "; guid=" + config["Main"]["guid"] + "; autologin=" + config["Main"]["autologin"]
  110. print(cookie)
  111. start()
  112.  
  113. while (True):
  114. next()
  115. print("ANSWERED")
  116. time.sleep(random.randint(1, 2))
  117.  
  118. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement