
Spent the last few weeks building an Instagram automation script optimized for Termux (Android).
I wanted to share a hobby project I’ve been hacking on recently called ReelFlow. It’s a Python script that handles automated clip downloading (yt-dlp), parses video titles to dynamically generate context-aware hashtags, and uploads them to Instagram Reels using instagrapi.
My goal was to build something low-overhead enough that I could host it 24/7 on an old Android phone using Termux without needing a VPS. However, running long-running automation tasks on mobile environments threw a ton of unexpected roadblocks at me.
Here are the main technical hurdles I ran into and how I ended up patching them:
1. The Termux Dependency Trap (Rust/Clang compilation)
When trying to run pip install -r requirements.txt on a standard phone environment, the installation completely stalled out and crashed on modern packages like pydantic-core. Because there are no pre-compiled wheels for Android architecture on PyPI, Python tries to build the packages from source, which requires a Rust compiler and C tools.
To fix this for anyone cloning the repo, I wrote an interactive setup.sh script that checks the environment path. If it identifies the Termux filesystem (/com.termux/), it automatically flags the system to run pkg install rust clang make before triggering pip. It also takes configuration prompts in the terminal to cleanly compile a .env file on the fly without making the user jump into mobile text editors.
2. Self-Healing Expiry Loops
Anyone who has worked with instagrapi knows that Instagram aggressively drops session tokens, resulting in script-killing LoginRequired or ClientError exceptions halfway through a scheduled loop.
Instead of letting the main schedule thread crash, I wrapped the initialization into a reusable state manager. Every time a scheduled post triggers, the script executes a lightweight cl.get_timeline_feed() heartbeat check. If it catches an authentication error, it halts the job, triggers a re-login workflow to refresh session.json, and then allows the upload pipeline to proceed.
3. Contextual Hashtag Splitting
To avoid getting shadowbanned for using identical blocks of 30 hashtags on every single post, I built a modular generator that takes the pulled YouTube video title as a raw string hint. It runs keyword checks (e.g., matching character names or series titles) and uses rsplit() to dynamically stitch highly targeted sub-community tags directly above the media credit lines, while randomly shuffling a generic pool of tags for the bulk of the caption.
I'd love to hear how other people handle long-running background scripts on Android, or if there's a more efficient way to maintain Instagram session stability over long periods.