├── requirements.txt ├── scripts └── read.sh ├── js ├── get_read.js └── get_unread.js ├── LICENSE ├── drivers └── README.md ├── .gitignore ├── README.md ├── CONTRIBUTING.md └── main.py /requirements.txt: -------------------------------------------------------------------------------- 1 | selenium==3.10.0 -------------------------------------------------------------------------------- /scripts/read.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Move to 'chat' folder and display the files 4 | cd ../chats 5 | ls 6 | 7 | # Enter the chat you want to enter 8 | echo "Enter the name of the chat you want to view." 9 | echo "->" 10 | read file_name 11 | cat $file_name -------------------------------------------------------------------------------- /js/get_read.js: -------------------------------------------------------------------------------- 1 | var chats = Store.Chat.models; 2 | 3 | var r = []; 4 | 5 | for (i in chats){ 6 | if(i>20) 7 | break; 8 | if(isNaN(i)) 9 | continue; 10 | var chat = {}; 11 | chat.name = chats[i]._values.formattedTitle; 12 | chat.messages = []; 13 | var messages = chats[i].msgs.models; 14 | var l = messages.length; 15 | for(var k=0;k Salman Shah 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /js/get_unread.js: -------------------------------------------------------------------------------- 1 | var chats = Store.Chat.models; 2 | 3 | var r = []; 4 | 5 | for (i in chats){ 6 | if(isNaN(i)) 7 | continue; 8 | 9 | var chat = {}; 10 | chat.name = chats[i]._values.formattedTitle; 11 | chat.messages = []; 12 | 13 | var messages = chats[i].msgs.models; 14 | var unread_count = chats[i]._values.unreadCount; 15 | var l = messages.length; 16 | 17 | if(chat.name==currentChat){ 18 | for(var k=l-1;k>=0;k--){ 19 | if(messages[k]._values.t <= last_seen || (messages[k].id.fromMe==true && messages[k]._values.body[0] != "\\")) 20 | break; 21 | var s; 22 | if(messages[k]._values.type=='chat') 23 | s = messages[k]._values.body; 24 | else 25 | s = '['+messages[k]._values.type.toUpperCase()+']'; 26 | chat.messages.push( 27 | { 28 | msg: s, 29 | t: messages[k]._values.t 30 | }); 31 | } 32 | chat.messages.reverse(); 33 | } 34 | else{ 35 | for(var k=l-unread_count;kTime for new features 11 | 12 | You can request a new feature by submitting an issue to our [Github Repository](https://github.com/salman-bhai). 13 | 14 | ## Bug reports 15 | 16 | A bug is a *demonstrable problem* that is caused by the code in the repository. Good bug reports are extremely helpful - thank you! 17 | 18 | Guidelines for bug reports: 19 | 20 | 1. **Use the GitHub issue search**. Check if the issue has already been reported. 21 | 22 | 2. **Check if the issue has been fixed**. Try to reproduce it using the latest master or development branch in the repository. 23 | 24 | 3. **Provide environment details**. Provide your operating system and browser(s). 25 | 26 | 4. **Create an isolated and reproducible test case**. Create a reduced test case. 27 | 28 | A good bug report shouldn't leave others needing to chase you up for more information. Please try to be as detailed as possible in your report. 29 | 30 | * What is your environment? 31 | * What steps will reproduce the issue? 32 | * What browser(s) and OS experience the problem? 33 | * What would you expect to be the outcome? 34 | **All these details** will help people to fix any potential bugs. 35 | 36 | ### Example: 37 | 38 | >Short and descriptive example bug report title 39 | >A summary of the issue and the browser/OS environment in which it occurs. If suitable, include the steps required to reproduce the bug. 40 | 41 | >This is the first step 42 | 43 | Any other information you want to share that is relevant to the issue being reported. This might include the lines of code that you have identified as causing the bug, and potential solutions (and your opinions on their merits). 44 | 45 | ## Pull requests 46 | You can send Pull Requests by mentioning the Issue that you are closing and certain description as to what that particular Pull Request does! 47 | 48 | ## More information 49 | You can find out more detailed information about contributing in the [WhatsApp-Web documentation](README.md) 50 | 51 | [README]: https://github.com/salman-bhai/WhatsApp-web/blob/master/README.md 52 | [GitHub]: https://github.com/salman-bhai/WhatsApp-web -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # Import necessary selenium libraries 2 | from selenium import webdriver 3 | from selenium.webdriver.firefox.webdriver import FirefoxProfile 4 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 5 | 6 | # Python Module libraries 7 | import time 8 | import threading 9 | import os 10 | import subprocess 11 | 12 | # Argument Parse for Parsing whether to use Chrome Driver or Geckodriver 13 | import argparse 14 | 15 | # Start the argparse 16 | parser = argparse.ArgumentParser() 17 | parser.add_argument("--chrome", help="Using Chrome Driver") 18 | parser.add_argument("--mozilla", help="Using Gecko Driver") 19 | args = parser.parse_args() 20 | if args.chrome: 21 | d = webdriver.Chrome('drivers/chromedriver') 22 | elif args.mozilla: 23 | d = webdriver.Chrome('drivers/geckodriver') 24 | else: 25 | print("Select a valid option") 26 | exit(0) 27 | 28 | # Start the browser and get Whatsapp Web 29 | d.get('https://web.whatsapp.com') 30 | d.implicitly_wait(10) 31 | d.get("https://web.whatsapp.com") 32 | 33 | # Encoding Values 34 | _B = '\033[1m' 35 | B_ = '\033[0m' 36 | ON = u"\u2022" 37 | 38 | # Global Variables 39 | last_seen = 0 40 | currentChat = "" 41 | currentChatState = 0 42 | 43 | # Get Time for the chat 44 | def get_time(): 45 | return int(round(time.time())) 46 | 47 | last_seen = get_time() 48 | 49 | def select_chat(Chat): 50 | global currentChat 51 | global currentChatState 52 | if Chat.lower() in currentChat.lower(): 53 | return 54 | try: 55 | inp = d.find_elements_by_class_name('input') 56 | inp[0].send_keys(' ') 57 | d.find_element_by_class_name('chat-body').click() 58 | inp[0].send_keys(Chat) 59 | time.sleep(1) 60 | chat = d.find_elements_by_class_name('infinite-list-item') 61 | chatName = chat[0].find_element_by_class_name('emojitext').get_attribute('title') 62 | print(chatName) 63 | if Chat.lower() in chatName.lower(): 64 | currentChat=chatName 65 | chat[0].click() 66 | chat_state = d.find_elements_by_class_name('pane-header')[1] 67 | state = chat_state.find_elements_by_class_name('emojitext')[1].get_attribute('title') 68 | currentChatState = (state=="online") 69 | print("Chat "+currentChat+" selected") 70 | else: 71 | print("Failed to select Chat "+ Chat) 72 | except: 73 | print("Failed to select Chat "+ Chat) 74 | 75 | def send_message(msg): 76 | try: 77 | inp = d.find_elements_by_class_name('input') 78 | inp[1].send_keys(msg) 79 | d.find_element_by_class_name('compose-btn-send').click() 80 | except: 81 | print("Failed to send message") 82 | 83 | def send_message_to(chat, msg): 84 | try: 85 | select_chat(chat) 86 | send_message(msg) 87 | except: 88 | print("Failed to send message") 89 | 90 | def get_unread(): 91 | global last_seen 92 | script = open("js/get_unread.js", "r").read() 93 | script = "var last_seen = "+str(last_seen)+";\n"+script 94 | script = "var currentChat = \""+currentChat+"\";\n"+script 95 | last_seen = get_time() 96 | chats = d.execute_script(script) 97 | return chats 98 | 99 | def get_read(): 100 | global last_seen 101 | script = open("js/get_read.js", "r").read() 102 | chats = d.execute_script(script) 103 | return chats 104 | 105 | def print_unread(): 106 | try: 107 | chats = get_unread() 108 | s = "" 109 | i=0 110 | for unread in chats: 111 | chat = unread['name'] 112 | for msg in unread['messages']: 113 | s += _B+chat.encode('utf-8')+" : "+B_ 114 | s += msg['msg'].encode('utf-8')+"\n" 115 | i += 1 116 | r = str(i)+" messages" 117 | if i>0: 118 | r += " from "+str(len(chats))+" chats" 119 | print("\n" + r + "\n") 120 | if len(s): 121 | print(s) 122 | except: 123 | print("Failed to get unread messages") 124 | 125 | def write2file(): 126 | try: 127 | chats = get_read() 128 | i=0 129 | for unread in chats: 130 | s = "" 131 | chat = unread['name'] 132 | f = open("chats/"+ chat.encode('utf-8'), "w") 133 | for msg in unread['messages']: 134 | s += msg['msg'].encode('utf-8')+"\n" 135 | i += 1 136 | if len(s): 137 | f.write(s) 138 | f.close() 139 | except: 140 | print("Failed to get messages") 141 | 142 | query = "" 143 | 144 | while query!="quit": 145 | if len(currentChat)>0: 146 | if currentChatState: 147 | query = input(ON.encode('utf=8')+' '+currentChat.encode('utf-8')+" # ") 148 | else: 149 | query = input(currentChat.encode('utf-8')+" # ") 150 | else: 151 | query = input("# ") 152 | query = query.strip() 153 | q = query[0:3].strip() 154 | s = query[3:].strip() 155 | if q=="sc": 156 | chat = s 157 | select_chat(chat) 158 | elif q=="sm": 159 | msg = s 160 | send_message(msg) 161 | elif q=="um": 162 | print_unread() 163 | elif q=="gc": 164 | write2file() 165 | print("All chats are now accessible ...") 166 | subprocess.Popen(["scripts/read.sh"]) 167 | elif query!="quit" and len(query)>0: 168 | print("Invalid input") 169 | 170 | # Close the Web Driver 171 | d.quit() --------------------------------------------------------------------------------