-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautonotes.py
More file actions
80 lines (69 loc) · 2.45 KB
/
autonotes.py
File metadata and controls
80 lines (69 loc) · 2.45 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
import README
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import gkeepapi
from selenium.webdriver.common.action_chains import ActionChains
def itemize(items):
res = []
for item in items:
if item[-1] == '#':
res.append((item[:-1], True))
else:
res.append((item, False))
return res
class AutoNotes:
def __init__(self, whatsapp, qr_time):
self.driver = webdriver.Firefox() if README.browser else webdriver.Chrome()
self.web = whatsapp
self.qr_time = qr_time
self.keep = gkeepapi.Keep()
self.email = README.email
self.password = README.password
def get_notes(self):
self.driver.get(self.web)
time.sleep(self.qr_time)
xpath = "//*[@title='{}']".format(README.group_name)
elem = self.driver.find_element_by_xpath(xpath)
elem.click()
notes_ob = self.driver.find_elements_by_class_name("_3zb-j")
time.sleep(1)
notes = list(map(lambda note_ob: note_ob.text, notes_ob))
return notes
def clear_notes(self):
empty_chat = self.driver.find_element_by_class_name("wml2-")
action_chains = ActionChains(self.driver)
action_chains.context_click(empty_chat).perform()
time.sleep(1)
clear = self.driver.find_element_by_xpath("//*[@title='Clear messages']")
clear.click()
time.sleep(1)
delete = self.driver.find_element_by_xpath("//div[contains(text(),'Clear')]")
delete.click()
def close_driver(self):
self.driver.close()
def keep_log_in(self):
self.keep.login(self.email, self.password)
def keep_sync(self):
self.keep.sync()
def create_notes(self, notes):
for note in notes:
try:
title, text = note.split(' - ')
except:
print("Please write notes in the correct format.")
try:
star, title = title.split('*')
texts = text.split(', ')
items = itemize(texts)
self.keep.createList(title, items)
except:
self.keep.createNote(title, text)
if __name__ == '__main__':
auto_notes = AutoNotes('https://web.whatsapp.com', 7)
notes = auto_notes.get_notes()
auto_notes.clear_notes()
auto_notes.close_driver()
auto_notes.keep_log_in()
auto_notes.create_notes(notes)
auto_notes.keep_sync()