Add periodic R script to scrape Open Government ATIP requests by department - #10
Add periodic R script to scrape Open Government ATIP requests by department#10charles-hebert wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f58643c329
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else { | ||
| new_rows <- scraped | ||
| combined <- scraped |
There was a problem hiding this comment.
Preserve existing rows when dedupe key is unavailable
When output_csv exists but the loaded data does not contain file_number (including the read-error fallback to an empty frame), this branch replaces the whole dataset with only the current scrape. In that case historical rows are silently discarded, which contradicts the append-only incremental behavior and can corrupt long-running exports; this should fail fast or keep existing rows instead of overwriting them.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| if (nrow(existing) > 0 && "file_number" %in% colnames(existing)) { | ||
| new_rows <- scraped[!(scraped$file_number %in% existing$file_number), , drop = FALSE] |
There was a problem hiding this comment.
Deduplicate scraped rows by file_number before append
The incremental filter only removes rows already present in existing, so duplicates within the same run (same file_number repeated across tables/pages) are all appended together. Because unique(scraped) includes source_url, duplicates with different page URLs are not collapsed, which can inflate counts and create duplicate request entries in the CSV.
Useful? React with 👍 / 👎.
Motivation
Description
atip_requests_updater.Rwhich constructs a search URL againsthttps://open.canada.ca/en/search/atiand paginates results up to a configurableATIP_MAX_PAGES.date,pages,description, andfile_number.department,source_url,scraped_at_utc), and orders the output with the requested columns first.file_number) to the configuredATIP_OUTPUT_CSV, and includes a CRON/n8n usage example in the script header.Testing
Rscript -e "parse(file='atip_requests_updater.R')"but the check could not run becauseRscriptis not installed in this environment.curlwhich returned403 Forbidden, so live scraping could not be validated in this environment.Codex Task