-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselenium_bot.py
More file actions
138 lines (108 loc) · 3.71 KB
/
selenium_bot.py
File metadata and controls
138 lines (108 loc) · 3.71 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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
# from selenium.common.exceptions import TimeoutException
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.support.ui import Select
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support import expected_conditions
# from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
import datetime
options = webdriver.ChromeOptions()
options.add_argument("--disable-notifications")
options.add_argument('--headless')
# to open chrome webbrowser and maximize the window
driver = webdriver.Chrome(chrome_options=options)
# Implicit Wait when element is taking time to load
driver.implicitly_wait(2)
# connect to the specific ip address
def connect(login, password):
driver.get("http://www.facebook.com")
a = driver.find_element_by_id('email')
a.send_keys(login)
b = driver.find_element_by_id('pass')
b.send_keys(password)
c = driver.find_element_by_id('loginbutton')
c.click()
def reply_messages(command):
if command == "!BOT":
return "Wiadomosc na !BOT"
if command == "!BTC":
return "Aktualny kurs BTC to " + "X $"
def crypto_course(waluta):
return
def dzien_tygodnia():
dzien_tygodnia = datetime.datetime.now().strftime("%A")
return dzien_tygodnia
def numer_tygodnia():
numer_tygodnia = datetime.datetime.now().strftime("%U")
return int(numer_tygodnia)
def iseven(week_number):
if week_number % 2 == 0:
return "2/4"
else:
return "1/3"
# print(iseven(numer_tygodnia()))
planzajec = [
{
"przedmiot": "Programowanie",
"sala": "208 B4",
"rozpoczecie": "8:00",
"zakonczenie": "9:30",
"tydzien": "1/3",
"dzien_tyg": "Tuesday",
},
{
"przedmiot": "Metodyka",
"sala": "243 B1",
"rozpoczecie": "9:45",
"zakonczenie": "11:15",
"tydzien": "2/4",
"dzien_tyg": "Tuesday"
},
{
"przedmiot": "Metodyka",
"sala": "243 B1",
"rozpoczecie": "9:45",
"zakonczenie": "11:15",
"tydzien": "2/4",
"dzien_tyg": "Tuesday"
}
]
# print(dzien_tygodnia())
wiadomosc_bota = ["Zajęcia dziś \n "]
# Dodawanie planu zajec do wiadomosci_bota
for zajecia in planzajec:
if zajecia["dzien_tyg"] == dzien_tygodnia() and zajecia["tydzien"] == iseven(numer_tygodnia()):
print(zajecia["przedmiot"])
print(zajecia["rozpoczecie"])
print(zajecia["sala"])
# print(iseven
wiadomosc_bota += zajecia["przedmiot"] + " " + zajecia["rozpoczecie"] + " " + zajecia["sala"] + " "
# sleep(20)
connect("login", "password")
driver.get("https://www.facebook.com/messages/t/1974449535911266")
sleep(2)
# driver.find_element_by_xpath("//*[@data-editor]").click()
# actions = ActionChains(driver)
# actions.send_keys(wiadomosc_bota)
# actions.send_keys(Keys.RETURN)
# actions.perform()
# profilePicList = driver.find_elements_by_xpath('//*[@id="js_1"][@type="text"]')
while True:
wiadomosci=driver.find_element_by_xpath('//*[@id="js_1"]')
dane_text=wiadomosci.text
dane_lista=dane_text.split('\n')
print(dane_lista)
if dane_lista[-1] == "!BOT":
# print("Pasuje odpisac na wiadomosc: " + dane_lista[-1])
driver.find_element_by_xpath("//*[@data-editor]").click()
actions=ActionChains(driver)
# actions.send_keys(reply_messages(dane_lista[-1]))
actions.send_keys(wiadomosc_bota)
actions.send_keys(Keys.RETURN)
actions.perform()
sleep(10)
# wiadomosc=driver.find_element_by_xpath('//*[@id="js_1"]')
# print(wiadomosc.text)