-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_message
executable file
·65 lines (46 loc) · 1.56 KB
/
send_message
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
#!/usr/bin/env python
import requests
from selenium import webdriver
def get_reddit_link() -> str:
r = requests.post(
"https://www.reddit.com/api/v1/access_token",
data={
"grant_type": "https://oauth.reddit.com/grants/installed_client",
"device_id": "DO_NOT_TRACK_THIS_DEVICE",
},
auth=("ZJKlJzbFxkGauA", ""),
headers={"User-agent": "Muzei for reddit 0.1"},
)
token = r.json()["access_token"]
r2 = requests.get(
"https://api.reddit.com/r/rarepuppers/top?t=day&limit=1",
headers={
"User-agent": "Muzei for reddit 0.1",
"Authentication": "bearer {}".format(token),
},
)
j = r2.json()
return j["data"]["children"][1]["data"]["url"]
def main():
link = get_reddit_link()
options = webdriver.ChromeOptions()
options.add_argument("window-size=1200x800")
# options.add_argument('headless')
driver = webdriver.Chrome(
chrome_options=options,
executable_path="/mnt/c/ProgramData/chocolatey/bin/chromedriver.exe",
)
driver.get("https://web.whatsapp.com")
driver.implicitly_wait(10)
conversation = driver.find_element_by_xpath("//span[contains(.,'Strawberry')]")
conversation.click()
txt_box = driver.find_element_by_css_selector("._2S1VP")
txt_box.click()
txt_box.send_keys(f"Hola, un perrito: {link}")
driver.implicitly_wait(5)
btn = driver.find_element_by_css_selector("._35EW6")
btn.click()
driver.close()
driver.quit()
if __name__ == "__main__":
main()