-
Notifications
You must be signed in to change notification settings - Fork 0
/
Instagram_and_facebook.py
68 lines (66 loc) · 2.24 KB
/
Instagram_and_facebook.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
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
import keyboard
import re
import pyautogui
def facebook():
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)
driver.get("https://www.facebook.com")
time.sleep(2)
keyboard.write("")#Enter your email here
pyautogui.press("tab")
keyboard.write("")#Enter your password here
time.sleep(0.7)
pyautogui.press("tab")
time.sleep(0.7)
pyautogui.press("tab")
pyautogui.press("enter")
time.sleep(7)
htm = driver.page_source
k = str(re.search("aria-label=\"Messenger(.*)\"", htm))
last_char_index = k.rfind("\"")
k = k[:last_char_index] + "," + k[last_char_index + 1:]
k = k[k.index("ger") + 4:k.rfind("\"")]
res = [int(i) for i in k.split() if i.isdigit()]
try:
res = str(res[0])
except:
res = ""
if res == "":
k = "Sir you are all caught up"
else:
if res == "1":
k = "Sir you have {} new message".format(res)
else:
k = "Sir you have {} new messages".format(res)
return k
def instagram():
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)
driver.get("https://www.instagram.com")
time.sleep(2)
pyautogui.press("tab")
pyautogui.press("tab")
keyboard.write("")#Enter your email here
pyautogui.press("tab")
keyboard.write("")#Enter your password here
time.sleep(0.4)
pyautogui.press("tab")
time.sleep(0.4)
pyautogui.press("tab")
pyautogui.press("enter")
time.sleep(7)
htm = driver.page_source
try:
k = htm[htm.index("bqXJH\">")+7:]
k = k[:k.index("<")]
k = "Sir you Have {} new messages".format(k)
except:
k = "You are all caught up sir"
return k