forked from taiQui/bot_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epic_free.py
102 lines (94 loc) · 3.21 KB
/
epic_free.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
import requests
from selenium import webdriver
from threading import Thread,RLock
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from datetime import datetime
import asyncio
import time
import discord
class Epic_Free(Thread):
def __init__(self):
Thread.__init__(self)
self.found = False
self.close= "N"
self.url = "https://www.epicgames.com/store/en-US/free-games"
self.game = []
self.gameTook = False
self.error = ""
def run(self):
print("[EPIC] Running Epic free thread !")
while True:
self.getGames()
self.waitTime()
if self.close == "N":
if self.found:
self.found = False
self.gameTook = False
self.game = []
#wait 1 day
time.sleep(3600*24)
elif self.close == "A":
#wait 10 hours
time.sleep(3600*10)
elif self.close == "Y":
#wait 1hours
time.sleep(3600)
elif self.close == "F":
if not self.found:
self.found = True
self.getGames()
else:
time.sleep(60)
# Found the good time to execute
def waitThursday(self):
return datetime.today().strftime("%A")=="Thursday"
def waitWednesday(self):
return datetime.today().strftime("%A")=="Wednesday"
def wait14PM(self):
today = datetime.today()
today = today.strftime("%H")
return int(today) >= 14
def waitTime(self):
if self.waitWednesday():
self.close = "A"
elif self.waitThursday():
if self.wait14PM():
self.close = "F"
else:
self.close = "Y"
else:
self.close = "N"
def getGames(self):
print('[EPIC] Start fetching game')
l = []
try:
options = Options()
options.add_argument('--headless')
driver = webdriver.Firefox('.',options=options)
driver.get(self.url)
start = time.time()
print('[EPIC] Gecko started')
while True:
try:
a = driver.find_element_by_class_name('css-1u5k6xy')
break
except:
if time.time() - start > 60:
return None
pass
i = driver.find_element_by_class_name('CardGrid-groupWrapper_e669488f')
for j in i.find_elements_by_tag_name('a'):
if j.get_attribute('href') != "https://www.epicgames.com/store/en-US/free-games":
link = j.get_attribute('href')
game = link.split('/')[-1]
k = i.find_element_by_tag_name('img')
img = k.get_attribute('src')
l.append((game,img,link))
driver.close()
self.game = l
print('[EPIC][+] found free game')
except Exception as e:
self.game = []
self.error = e
return None