0

I'm trying to create a program based on the web application of WhatsApp. I'm trying to figure out which is the best programming language to start this kind of programs. I've for example tried it with java but with this implementation:


    public UrlReader() throws IOException {

            try {
                URL whatsApp = new URL("https://web.whatsapp.com/");
                DataInputStream dis = new DataInputStream(whatsApp.openStream());
                String inputLine;

                while ((inputLine = dis.readLine()) != null) {
                    System.out.println(inputLine);
                }
                dis.close();
            } catch (MalformedURLException me) {
                System.out.println("MalformedURLException: " + me);
            } catch (IOException ioe) {
                System.out.println("IOException: " + ioe);
            }
        }

that is only a basic copy and paste from the oracle website. The output of this program is a site that says me that I have to use browser like chrome. Is there a better way to create programs like this?

1 Answers1

0

You can start with Python to play with web.whatsapp.com. I assume you are trying to send a message on WhatsApp using code.

In Python, you can do it the same way we do it with mobile application

 web.open('https://web.whatsapp.com/send?phone='+phone_no+'&text='+message)

This will prepopulate the text for given mobile number(Enter the phone_no as CountryCode and the number eg +918888888888) Then using pyautogui you can press enter onto whatsapp.web

Working code :

def sendwhatmsg(phone_no, message, time_hour, time_min):
     '''Sends whatsapp message to a particulal number at given time'''
     if time_hour == 0:
         time_hour = 24
     callsec = (time_hour*3600)+(time_min*60)

     curr = time.localtime()
     currhr = curr.tm_hour
     currmin = curr.tm_min
     currsec = curr.tm_sec

     currtotsec = (currhr*3600)+(currmin*60)+(currsec)
     lefttm = callsec-currtotsec

     if lefttm <= 0:
         lefttm = 86400+lefttm

     if lefttm < 60:
         raise Exception("Call time must be greater than one minute")

     else:
         sleeptm = lefttm-60
         time.sleep(sleeptm)
         web.open('https://web.whatsapp.com/send?phone='+phone_no+'&text='+message)
         time.sleep(60)
         pg.press('enter')

I've taken this from this repository - Github repo

Savan
  • 161
  • 3
  • 11