-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewardme.py
More file actions
130 lines (103 loc) · 3.34 KB
/
rewardme.py
File metadata and controls
130 lines (103 loc) · 3.34 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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import random
from importconfig import get_config
def search(driver, word):
"""
Searches for a set word and returns the driver at the bing search page
:param driver: current selenium web driver
:param word: current word to be searched
:return: return a webdriver at the bing search page
"""
search_field = driver.find_element_by_id("sb_form")
search_field.click()
search_field = driver.find_element_by_name("q")
# enter search textbox
search_field.send_keys(str(word))
search_field.submit()
try:
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "b_content")))
finally:
to_bing(driver)
def to_bing(driver):
"""
Returns the webdriver to bing.com
:param driver: current webdriver
:return: VOID
"""
driver.get("https://www.bing.com/")
try:
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "sbox")))
except:
print("ERROR")
def start():
"""
VOID FUNCTION, starts the search process assuming a correctly configured words.txt and config.cfg
:return:
"""
print("MicrosoftRewards V 1.0")
print("Loading Config...")
try:
user_list = get_config()
print("Word file opened...")
except:
print("Config could not be found or read. Please ensure you have a valid config.cfg in the root directory")
exit_quit()
print("Loading word file...")
word_file = "words.txt"
try:
words = open(word_file).read().splitlines()
print("Word file opened...")
except FileNotFoundError:
print("Could not open word file, are you sure you have a words.txt in the root directory?")
exit_quit()
for user in user_list:
execute(user, words)
def execute(user, words):
"""
For a set user execute searches with a given word list
:param user: current instantiated user class, see Users.py for more information
:param words: list of words
:return: VOID
"""
driver = start_browser()
# Eventually need to implement logging in, currently user just performs the same action regardless of current acct
# driver = microsoft_login(driver, user)
for i in range(user.get_num_times()):
current_word = random.choice(words)
search(driver, current_word)
to_bing(driver)
print("Successfully completed user {}".format(user.get_key()))
quit_browser()
def start_browser():
"""
Opens Edge browser and navigate to https://www.bing.com/
:return: return the instantiated web driver
"""
# Create new Edge session
driver = webdriver.Edge()
driver.implicitly_wait(10)
driver.get("https://www.bing.com/")
return driver
def microsoft_login(driver, user):
"""
Login to microsoft account
:param driver: current webdriver
:param user: current user to be logged in
:return: return updated webdriver
"""
return driver
def quit_browser(driver):
driver.quit()
def exit_quit():
"""
ERROR QUIT CASE
:return:
"""
print()
print("FATAL ERROR HAS OCCURRED, EXITING")
exit()
if __name__ == "__main__":
start()