Pythonelectron Application for Programmatically Scrolling Through Reels on Instagram

https://github.com/arazzz/flicktok_testing

The example Python x Electron application I had thrown together while waiting for Qt’s build process to SEGFAULT on me is here. It’s public for now, but might make it private later — if you’d like to view or add to it for experimentation, please let me know, and I can add you as a collaborator.

There are a million different ways to develop/run a Node.JS (Electron) & Python app together, but I tried to pick one that’s scaled well for me in the past, without much overhead or slowing-down of prototyping. That said, it’s still hilariously more complicated than it needs to be (hence the delay in posting this— sorry— forgot how much I’d have to write to explain this), and easy to simplify if needed.
I tried to include most of the details in the README.md, and plenty of comments & log messages in the code, so hope it’s easy to follow — if not, please let me know.

Basic Idea


The basic idea is to create a monorepo with two projects: one for the Python side, and one for the Node.JS side. This makes it easier to manage their (common) dependencies, share the codebase, run the two projects together, and eventually build a final executable or bundle for distribution/deployment, if needed. Almost none of that is absolutely necessary for this particular example, but mentioning it for completeness.

From the root of the monorepo, both projects can be launched in parallel (e.g., via bun run dev), and can then communicate with each other via HTTP requests (e.g., using requests in Python, and axios in Node.JS), or as done here for bidirectional real-time communication, via websockets (using the python-socketio library in Python, and the socket.io library in JavaScript). There are many other ways to enable message-passing between the two sides using some kind of pub/sub pattern with a broker/message/queue system (e.g., via Redis, ZeroMQ, Kafka etc.), but websockets were the first thing I reached for, and may also be amongst the simplest options in this case.

Once launched, the example application is simple — it starts by opening (on the Electron/JS side) a window that goes to the Instagram website, and once the user signs in, navigates to Instagram’s Reels page, and sends a message to the Python side with the duration of the first Reel that the user starts watching.
The Python side then sends back a random time in the video (based on the duration) to the JS side, and when the JS side detects that the video has reached that time, it scrolls to the next Reel.
This process repeats until the application is closed.

For now, I’ll leave it to the README.md to explain what’s going on in the codebase in more detail, but will try to come back here to explain things more clearly.