Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PR2 Sim Map Publisher
- #By Devil6Lair
- import sys
- import urllib.request #required for getting newest data
- import time #used to wait x time before checking
- import datetime
- import pyautogui
- import random
- sim_letter = input("Enter the sim letter of the last published map: ")
- sim_num = int(input("Enter the sim number of the last published map: "))
- print("Steps to get account name")
- print("Publish a map to newest page 1 and go to")
- print("pr2hub.com/files/lists/newest/1 and look at it in a text editor")
- print("then find the username assoicated with your level you just published")
- print("the username required is the part after \"userName0=\"")
- acc_name = input("Enter the account name: ")
- pyautogui.PAUSE = 0.5 #5 second pause between each automation
- while sim_num != 54 or sim_letter != "C":
- try:
- with urllib.request.urlopen("https://pr2hub.com/files/lists/newest/1") as response:
- data = str(response.read()) #get newest data
- except:
- print("Error (timeout most likely) with url fetch")
- data = acc_name * 3 #don't publish if couldn't get newest data
- num_sim_maps = data.count(acc_name) #number of your sim maps on page 1
- print("Number of sim maps on page 1: {0}".format(num_sim_maps))
- print(datetime.datetime.now())
- if num_sim_maps < 3: #only allows 3 on page total
- index = data.index("userName0=")
- if data[index+10:index+10+len(acc_name)] != acc_name: #check if I published last map
- ##changes vars for chaning title to next map
- if sim_num == 54: #change to next set of 54
- if sim_letter == "B":
- sim_letter = "A"
- elif sim_letter == "A":
- sim_letter = "D"
- elif sim_letter == "D":
- sim_letter = "C"
- elif sim_letter == "C": #if letter C and num 54 then done
- print("All Levels have been published")
- print("Program now stopping")
- sys.exit()
- else: #catch unexpected and stop
- print("An unexpected value appeared in sim_letter")
- print("The Char was: {0}".format(sim_letter))
- sys.exit()
- sim_num = 1 #set number to 1 for next set
- elif sim_num < 54 and sim_num > 0: #just need to +1
- sim_num += 1
- else: #catch unexpected and stop
- print("An unexpected value appeared in sim_num")
- print("The value was: {0}".format(sim_num))
- sys.exit()
- print("Starting Automation")
- pyautogui.click(x=842,y=5) #click window to make sure focussed
- #auto publish new map
- pyautogui.click(x=500,y=954) #click save button
- pyautogui.click(x=905,y=428) #click in title field
- pyautogui.keyDown("ctrlleft")
- pyautogui.press("a")
- pyautogui.keyUp("ctrlleft")
- pyautogui.press("del") #delete current title fully
- pyautogui.typewrite("{0}-Sim {1}".format(sim_letter,sim_num), interval=0.25) #write new title
- pyautogui.click(x=828,y=825) #click submit
- upload_work = None
- print("before image check")
- iteration = 1
- while upload_work == None: #wait unless success
- print("Interation to check for success: {0}".format(iteration))
- if iteration > 99:
- print("Couldn't find success window for upload")
- print("Program stopping")
- sys.exit()
- upload_work = pyautogui.locateCenterOnScreen("SaveSuccessful.png")
- iteration += 1
- pyautogui.click(x=949,y=703) #click ok button to return to original
- else:
- print("Published last map, waiting until not the case to seem less spammy")
- print(sim_num) #debug
- print(sim_letter) #debug
- print(sim_num != 54 or sim_letter != "C") #debug loop
- x = random.randrange(3,7)
- time.sleep(90+x) #just to seem less automatic
- print("Finished publish via exiting while loop")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement