Split tweet_scraper.py into a config/query/api/cli package#10
Merged
cybermejo merged 2 commits intoJun 18, 2026
Merged
Conversation
added 2 commits
June 18, 2026 10:30
The 630-line single module is now a package with the same flat public API (re-exported from __init__, so 'from tweet_scraper import X' and the 'tweet_scraper:main' entry point are unchanged): config vars.json load/validate + date parsing query build_query + handle extraction api HTTP client: get_api_key, paged_get (retry/cursor), fetchers cli flatten -> CSV, streaming writes, main Behavior-preserving — same 65 tests pass. Test mock patch targets were retargeted to where names are now looked up (tweet_scraper.api.requests/.time/.paged_get/ .tweet_replies); cli calls fetchers via the api namespace so those patches resolve. CI mypy target updated tweet_scraper.py -> tweet_scraper; CLAUDE.md architecture note updated for the package layout.
Adversarial verification flagged two minor regressions from the split: - The original supported 'python tweet_scraper.py'; the package had no __main__, so the README's no-install run path broke. Add __main__.py so 'python -m tweet_scraper' works (mirrors the tweet-scraper console script). - README + CLAUDE.md still said 'python tweet_scraper.py' and 'mypy tweet_scraper.py', and the project-structure tree / data-flow / Roadmap were stale. Update invocation to 'python -m tweet_scraper', mypy target to the package, the structure tree to the new modules, and mark the now-shipped Roadmap items done. Full loop green: 65 tests, mypy on 6 files, python -m verified.
cybermejo
pushed a commit
that referenced
this pull request
Jun 18, 2026
PR #10 (config/query/api/cli split + __main__.py) had merged into its stacked base branch but not into main, which still carried the flat tweet_scraper.py. Bring the split to main. Touches only scraper/CI/docs — no Studio files, so the PR #6/#7 Studio work is untouched. CLAUDE.md auto-merged (kept the PR #8 Studio note + the split's python -m updates). Validation loop green: 65 tests, mypy on the package, python -m tweet_scraper verified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Splits the 630-line
tweet_scraper.pyinto aconfig / query / api / clipackage — the last remaining README Roadmap item for the scraper. Behavior-preserving: same 65 tests pass.Layout (flat public API preserved)
from tweet_scraper import Xand thetweet_scraper:mainentry point are unchanged —__init__.pyre-exports the full public API (including the_underscorehelpers the tests import).config.pyDEFAULTS,_CONFIG_TYPES,validate_config,load_config, date parsingquery.pybuild_query,handle_from_urlapi.pyget_api_key,_extract_*,paged_get(retry/cursor),search_tweets,user_tweets,tweet_repliescli.pyCSV_COLUMNS,flatten, streaming writers,main__main__.pypython -m tweet_scraperMock-patch retargeting (the tricky part)
The suite has 20 patch targets on the flat namespace. Since the patched objects moved into
api, the strings were retargeted to where names are actually looked up —tweet_scraper.api.{requests,time,paged_get,tweet_replies}— andclicalls fetchers via theapi.namespace so the patches intercept.Verification (beyond the green loop)
python -mentry, stale docs) are fixed in this PR.Also updated
mypy tweet_scraper.py→mypy tweet_scraper.python -m tweet_scraper, project-structure tree, data-flow, and Roadmap (shipped items marked done).Testing
Full CI-equivalent loop green from
scraper/:ruff,ruff format --check,mypy tweet_scraper(6 files),pytest --cov— 65 tests pass.python -m tweet_scraper --dry-runverified without install.