-
Notifications
You must be signed in to change notification settings - Fork 0
/
valorant1.py
129 lines (83 loc) · 3.41 KB
/
valorant1.py
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
import json
import time
import csv
import pandas
from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.select import Select
#driver initiation
options=Options()
options.add_experimental_option("detach",True)
options.add_argument("--headless=new")
driver=webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
#interactive terminal commands
file=open("valhistory1.json",'a+')
print("Welcome to valorant profile finder.")
print()
print("\n\n")
print("Please choose your region(1/2/3/4) or retrieve player data from file")
print("\n\n")
print("1.APAC\n2.Europe\n3.North America \n4.Retrieve the last player's data")
#csv file writer and opener modules
def csvwrite(listobj):
with open('valhistory1.json', 'w') as file:
json.dump(listobj,file,indent=2)
def csvread(listobj):
with open('valhistory1.json','r') as file:
listobj=json.load(file)
return listobj
#browser driver definition here
def valdriver(usern,usert,reg):
driver.get("https://docs.henrikdev.xyz/valorant.html")
select_element=driver.find_element(By.ID,"SelectMMR")
select=Select(select_element)
#fetch elements from the API
select.select_by_visible_text(reg)
driver.find_element(By.ID,"MMRName").send_keys(usern)
driver.find_element(By.ID,"MMRTag").send_keys(usert)
driver.find_element(By.ID,"buttonmmr").click()
time.sleep(3)
text=driver.find_element(By.ID,"mmrresponse").text
return text
### after-API interactive terminal definition
def datasave():
print("Player data can be stored so that it does not have to be searched repeatedly")
print("Do you want to save this players data? Y/N")
response=str(input())
if response=="Y":
csvwrite([username,usertag,region])
else:
print("Invalid response")
#terminal interaction definition
choice=int(input())
if choice==1:
region="ap"
username=str(input("Enter the username of the player. (the part of the id that comes before the # eg SillyGooose in SillyGooose#4078): "))
usertag=str(input("Please enter the tag of the player( the part of the id that comes after # eg: SillyGooose#4078)"))
text=valdriver(username,usertag,region)
print(text)
datasave()
elif choice==2:
region="eu"
username=str(input("Enter the username of the player. (the part of the id that comes before the # eg SillyGooose in SillyGooose#4078): "))
usertag=str(input("Please enter the tag of the player( the part of the id that comes after # eg: SillyGooose#4078)"))
text=(valdriver(username,usertag,region))
print(text)
datasave()
elif choice==3:
region="na"
username=str(input("Enter the username of the player(the part of the id that comes before the # eg SillyGooose in SillyGooose#4078): "))
usertag=str(input("Please enter the tag of the player( the part of the id that comes after # eg: SillyGooose#4078)"))
text=valdriver(username,usertag,region)
print(text)
datasave()
elif choice==4:
newlist=[]
newlist=csvread(newlist)
print(valdriver(newlist[0],newlist[1],newlist[2]))
else:
raise(ValueError("Please enter the correct value type."))