What are the best Python scripts you've ever written?

Updated on : December 3, 2021 by Dexter Berry



What are the best Python scripts you've ever written?

I am a computer engineer with 15 years of experience. I have created multiple python scripts (similar to many scripts described already) for daily usage tasks.

However my best python script would be facebook automation. The setup includes a selenium driver on firefox.

The script is triggered once every 6 hours on a dedicated computer. The scripts opens web browser and logs in with my account.

Some of thing it can do are listed:

  1. Parse my full friend list and create an xml with all relevant details. (This is important as later steps take action only on feeds from people in this created xml.)
  2. Wish bi
Continue reading

I am a computer engineer with 15 years of experience. I have created multiple python scripts (similar to many scripts described already) for daily usage tasks.

However my best python script would be facebook automation. The setup includes a selenium driver on firefox.

The script is triggered once every 6 hours on a dedicated computer. The scripts opens web browser and logs in with my account.

Some of thing it can do are listed:

  1. Parse my full friend list and create an xml with all relevant details. (This is important as later steps take action only on feeds from people in this created xml.)
  2. Wish birthday to friends. It picks up a random message from a fixed pool and wishes them on birthday.
  3. Scroll the feedpage and take actions on individual feeds.
  4. It can like the photos / posts if some preconditions are satisfied. For eg one precondition is that photo should be directly uploaded and not shared from someone else's feed.
  5. By default it will like any profile pic / cover pic change.
  6. If other people congratulate on anniversary, it can parse the comment, like the feed and comment congratulation message for anniversary from anniversary message pool.
  7. If other people congratulate my friend, it can parse the comment, like the feed and comment congratulation message.
  8. If someone shares a post for specific event (like traveling, checkin at some place or ran with activity trackers) then it is automatically liked.

I am anonymous because most likely it's against facebook policies to use this kind of scripts for daily interaction.

EDIT 1:

This edit section is for people who are interested in knowing how the whole script works. I will try to keep it minimal so that it doesn't become too technical.

The script has 3 main work areas:

  1. Navigation: Navigate to a webpage, scroll the page etc.
  2. Info collection: Collect the information from specific elements in webpage and save them in local structures
  3. Action: Take some action on specific element based on info collected.

Navigation

Selenium driver gives the direct capability to launch a browser, navigate to a url, scroll down etc. Hence this part is pretty much straight forward.

Info collection

This is one of the most hard parts. On firefox you can right click any element and inspect it. "Inspect Element" gives details of what the html code for an element looks like

Here is a snapshot of what firefox shows when i inspect a friend's name in my friends list.

The class of "div" element is very important. I now know that whenever I will parse an element of this class, it will have the details of my friend (name, url etc)

I first statically find these elements manually and then hardcode them in my script.

I can now parse necessary elements and collect the information present in those via selenium. Selenium gives the api's to extract each information of an element. For eg I can extract the “href” in above picture and I can save the url of my friend.

This example also covers first point of my script of how i created xml of all my friends. I need to parse my friends list only once and save it for future use until I add / remove a friend.

In a similar way we can parse comments / like count / birthday events etc.

Action

Once we have collected the information we can apply our own programming logic to that information. For eg if someone has commented “Nice picture” we can post a similar comment.

Selenium provides the api's to click on element / type in a textarea etc. So for like we simply click on “Like” element with that specific class.

That's all folks.

Created a python program using OpenCV to play NFS MostWanted with hand gestures.

So I thought to combine my love for gaming and my interest in technology to have some fun, which resulted in this project. I got inspired by Xbox-kinect. This program will only make use of the webcam and can give the feel of playing on kinect.

Also this program can be used to play any game which can be run by maximum of 4 keyboard keys (atleast as of now).

Before I dig into how I made this program watch me race with hand gestures and win the race too;)

(Note: Video is appearing as a small icon in some devices, click to

Continue reading

Created a python program using OpenCV to play NFS MostWanted with hand gestures.

So I thought to combine my love for gaming and my interest in technology to have some fun, which resulted in this project. I got inspired by Xbox-kinect. This program will only make use of the webcam and can give the feel of playing on kinect.

Also this program can be used to play any game which can be run by maximum of 4 keyboard keys (atleast as of now).

Before I dig into how I made this program watch me race with hand gestures and win the race too;)

(Note: Video is appearing as a small icon in some devices, click to view the video)

So getting into the technical aspects:

What I am doing basically is detecting objects based on color (in this case orange) and using those detected objects to give a keyboard key press command from the program which controls the car in the game. To do that i will resize the frame to 600px width so that I don't need to process huge frame as I wanted it to work in realtime even on low end laptops / desktops. Apply Gaussian blur to filter out noise, convert the frame to HSV color space and find pixels that fall in the orange color range in HSV color space.

Then I draw contours around the detected objects and find the centroid of that object. The frame is logically divided into two parts. Right part is used to control accelerator and brake. Left part is used to turn the vehicle left or right.

As seen in the video if the center of the object of the right hand goes above the blue box then the key to accelerate vehicle is pressed, if it goes below then key for the brake is pressed. Similar logic goes for object detected on the left part of the frame.

The code for this project is available at: pateldigant / gesture-gaming-python

Other Guides:


GET SPECIAL OFFER FROM OUR PARTNER.