Advertisement
Devil6Lair

PR2 - Sim Map Publisher Script

Apr 22nd, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.17 KB | None | 0 0
  1. #PR2 Sim Map Publisher
  2. #By Devil6Lair
  3.  
  4. import sys
  5. import urllib.request #required for getting newest data
  6. import time #used to wait x time before checking
  7. import datetime
  8. import pyautogui
  9. import random
  10.  
  11. sim_letter = input("Enter the sim letter of the last published map: ")
  12. sim_num = int(input("Enter the sim number of the last published map: "))
  13. print("Steps to get account name")
  14. print("Publish a map to newest page 1 and go to")
  15. print("pr2hub.com/files/lists/newest/1 and look at it in a text editor")
  16. print("then find the username assoicated with your level you just published")
  17. print("the username required is the part after \"userName0=\"")
  18. acc_name = input("Enter the account name: ")
  19.  
  20. pyautogui.PAUSE = 0.5 #5 second pause between each automation
  21.  
  22. while sim_num != 54 or sim_letter != "C":
  23.     try:
  24.         with urllib.request.urlopen("https://pr2hub.com/files/lists/newest/1") as response:
  25.             data = str(response.read()) #get newest data
  26.     except:
  27.         print("Error (timeout most likely) with url fetch")
  28.         data = acc_name * 3 #don't publish if couldn't get newest data
  29.        
  30.     num_sim_maps = data.count(acc_name) #number of your sim maps on page 1
  31.     print("Number of sim maps on page 1: {0}".format(num_sim_maps))
  32.     print(datetime.datetime.now())
  33.     if num_sim_maps < 3: #only allows 3 on page total
  34.         index = data.index("userName0=")
  35.         if data[index+10:index+10+len(acc_name)] != acc_name: #check if I published last map
  36.             ##changes vars for chaning title to next map
  37.             if sim_num == 54: #change to next set of 54
  38.                 if sim_letter == "B":
  39.                     sim_letter = "A"
  40.                 elif sim_letter == "A":
  41.                     sim_letter = "D"
  42.                 elif sim_letter == "D":
  43.                     sim_letter = "C"
  44.                 elif sim_letter == "C": #if letter C and num 54 then done
  45.                     print("All Levels have been published")
  46.                     print("Program now stopping")
  47.                     sys.exit()
  48.                 else: #catch unexpected and stop
  49.                     print("An unexpected value appeared in sim_letter")
  50.                     print("The Char was: {0}".format(sim_letter))
  51.                     sys.exit()
  52.                 sim_num = 1 #set number to 1 for next set
  53.             elif sim_num < 54 and sim_num > 0: #just need to +1
  54.                 sim_num += 1
  55.             else: #catch unexpected and stop
  56.                 print("An unexpected value appeared in sim_num")
  57.                 print("The value was: {0}".format(sim_num))
  58.                 sys.exit()
  59.  
  60.             print("Starting Automation")
  61.             pyautogui.click(x=842,y=5) #click window to make sure focussed
  62.             #auto publish new map
  63.             pyautogui.click(x=500,y=954) #click save button
  64.             pyautogui.click(x=905,y=428) #click in title field
  65.             pyautogui.keyDown("ctrlleft")
  66.             pyautogui.press("a")
  67.             pyautogui.keyUp("ctrlleft")
  68.             pyautogui.press("del") #delete current title fully
  69.             pyautogui.typewrite("{0}-Sim {1}".format(sim_letter,sim_num), interval=0.25) #write new title
  70.             pyautogui.click(x=828,y=825) #click submit
  71.             upload_work = None
  72.             print("before image check")
  73.             iteration = 1
  74.             while upload_work == None: #wait unless success
  75.                 print("Interation to check for success: {0}".format(iteration))
  76.                 if iteration > 99:
  77.                     print("Couldn't find success window for upload")
  78.                     print("Program stopping")
  79.                     sys.exit()
  80.                 upload_work = pyautogui.locateCenterOnScreen("SaveSuccessful.png")
  81.                 iteration += 1
  82.             pyautogui.click(x=949,y=703) #click ok button to return to original
  83.  
  84.         else:
  85.             print("Published last map, waiting until not the case to seem less spammy")
  86.            
  87.     print(sim_num) #debug
  88.     print(sim_letter) #debug
  89.     print(sim_num != 54 or sim_letter != "C") #debug loop
  90.     x = random.randrange(3,7)
  91.     time.sleep(90+x) #just to seem less automatic
  92. print("Finished publish via exiting while loop")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement