Automate Some Mundane Tasks With Python

bot
python

My dear Python enthusiasts over there! Today I brought a little hack for making your life a little less boring. You can use this idea to build very complex algorithms.

bot

Getting the libraries:

I assume you have Python installed on your computer. If not and you still want to follow this instruction, please install python any version will do.

Today we will show you how can you automate some tasks automated just using a few functions from pyautogui library.
Most probably your python comes with this library, if not go ahead and pip install it.

command: pip install pyautogui.

Or using anaconda.


command: conda install -c conda-forge pyautogui

Clicking with Python:

Let me tell you first what will we do today. We will use the auto click function from the GUI library and make our program click where we want.

Let’s say we want to click on the close button to quit the window. So the question is where will our program click. to find out the coordinate position of the close button let’s open python in the command prompt or anaconda prompt or any of your terminal.

Then import the required library.

Chatbots
import pyautogui as gui

then type the command
gui position() (don’t press enter)
hover your mouse on the close button ( just hover, don’t click anywhere).
then press Enter you will see the script has detected the position of the close button (or wherever you were hovering the mouse pointer).
Now we found the coordinates of the button we want to click let’s simulate the click using click function. Click method requires two arguments. X and Y coordinate of the position.

 

 gui click(1895, 22)
 The program successfully clicked the button. If not make sure you did everything right. If it worked then play with more functions comes with pyautogui.   🎉 🎉 🎉
Datalators

Now let us make our program more useful.
Let’s think of something we need to automate. I have joined Fiverr recently and for a beginner, there isn’t a lot of posts to bid!
So refreshing the Buyer Requests page might be a good idea for me.
so let us find the position of the active button where the active jobs will be reloaded.
and now using the program click!

Looping and using Time:

So we want our program to click this button and check if there is any job every 30 seconds.
To do that we can run the program in a while True loop and use the time library.

 while True:
    gui.click(1962, 289)
    sleep(30)

so our program will loop over time and click the active button every after 30 seconds.

Now let us check if there is a new job!
we can detect the color of any given position to see if there is a job. Like if there is a job there will be this green send-offer button.

Datalators

for that, we will first find the position coordinate and then use the pixel method which takes the position arguments. which will check the color of the position. if there is no job this place will be light grey. (#RGB 247,247,247). But if there is a job there will be a send-offer button which is green.

gui.pixel(3058,453)        #then let us add condition

 

if c != (247,247,247):
gui.click(b)
print('Attention!')
sleep(25)

This code will check if the button is not grey then click the button for us and print Attention on the terminal.

Let us say we want the program beep as well to notify us.

let’s import another library which will play output sound. And use the Beep class to play the sound when there is the green button. Beep class will take two arguments, frequency of the beep and duration. 

we added extra 60 second to let us write a proposal if there is a job.

Now to not be disappointed we need to expect uncertainty!

i will keep track how many times did our program loop.

Download or fork the code on GitHub: Github Python

I hope you are familiar now with python automation. Use the idea to build complex algorithms.

You can use pyinstaller to make a exe file from the python file. And create sharable bots.

Thank you for staying with datalators. Subscribe our newsletter to make sure you don’t miss any post.

29 thoughts on “Automate Some Mundane Tasks With Python”

  1. Hello there! This is kind of off topic but I need some guidance from an established
    blog. Is it hard to set up your own blog? I’m not very techincal but I
    can figure things out pretty fast. I’m thinking about creating my own but I’m not
    sure where to start. Do you have any points or suggestions?

    Appreciate it

  2. Whats up are using WordPress for your site platform?

    I’m new to the blog world but I’m trying to get started and
    set up my own. Do you need any html coding expertise to make your own blog?
    Any help would be greatly appreciated!

  3. My brother recommended I might like this web site. He was entirely right.
    This submit actually made my day. You cann’t believe simply how a
    lot time I had spent for this info! Thanks!

  4. Hmm is anyone else encountering problems with the pictures
    on this blog loading? I’m trying to figure
    out if its a problem on my end or if it’s the blog.
    Any feed-back would be greatly appreciated.

  5. excellent submit, very informative. I ponder why the other specialists of this
    sector don’t realize this. You must continue your
    writing. I am confident, you have a great readers’ base already!

    games ps4 allenferguson games ps4

  6. Spot on with this write-up, I honestly think this site
    needs much more attention. I’ll probably be returning to read more,
    thanks for the advice! ps4 games 185413490784 ps4 games

  7. Wonderful goods from you, man. I have understand your stuff previous to and you’re just too
    wonderful. I really like what you have acquired here,
    certainly like what you’re saying and the way in which
    you say it. You make it enjoyable and you still care for
    to keep it sensible. I can’t wait to read much more from you.

    This is really a tremendous web site.

  8. W88 Casino Review
    Established in 2013, W88 has been a leading online gaming
    site in Asia for quite a while. During this time, the operator has
    earned a great reputation among players thanks to its wide range of activities, which include casino
    games, sports betting, lottery, live casino
    games and poker.

    The W88 site is well-known for its commitment to customer service, offering players
    the chance to claim generous bonuses regularly. So, it
    while it seems like this casino is packed
    with great games and customer service, let’s find
    out if there’s more to it than this.

  9. My brother recommended I might like this website. He was entirely
    right. This post actually made my day. You can not imagine simply
    how much time I had spent for this info! Thanks!

  10. I’m really impressed with your writing skills and also with the layout on your blog.

    Is this a paid theme or did you modify it yourself?
    Either way keep up the excellent quality writing, it is rare
    to see a great blog like this one these days.

  11. After looking over a handful of the blog articles
    on your blog, I seriously appreciate your technique of
    writing a blog. I book-marked it to my bookmark webpage list and will be checking back in the
    near future. Please visit my web site as well and tell me how you feel.

  12. Excellent site. Plenty of helpful information here. I am sending it
    to several buddies ans also sharing in delicious.
    And certainly, thanks on your effort! asmr 0mniartist

  13. Today, I went to the beach with my children. I found
    a sea shell and gave it to my 4 year old daughter and
    said “You can hear the ocean if you put this to your ear.”
    She put the shell to her ear and screamed. There
    was a hermit crab inside and it pinched her ear. She never wants to go back!
    LoL I know this is totally off topic but I had to tell someone!

  14. I like the helpful information you provide in your articles.
    I will bookmark your weblog and check again here regularly.
    I’m quite certain I will learn many new stuff right here! Best
    of luck for the next!

  15. Heya i’m for the first time here. I found this board and I
    find It truly useful & it helped me out a lot. I hope to give something back and aid others like you
    aided me.

  16. This is very interesting, You’re an overly professional blogger.
    I’ve joined your feed and look forward to in quest
    of more of your excellent post. Also, I have shared your web site in my social networks

  17. Hello my friend! I wish to say that this article is awesome,
    great written and include approximately all significant infos.
    I’d like to look more posts like this .

  18. I believe what you posted made a bunch of sense. However, what about this?
    what if you were to write a killer post title? I ain’t suggesting
    your content isn’t good., but what if you added a post title that grabbed
    folk’s attention? I mean Automate Some Mundane Tasks With Python – Datalators Blog is kinda boring.
    You ought to glance at Yahoo’s home page and note how they create article headlines to grab viewers to click.

    You might add a video or a related pic or two to get people interested about what you’ve
    written. In my opinion, it might make your posts a little livelier.

Leave a Comment

Your email address will not be published.