Skip to content

Rewrite tracker with instagrapi and snapshot-based diffing - #23

Open
Silverarmor wants to merge 3 commits into
masterfrom
claude/instagram-follower-tracker-eybjg7
Open

Rewrite tracker with instagrapi and snapshot-based diffing#23
Silverarmor wants to merge 3 commits into
masterfrom
claude/instagram-follower-tracker-eybjg7

Conversation

@Silverarmor

Copy link
Copy Markdown
Owner

Summary

Complete rewrite of the Instagram follower/following tracker, replacing the abandoned instaclient/Selenium stack with instagrapi and a snapshot-based architecture. The new version is more reliable, maintainable, and offers multiple data sources.

Key Changes

  • Replaced insta.py with tracker.py: New single-entry-point script with cleaner architecture

    • Removed dependency on instaclient (unmaintained) and Selenium
    • Switched to instagrapi (actively maintained private mobile API)
    • Removed Google Sheets logging (now just Discord webhooks + local JSON snapshots)
  • Snapshot-based diffing:

    • Each run saves a dated JSON snapshot to data/snapshot-YYYY-MM-DD.json
    • Diffs against the most recent previous snapshot
    • Enables historical tracking and recovery from bad scrapes
  • Dual data sources:

    • --source scrape (default): Uses instagrapi to log in and fetch lists
    • --source export: Parses official Instagram data exports (zero ban risk, manual process)
  • Improved session handling:

    • Reuses cached device session (session.json) instead of fresh login each run
    • Configurable random delays between API requests to avoid detection
    • Better 2FA handling with optional --2fa flag for non-interactive runs
  • Cleaner Discord reporting:

    • Refactored webhook logic into DiscordReporter class
    • Automatic rate-limit handling (429 responses)
    • Dry-run mode (--dry-run) for testing without sending webhooks
    • Same color scheme as v1 for familiarity
  • Removed obsolete files:

    • Deleted instaOneTimeCompare.py (one-off comparison tool, superseded by snapshot diffing)
    • Removed Google Sheets integration code
  • Updated credentials & documentation:

    • Simplified example_credentials.py (removed driver_path, service_account_path)
    • Added session_file and delay_range options
    • Comprehensive README with data source comparison table and anti-detection best practices

Notable Implementation Details

  • Snapshot format includes profile metadata (username, follower/following counts, bio) alongside the lists, enabling richer reporting
  • First run saves a baseline snapshot with no diff (prevents false positives)
  • Validates that scrape returned non-empty lists before saving (prevents poisoning the baseline with a bad scrape)
  • Handles both directory and ZIP exports for the official data source
  • Escapes underscores in Discord messages to prevent accidental italicization
  • Chunks long usernames lists into 1000-char segments to stay under Discord's 4096-char embed limit

https://claude.ai/code/session_01NW36HHEBk3eCps3Lrb2qsr

claude added 3 commits August 7, 2026 11:47
Replace the dead instaclient/Selenium implementation with a single
tracker.py supporting two data sources:

- scrape (default): instagrapi private mobile API with cached device
  session, 2FA support, randomised request delays, and challenge
  handling
- export: parse Instagram's official 'Download your information'
  export (zip or folder) for a zero-ban-risk alternative

Daily snapshots are stored as dated JSON under data/; each run diffs
against the previous snapshot and posts the four change categories to
a Discord webhook using the same embed titles/colours as v1. Empty
scrapes abort without saving so a bad run can't poison the next diff.

README documents the current (2026) scraping options, their ToS
status, and bot-detection tradeoffs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NW36HHEBk3eCps3Lrb2qsr
Optionally append one row per run (counts, the four change lists, and
the full follower/following lists) to a Google Sheet via a gspread
service account. If the local data/ directory is lost (dead SD card,
reinstall), the next run rebuilds its diff baseline from the sheet's
last row instead of starting over, so change detection stays
continuous. Sheets failures degrade to a webhook warning rather than
failing the run, and dry-run mode never writes to the sheet.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NW36HHEBk3eCps3Lrb2qsr
A missing data/ directory now just starts a fresh baseline by default.
Restoring the diff baseline from the Google Sheet's last row is an
explicit recovery action: it requires the Sheets backup to be
configured, refuses to run when local snapshots already exist, and
fails loudly when the sheet has no data rows.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NW36HHEBk3eCps3Lrb2qsr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants