-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtf2c.py
More file actions
145 lines (119 loc) · 4.9 KB
/
tf2c.py
File metadata and controls
145 lines (119 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium_stealth import stealth
import geckodriver_autoinstaller
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import json
import time
import winsound
#CONFIGURATION
config = {
"FirefoxProfilePath" : "",
"region" : "EU",
"mumble" : 0,
"gameType" : "6v6"
}
classes_to_play = ['roamer' , 'pocket']
maps_to_play = []
def load_selenium_geckodriver(firefox_profile_path):
profile = webdriver.FirefoxProfile(firefox_profile_path)
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX
driver = webdriver.Firefox(firefox_profile=profile, desired_capabilities=desired)
return driver
blu_scout1 = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[1]/div[2]/div"
blu_scout2 = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[1]/div[3]/div"
blu_roamer = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[1]/div[4]/div"
blu_pocket = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[1]/div[5]/div"
blu_demo = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[1]/div[6]/div"
blu_med = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[1]/div[7]/div"
red_scout1 = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[3]/div[2]/div"
red_scout2 = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[3]/div[3]/div"
red_roamer = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[3]/div[4]/div"
red_pocket = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[3]/div[5]/div"
red_demo = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[3]/div[6]/div"
red_med = "/html/body/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[2]/div/div/div/div[3]/div[7]/div"
def class_to_xpath(team, user_class):
xpath = ""
if (team == "blue"):
if (user_class == "scout"):
xpath = blu_scout1
elif (user_class == "roamer"):
xpath = blu_roamer
elif (user_class == "pocket"):
xpath = blu_pocket
elif (user_class == "demo"):
xpath = blu_demo
elif (user_class == "med"):
xpath = red_med
else:
if (user_class == "scout"):
xpath = red_scout1
elif (user_class == "roamer"):
xpath = red_roamer
elif (user_class == "pocket"):
xpath = red_pocket
elif (user_class == "demo"):
xpath = red_demo
elif (user_class == "med"):
xpath = red_med
return xpath
def load_lobby(lobbyid, team, tf2class, tf2map):
driver.get('https://tf2center.com/lobbies/' + str(lobbyid))
xpath = class_to_xpath(team, tf2class)
driver.find_element_by_xpath(xpath).click()
print ("Obtained spot on " + tf2map + " as " + team + " " + tf2class)
def search_lobbies(json, hours_played, lobbies_played):
global lobbyid
global team
global tf2class
global tf2map
for x in json:
if (x["gameType"] == config["gameType"] and x["region"] == config["region"] and x["mumbleRequired"] == config["mumble"] and x["advanced"] == 0):
if (maps_to_play and any(maptf2 in x["map"] for maptf2 in maps_to_play) == False):
continue
for c in x["slots"]:
if (c["tf2Class"] in classes_to_play):
for z in c["availableSlots"]:
if (z["reserved"] == False):
if "games" in z["restrictions"] and z["restrictions"]["games"] > int(lobbies_played):
continue
if "hours" in z["restrictions"] and z["restrictions"]["hours"] > int(hours_played):
continue
lobbyid = x["no"]
team = z["team"]
tf2class = c["tf2Class"]
tf2map = x["map"]
return
def get_data_between(data, start, end):
result = ""
start = current_src.partition(start)[-1]
result = start.partition(end)[0]
return result
driver = load_selenium_geckodriver(config["FirefoxProfilePath"])
driver.get("https://tf2center.com/lobbies/")
if "const mySteamId='';" in driver.page_source:
input("Log in to steam to continue.")
else:
print("Logged in.")
while(1):
lobbyid = 0
current_src = driver.page_source
if "replaceAllLobbies" in current_src:
raw_json = get_data_between(current_src, "replaceAllLobbies(", ");</script>")
lobbies_played = get_data_between(current_src, "const myLobbiesPlayed=", ";")
hours_played = get_data_between(current_src, "const myTotalHoursPlayed=", ";")
data = json.loads(raw_json)
search_lobbies(data, hours_played, lobbies_played)
if (lobbyid != 0):
winsound.Beep(3000, 800)
print("Lobby found.")
load_lobby(lobbyid, team, tf2class, tf2map)
input("Enter to requeue")
driver.get("https://tf2center.com/lobbies/")
time.sleep(3)
driver.execute_script("window.top.location = window.top.location")