Skip to content

Instantly share code, notes, and snippets.

@fancyremarker
Created October 5, 2020 21:19
Show Gist options
  • Save fancyremarker/2f4edeeb85a9482d1db2192f71eaa623 to your computer and use it in GitHub Desktop.
Save fancyremarker/2f4edeeb85a9482d1db2192f71eaa623 to your computer and use it in GitHub Desktop.
Print stats for NYT crossword completion
require 'net/http'
require 'time'
require 'json'
require 'uri'
TOKEN = File.read('nyt-s.token').rstrip
API_BASE = 'https://nyt-games-prd.appspot.com/svc/crosswords'
DELAY = 0.1
START_DATE = Time.parse('2019-07-06')
END_DATE = Time.parse('2020-10-03')
def format_date(date)
date.strftime('%Y-%m-%d')
end
def each_puzzle_id(start_date, end_date, &block)
uri = URI.parse("#{API_BASE}/v3/66465332/puzzles.json")
args = {
publish_type: 'daily',
sort_order: 'desc',
sort_by: 'print_date',
date_start: format_date(start_date),
date_end: format_date(end_date)
}
uri.query = URI.encode_www_form(args)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['nyt-s'] = TOKEN
JSON.parse(http.request(request).body)['results'].each do |r|
yield [Time.parse(r['print_date']), r['puzzle_id']]
end
end
def seconds_to_solve(puzzle_id)
uri = URI.parse("#{API_BASE}/v6/game/#{puzzle_id}.json")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['nyt-s'] = TOKEN
JSON.parse(http.request(request).body)['calcs']['secondsSpentSolving']
end
d = END_DATE
while d > START_DATE
each_puzzle_id(START_DATE, d) do |date, puzzle_id|
d = date if date < d
puts [format_date(date), seconds_to_solve(puzzle_id)].join("\t")
sleep DELAY
end
end
@fancyremarker
Copy link
Author

  1. Figure out your nyt-s cookie value. In Chrome, open Developer Tools (⌥⌘I), navigate to your NYT Crossword Archive, click the Network tab of Developer Tools and find a request to the domain nyt-games-prd.appspot.com. Click on it, view the request headers, and copy the nyt-s cookie value:
    image
  2. Save this value to a file named nyt-s.token
  3. Run ruby print_puzzle_stats.rb

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