As I was learning Python and I love making robots I thought to make an automated robotic comment or messaging system.

A python3 code to post comments / Messages automatically. Sending Love messages to your partner can be very effective. But as we always don't have that much time to do so, also as I was learning Python and I love making robots I thought to make an automated (semi automated actually) robotic comment or messaging system for my girl friend.

Things must need:

  1. A computer with python3 installed. Download from here. Make sure to add python to your environment variable path. Just check the box that tells you to do so.
  2. pyautgui library. Open up Command prompt or Powershell then type- pip install pyautogui 

pyautogui does the work of typing automatically, it is a GUI (Graphical User Interface) library kind of like tkinter but not as good as tkinter. But for this message automation task it is better than tkinter.



        """
***Sending Automated messages or Comments**** 

Warning: DO NOT USE THIS FOR VIOLATION
         I will NOt hold responsibilites if something wrong is done using this code
"""

"""
by: Ashraf Minhaj
mail: [email protected]
blog: http://ashrafminhajfb.blogspot.com

python version: python3.7.1
"""

import pyautogui
from time import sleep
from random import randint

x = 50   #how many messages or comments you want to send

def name():
    """generates random names"""

    nameList = ["Baby", "Shona", "Honey", "Jaan", "Wifey"]   #list of names (change according to your requirement)
    rand_name = nameList[randint(0, len(nameList) - 1)]      #traverse names randomly for n, from 0 to (n-1)

    return rand_name    #return the random name it just generated
 


while True:      #forever loop
    pyautogui.typewrite(f"I love you {name()}")  #type message
    sleep(.600)                        #A bit delay of 600 ms
    pyautogui.typewrite("\n")          #New line, here 'Enter' to send text
    sleep(2)                           #delay of 2 seconds

    x = x - 1         #decrement x value by 1

    if x == 0:       
        break         #get out of the loop and finish
    

Run The code

That's it now you can run the code from command prompt. Here's an advice. Don't use Ide/idle to do code, this will kill your ability and quality. Use an editor to code then run from command prompt. To run a python code from command prompt or powershell:

  1. Copy the path of the python code/script
  2. Open up Cmd (Command Prompt) / Powershell
  3. Type python followed by the copied path (watch the video above for better understanding)

Thats it, now after running the code put the cursor in a where you want the comment/ message to be typed. You'll see the magic.

Ashraf Minhaj
A Computer Science and Engineering student and a Hobbyist. Love to make robots, DIY gadgets. Interested in robotics and AI. 

Categories