DEV Community

qing
qing

Posted on

How I Made $350 With Python Automation (Step-by-Step)

Introduction to My Journey

As a Python enthusiast, I've always been fascinated by the potential of automation to generate passive income. After months of experimenting with different scripts and tools, I'm excited to share my story of how I made $350 using Python automation. In this article, I'll walk you through the step-by-step process of building the scripts, the platforms I used, and the time investment required.

The Idea Behind the Automation

The idea was to automate the process of data scraping and reporting for a client who needed help extracting information from a website. The client was willing to pay $50 per report, and I estimated that I could generate at least 7 reports per week. With a potential weekly income of $350, I was motivated to make it work.

Setting Up the Environment

Before we dive into the code, let's set up the environment. You'll need to have Python installed on your system, along with the following libraries:

  • requests for making HTTP requests
  • beautifulsoup4 for parsing HTML
  • pandas for data manipulation

You can install these libraries using pip:

pip install requests beautifulsoup4 pandas
Enter fullscreen mode Exit fullscreen mode

Installing the Required Libraries

Here's a Python code snippet to install the required libraries:

import subprocess
import sys

def install_libraries():
    libraries = ['requests', 'beautifulsoup4', 'pandas']
    for library in libraries:
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', library])

install_libraries()
Enter fullscreen mode Exit fullscreen mode

Building the Data Scraper

The first step was to build a data scraper that could extract the required information from the website. I used the requests library to make an HTTP request to the website and the beautifulsoup4 library to parse the HTML response.

Data Scraper Code

Here's the code for the data scraper:

import requests
from bs4 import BeautifulSoup

def scrape_data(url):
    response = requests.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')
    data = []
    for item in soup.find_all('div', {'class': 'item'}):
        title = item.find('h2', {'class': 'title'}).text.strip()
        price = item.find('span', {'class': 'price'}).text.strip()
        data.append({'title': title, 'price': price})
    return data

url = 'https://example.com'
data = scrape_data(url)
print(data)
Enter fullscreen mode Exit fullscreen mode

Building the Reporting Script

The next step was to build a reporting script that could take the scraped data and generate a report in the required format. I used the pandas library to manipulate the data and the openpyxl library to generate an Excel report.

Reporting Script Code

Here's the code for the reporting script:

import pandas as pd
from openpyxl import Workbook

def generate_report(data):
    df = pd.DataFrame(data)
    wb = Workbook()
    ws = wb.active
    ws.title = 'Report'
    ws['A1'] = 'Title'
    ws['B1'] = 'Price'
    for index, row in df.iterrows():
        ws.cell(row=index + 2, column=1).value = row['title']
        ws.cell(row=index + 2, column=2).value = row['price']
    wb.save('report.xlsx')

data = [{'title': 'Item 1', 'price': '$10.99'}, {'title': 'Item 2', 'price': '$9.99'}]
generate_report(data)
Enter fullscreen mode Exit fullscreen mode

Setting Up the Automation

To automate the process, I used the schedule library to schedule the data scraper and reporting script to run at regular intervals. I also set up a Dropbox account to store the generated reports and shared the link with the client.

Automation Code

Here's the code for the automation script:

import schedule
import time

def automate():
    scrape_data('https://example.com')
    generate_report(scrape_data('https://example.com'))
    # Upload the report to Dropbox
    print('Report generated and uploaded')

schedule.every(1).day.at("08:00").do(automate)  # Run the automation script every day at 8am

while True:
    schedule.run_pending()
    time.sleep(1)
Enter fullscreen mode Exit fullscreen mode

Time Investment and Effort Required

The total time investment for this project was around 20 hours, spread over a period of 2 weeks. This included:

  • Researching the requirements and planning the approach (2 hours)
  • Building the data scraper and reporting script (8 hours)
  • Setting up the automation and testing (4 hours)
  • Debugging and refining the code (6 hours)

While the effort required was significant, the potential reward was worth it. With a weekly income of $350, I was motivated to make it work.

Conclusion and Next Steps

In conclusion, making $350 with Python automation is definitely possible, but it requires effort and dedication. By following the steps outlined in this article, you can replicate my success and start generating passive income. Remember to:

  • Identify a problem or opportunity for automation
  • Build a script or tool to solve the problem
  • Set up the automation and testing
  • Refine and debug the code

If you're interested in learning more about Python automation and how to generate passive income, be sure to follow me for more content. I'll be sharing more tips, tricks, and tutorials on how to get started with Python automation and take your skills to the next level. Happy coding!


Found this useful? Follow me on Dev.to for more Python automation tips every week. Drop a comment below — I reply to every one!

Top comments (0)