Skip to content

Commit

Permalink
update to use cookies instead of headers
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Feb 2, 2024
1 parent b1f4f67 commit 36daf9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ browsers' developer tools.
1. Navigate to <https://www.nytimes.com/crosswords>
1. Look for a request for some kind of json file e.g. `progress.json`, `mini-stats.json`, or
`stats-and-streaks.json`.
1. In the headers pane, find the value of `nyt-s` in the list of request headers. That is your
token. If you can't find the `nyt-s` header in the request, try a different json file.
1. In the headers pane, find the list of cookies, and fine `NYT-S` in that string. That is your
token. If you can't find the `NYT-S` cookie in the request, try a different json file.

### Under the hood

Expand All @@ -108,7 +108,7 @@ in your browser. Alternatively, you can supposedly extract your session cookie f
send that instead (see linked reddit post below), but I haven't tried it myself.

```sh
curl 'https://www.nytimes.com/svc/crosswords/v6/game/{id}.json' -H 'accept: application/json' -H 'nyt-s: {subscription_header}'
curl 'https://www.nytimes.com/svc/crosswords/v6/game/{id}.json' -H 'accept: application/json' --cookie 'NYT-S={subscription_header}'
```

1. Check out the `calcs` and `firsts` field of this response to get information like solve duration,
Expand Down
4 changes: 2 additions & 2 deletions src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use governor::state::direct::NotKeyed;
use governor::state::InMemoryState;
use governor::{Quota, RateLimiter};
use log::error;
use reqwest::header::{self, HeaderMap};
use reqwest::header::{self, HeaderMap, HeaderValue};
use reqwest::IntoUrl;
use serde::Deserialize;
use std::collections::HashMap;
Expand Down Expand Up @@ -119,9 +119,9 @@ impl RateLimitedClient {
/// * `quota` - Outgoing request quota in requests per second
pub fn new(nyt_s: &str, quota: NonZeroU32) -> Self {
let mut headers = HeaderMap::new();
headers.insert("nyt-s", nyt_s.parse().unwrap());
headers.insert(header::ACCEPT, "application/json".parse().unwrap());
headers.insert(header::DNT, "1".parse().unwrap());
headers.insert(header::COOKIE, HeaderValue::from_str(&format!("NYT-S={}", nyt_s)).unwrap());

let client = reqwest::ClientBuilder::new()
.user_agent("Scraping personal stats")
Expand Down

0 comments on commit 36daf9c

Please sign in to comment.