DEV Community

Samuel James Hiotis
Samuel James Hiotis

Posted on

Zero-capital automation: running a business from Termux

Zero-Capital Automation: Running a Business From Termux

Okay, buckle up. This isn't your typical "passive income" article. This is about actively building a business, leveraging the frankly ridiculous power packed into a mobile terminal emulator called Termux. And the best part? You can start with virtually zero capital. I'm talking the cost of your smartphone and some elbow grease.

I’ve been building and running a small (but profitable!) business entirely from my phone using Termux for the past six months. It started as a technical challenge – could I really replace my laptop for some core business tasks? The answer is a resounding yes. Now I’m sharing how I did it, and how you can too.

What is Termux, and Why Bother?

Termux is an Android terminal emulator and Linux environment. It's not a root requirement; it operates within userland permissions. But don’t let that fool you. It’s capable. Think package management (apt), scripting (bash, Python, Node.js), networking tools (curl, wget, ping), and even running lightweight servers.

Why bother using your phone for business? Simple: portability, cost, and access. My "office" is now anywhere with a data connection. No more being chained to a desk. And crucially, the startup cost is incredibly low.

My Business: Automated Data Scraping & Reporting

To give context, my business focuses on scraping publicly available data (ethically, of course - more on that later!), processing it, and delivering reports to clients on a recurring basis. Think competitor price monitoring, product availability checks, or tracking industry trends. The core logic is relatively simple, but the volume of data and the automation requirements are significant. This is where Termux shines.

The Tech Stack (All Within Termux)

  • Python 3: My primary scripting language. Termux installs it easily with pkg install python.
  • Beautiful Soup 4: For parsing HTML. pkg install python-beautifulsoup4
  • Requests: For making HTTP requests. pkg install python-requests
  • Cron: For scheduling tasks. This is huge. pkg install cron
  • Ngrok: (Optional, but powerful) For exposing local Termux services to the internet. pkg install ngrok
  • Text Editors: nano or vim (I prefer nano - pkg install nano).
  • SQLite: For simple data storage. pkg install sqlite

Building the Automation Pipeline: A Code Snippet

Let's look at a simplified example of scraping a website and saving the data. This is heavily simplified for clarity, but it illustrates the core idea.

#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup
import sqlite3

# Target website (replace with your target)
url = "https://example.com/products"

try:
    response = requests.get(url)
    response.raise_for_status()  # Raise HTTPError for bad responses (4xx or 5xx)
    soup = BeautifulSoup(response.content, 'html.parser')

    # Find elements containing product names and prices (adjust selectors!)
    product_elements = soup.find_all('div', class_='product')

    # Connect to SQLite database
    conn = sqlite3.connect('products.db')
    cursor = conn.cursor()

    # Create table if it doesn't exist
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS products (
            name TEXT,
            price TEXT
        )
    ''')

    for product in product_elements:
        name = product.find('h2', class_='product-name').text.strip()
        price = product.find('span', class_='product-price').text.strip()
        cursor.execute("INSERT INTO products (name, price) VALUES (?, ?)", (name, price))
        print(f"Scraped: {name} - {price}")


    conn.commit()
    conn.close()

except requests.exceptions.RequestException as e:
    print(f"Error during requests to {url}: {e}")
except Exception as e:
    print(f"An error occurred: {e}")

Enter fullscreen mode Exit fullscreen mode

Important Considerations:

  • Respect robots.txt: Before scraping any website, check its robots.txt file (e.g., https://example.com/robots.txt) to understand what parts of the site are disallowed. Disregarding robots.txt is unethical and can lead to legal issues.
  • Be Polite (Rate Limiting): Don't hammer the website with requests. Introduce delays (e.g., time.sleep(2) between requests). Aggressive scraping can overload their servers and get your IP blocked.
  • Website Structure Changes: Websites change their HTML structure frequently. Your selectors (the find_all arguments in the code) will need to be updated accordingly. This is where monitoring and regular maintenance come in.

Scheduling with Cron

The real magic happens with cron. This allows you to run your Python script automatically on a schedule.

  1. Edit the crontab: Run crontab -e in Termux. This will open the crontab file in nano.
  2. Add a schedule entry: Add a line like this:

0 8 * * * python /sdcard/your_script.py >> /sdcard/log.txt 2>&1

  • 0 8 * * *: Runs the script every day at 8:00 AM. (Minute Hour Day Month Weekday)
  • python /sdcard/your_script.py: The command to execute (assuming your script is saved as your_script.py in your SD card's root directory).
  • >> /sdcard/log.txt 2>&1: Appends the script's output (and any errors) to a log file. Crucially important for debugging!

Running a Web Server (Optional - For Reporting)

For delivering reports, I use a very lightweight Python web server. This allows clients to access their reports through a simple URL.

#!/usr/bin/env python3
import http.server
import socketserver
import os

PORT = 8080 # You can change this

# Define the directory to serve (e.g., the directory containing your reports)
DIRECTORY = "/sdcard/reports"

os.chdir(DIRECTORY)

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print("Serving at port", PORT)
    httpd.serve_forever()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)