Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hacker News Datasette write demo #1928

Closed
simonw opened this issue Dec 2, 2022 · 7 comments
Closed

Hacker News Datasette write demo #1928

simonw opened this issue Dec 2, 2022 · 7 comments

Comments

@simonw
Copy link
Owner

simonw commented Dec 2, 2022

Idea is to have my existing scraper at https://github.com/simonw/scrape-hacker-news-by-domain also write to my private Datasette Cloud account, then create an atom feed from it.

@simonw
Copy link
Owner Author

simonw commented Dec 2, 2022

@simonw
Copy link
Owner Author

simonw commented Dec 2, 2022

This is the SQL view for the atom feed:

CREATE VIEW hacker_news_posts_atom as select
  id as atom_id,
  title as atom_title,
  url,
  commentsUrl as atom_link,
  dt || 'Z' as atom_updated,
  'Submitter: ' || submitter || ' - ' || points || ' points, ' || numComments || ' comments' as atom_content
from
  hacker_news_posts
order by
  dt desc
limit
  100;

@simonw
Copy link
Owner Author

simonw commented Dec 2, 2022

I created the hacker_news_posts table like this:

export ROWS=$(
  jq -n --argjson rows "$(cat simonwillison-net.json)" \
  '{ "table": "hacker_news_posts", "rows": $rows, "pk": "id", "replace": true }'
)
# Use curl to POST some JSON to a URL
curl -X POST \
  https://simon.datasette.cloud/data/-/create \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DS_TOKEN" \
  -d $ROWS

@simonw
Copy link
Owner Author

simonw commented Dec 2, 2022

But until I fix this issue:

I need to insert freshly scraped data like this:

export ROWS=$(
  jq -n --argjson rows "$(cat simonwillison-net.json)" \
  '{ "rows": $rows, "replace": true }'
)

curl -X POST \
  https://simon.datasette.cloud/data/hacker_news_posts/-/insert \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DS_TOKEN" \
  -d $ROWS

@simonw
Copy link
Owner Author

simonw commented Dec 2, 2022

Here's the change that should submit data to Datasette Cloud: simonw/scrape-hacker-news-by-domain@848bb7e

I ran delete from hacker_news_posts against my instance so https://simon.datasette.cloud/data/hacker_news_posts is now empty.

@simonw simonw transferred this issue from another repository Dec 2, 2022
@simonw simonw transferred this issue from simonw/temp Dec 2, 2022
@simonw simonw closed this as completed Dec 2, 2022
@simonw
Copy link
Owner Author

simonw commented Dec 2, 2022

Wrote about this extensively here: https://simonwillison.net/2022/Dec/2/datasette-write-api/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant