-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameGrabber.py
More file actions
192 lines (170 loc) · 7.49 KB
/
GameGrabber.py
File metadata and controls
192 lines (170 loc) · 7.49 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import discord
import os
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
import time
headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'}
PATH = "C:\Program Files (x86)\chromedriver.exe"
URL = ""
global count
count = 0
link = ["","","","","","","","","",""]
######## Discord Connect #############
client = discord.Client()
@client.event
async def on_ready():
print ('We have logged in as {0.user}'
.format(client))
@client.event
async def on_message(message):
global count
if message.author == client.user:
return
msg = message.content
if msg.startswith('$check'):
count = 1
gameReq = msg.split('$check ',1)[1]
#await message.channel.send('Price checking ' + gameReq.title() + '...')
await message.add_reaction('\U0001F911')
searchString = gameReq
steamSearchString = searchString.replace(" ", "+")
cdKeysSearchString = searchString.replace(" ", "%20")
g2aSearchString = searchString.replace(" ", "%20")
g2aSearchString += " GLOBAL"
############ STEAM ##########
URL = "https://store.steampowered.com/search/?term=" + steamSearchString + "&cc=ca"
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
containers = soup.find_all("a", {"class": "search_result_row ds_collapse_flag"})
reply = "***STEAM PRICES***\n**-----------------------------------------**\n"
print("STEAM PRICES")
print("-----------------------------------------")
i = 0
for container in containers:
if (i < 3):
name = container.findAll("span", {"class": "title"})
if container.findAll("div", {"class": "col search_price responsive_secondrow"}):
price = container.findAll("div", {"class": "col search_price responsive_secondrow"})
name = name[0].text
price = price[0].text
price = price.replace(" ", "").replace('\r', '').replace('\n', '').replace('CDN', '').replace('USD', '').replace('FreetoPlay', 'Free')
print(name + ' ----- ' + price)
reply += (str(count) + ". " + name.title() + ' **--------** ' + price + '\n')
print ("URL:", container['href'])
link[count] = ('steam://openurl/' + container['href'] + "?cc=ca")
count += 1
else:
price = container.findAll("div", {"class": "col search_price discounted responsive_secondrow"})
discount = container.findAll("div", {"class": "col search_discount responsive_secondrow"})
discount = discount[0].text
discount = discount.replace(" ", "").replace('\r', '').replace('\n', '').replace('-', '')
name = name[0].text
price = price[0].text
price = price.replace(" ", "").replace('\r', '').replace('\n', '').replace('CDN', '').replace('USD', '').replace('FreetoPlay', 'Free')
remove = (price[1:].index("$")) + 1
price = price[remove:]
print(name + ' -------- ' + price + ' **' + discount + ' OFF**')
reply += (str(count) + ". " + name.title() + ' **--------** ' + price + ' **' + discount + ' OFF**\n')
print ("URL:", container['href'])
link[count] = ('steam://nav/console' + container['href'] + "?cc=ca")
count += 1
i += 1
############## CD KEYS ##################
URL = "https://www.cdkeys.com/catalogsearch/result/?q="+ cdKeysSearchString +"&platforms=Steam®ion=Worldwide¤cy=CAD"
driver = webdriver.Chrome(PATH)
driver.get(URL)
content = driver.find_element_by_id("instant-search-results-container")
reply += "\n***CDKEYS PRICES***\n**-----------------------------------------**\n"
print("CDKEYS PRICES")
print("-----------------------------------------")
i = 0
while (i < 3):
results = content.find_elements_by_css_selector("li.ais-InfiniteHits-item.product-item__in-region")
if i < (len(results)):
results = results[i]
name = results.find_element_by_css_selector("h3.result-title.text-ellipsis")
price = results.find_element_by_css_selector("span.after_special")
links = results.find_element_by_css_selector("h3.result-title.text-ellipsis > a").get_attribute('href')
name = name.text
name = name.replace(' PC', '').replace(' -', '').replace(':', '')
price = price.text
price = price.replace('CA', '').replace('US', '')
print(name.title() + ' -------- ' + price)
link[count] = links
reply += (str(count) + ". " + name.title() + ' **--------** ' + price + '\n')
count += 1
i += 1
driver.quit()
############## G2A KEYS ##################
URL = "https://www.g2a.com/category/gaming-c1?f[drm][0]=1&query=" + g2aSearchString + "¤cy=CAD"
driver = webdriver.Chrome(PATH)
driver.get(URL)
content = driver.find_element_by_css_selector("section.indexes__ContentSlot-wklrsw-193.bbJYLf")
reply += "\n***G2A PRICES***\n**-----------------------------------------**\n"
print("G2A PRICES")
print("-----------------------------------------")
i = 0
while (i < 3):
name = content.find_elements_by_css_selector("h3.indexes__ve-wklrsw-118.jDoEKD.hTAfZi")
price = content.find_elements_by_css_selector("span.indexes__A1-wklrsw-93.jckuPr")
elems = content.find_elements_by_css_selector("div.indexes__I-wklrsw-91.indexes__ye-wklrsw-112.ggXzuE.jBmMTn > a")
links = [elem.get_attribute('href') for elem in elems]
if i < (len(price)):
name = name[i].text
name = name.replace(' Steam Key', '').replace(' Gift', '').replace(' Steam', '').replace(' GLOBAL', '').replace(' (PC)', '').replace(' -', '').replace(':', '')
price = price[i].text
price = "$" + price
print(name + ' -------- ' + price)
link[count] = links[i]
reply += (str(count) + ". " + name.title() + ' **--------** ' + price + '\n')
count += 1
i += 1
driver.quit()
await message.channel.send(reply)
if msg == '$1':
if count > 1:
reply = 'Link # 1'
print("Sending Link 1")
await message.channel.send(link[1])
if msg == '$2':
if count > 2:
reply = 'Link # 2'
print("Sending Link 2")
await message.channel.send(link[2])
if msg == '$3':
if count > 3:
reply = 'Link # 3'
print("Sending Link 3")
await message.channel.send(link[3])
if msg == '$4':
if count > 4:
reply = 'Link # 4'
print("Sending Link 4")
await message.channel.send(link[4])
if msg == '$5':
if count > 5:
reply = 'Link # 5'
print("Sending Link 5")
await message.channel.send(link[5])
if msg == '$6':
if count > 6:
reply = 'Link # 6'
print("Sending Link 6")
await message.channel.send(link[6])
if msg == '$7':
if count > 7:
reply = 'Link # 7'
print("Sending Link 7")
await message.channel.send(link[7])
if msg == '$8':
if count > 8:
reply = 'Link # 8'
print("Sending Link 8")
await message.channel.send(link[8])
if msg == '$9':
if count > 9:
reply = 'Link # 9'
print("Sending Link 9")
await message.channel.send(link[9])
client.run("TOKEN")