# How to automatically upload the daily NYT crossword to Dropbox

2023-03-13

![](//images.ctfassets.net/gkzlwgn72prn/2DZAkz4sC5FQ21NA9ZdBzN/743db5c2ddf896f28bc6dff4def4c57c/supernote-1.jpg)

This guide will walk you through the steps to automatically upload the daily NYT to your personal Dropbox account so that it can be synced with devices like the [Ratta Supernote](https://supernote.com) e-ink tablet.

Throughout the course of this tutorial, you will create a Dropbox developer app, generate a Dropbox refresh token, and deploy a cron job to Render.com.

Please note that Render.com does charge for this service, but the fees should be extremely minimal (approx. $1/mo).

[[toc]]

---

## Step 0: Pre-requisites

* A [Dropbox account](https://dropbox.com).
* A NY Times [puzzle subscription](https://www.nytimes.com/subscription/games).
* Enough technical know-how to access your computer's terminal, make `cURL` requests, and access your browser's developer console.
* About $1 to spend per month.

## Step 1: Create a Dropbox developer app

First, you need to create your own personal Dropbox developer app. Don't worry, the app won't be publicly available. It will just allow you to use Dropbox's APIs to upload files.

Navigate to your [App Console](https://www.dropbox.com/developers/apps/) on the Dropbox Developer portal, and [create a new app](https://www.dropbox.com/developers/apps/create).

![image](//images.ctfassets.net/gkzlwgn72prn/7p9BMAaz5cn8d407wP4iey/cb4c44bbe8bc8293b7eebcb102a1ab64/image.png)

You will now configure your application.

For *Step 1.*, choose __Scoped access__.

![Screenshot from 2023-03-12 17-53-22](//images.ctfassets.net/gkzlwgn72prn/756Y0mFmtK0heVT5F0uONq/bc73b1ba849d35d999af655a4a728029/Screenshot_from_2023-03-12_17-53-22.png)

For *Step 2.*, choose __Full Dropbox__.

![Screenshot from 2023-03-12 17-53-34](//images.ctfassets.net/gkzlwgn72prn/208xmZOBVgekprgL8vgOEC/c59809037409403dbd0cacbe4be57bf8/Screenshot_from_2023-03-12_17-53-34.png)

For *Step 3.*, enter something meaningful like __NYT Crossword__.

You *may* also have a *Step 4.* if your personal Dropbox account is linked to a business Dropbox account. If you see this step, simply choose the account which you want to create the app with.

![Screenshot from 2023-03-12 17-53-55](//images.ctfassets.net/gkzlwgn72prn/4V9MJkgEjSiRi2Imi0kJeR/af16c7bbf9cb68cd141bf9e276e89595/Screenshot_from_2023-03-12_17-53-55.png)

Click __Create app__ to finish.

On the next page, take note of your *App key* and *App secret*. We'll need these multiple times in the future.

![image](//images.ctfassets.net/gkzlwgn72prn/3byfo3LYzL0VzGjiVXL2M6/3046f0ebb337f688ce5890bca195649a/image.png)

Navigate to *Permissions* and select the checkbox for *files.content.write*. This is because your app will need to be able to write to your Dropbox account in order to upload the daily NYT crossword.

![Screenshot from 2023-03-12 17-55-28](//images.ctfassets.net/gkzlwgn72prn/7b6zqMplSCsFScSN8VdNX/32dea4b195488f244f754d60b1595599/Screenshot_from_2023-03-12_17-55-28.png)

Click __Submit__ at the bottom to save your changes.

![image](//images.ctfassets.net/gkzlwgn72prn/6MR86g1r7FKvZwIxBLbYed/1b9ff44d51b4f06b8c5a5285b11b67e4/image.png)

## Step 2: Generate a Dropbox refresh token

In order to interact with the Dropbox's API to upload files, we need to obtain a refresh token.

To do this, first you'll need to authorize the app on your account and obtain an access code.

To generate an access code for you account, visit the following URL in your web browser, making sure to replace `<app key>` with your Dropbox app's *App key*.

```
https://www.dropbox.com/oauth2/authorize?client_id=<app key>&token_access_type=offline&response_type=code
```

When you land on this page, you will see a warning about the kind of permissions the app will have on your account if you authorize it. Since this is your *your* Dropbox app with your App key and not anyone else's, you can disregard this warning, and click __Continue__ to move on to the next step.

![image](//images.ctfassets.net/gkzlwgn72prn/2mPSimu5gQwT4n19AXRCko/4037583934ab5cbed865cf5314a7e777/image.png)

The next step will be to approve the app for your account.

Like in step 1, you might be given an option to choose which account to authorize. If you only have one, disregard.

Approve your app and link it to your account.

![image](//images.ctfassets.net/gkzlwgn72prn/5EyTY4lL0ydMfBUh0acnZw/03542352716f7abd935fbb3faecf3465/image.png)

On the next screen, you will see your access code. Copy this or write it down somewhere, you will need it in just a moment.

__Note: You will need to do the next step within approximately five minutes, or the access token will expire.__ If the token has expired, simply open a new tab with that URL you generated a few steps ago and re-authorize the application.

![image](//images.ctfassets.net/gkzlwgn72prn/3eSTAHAkgk2ZJCYwjr8ht/113c9e62e8ab2f4716e123e9f3d9124d/image.png)

Now let's create a refresh token.  

To do this, you'll need to make the following cURL request from your terminal, being sure to replace some of the parameters with your own values you obtained in previous steps.

```
curl https://api.dropbox.com/oauth2/token \
    -d code=<access code> \
    -d grant_type=authorization_code \
    -d client_id=<app key> \
    -d client_secret=<app secret> | jq '.refresh_token'
```

Replace `<access code>` with the access code you just received.

Replace `<app key>` with your Drobox app's *App key* from Step 1.

Replace `<app secret>` with your Drobox app's *App secret* from Step 1.

![image (9)](//images.ctfassets.net/gkzlwgn72prn/4DsoBXFZiNSO89W6CKzDcm/85fb450e725794645346d90a58ffe73e/image__9_.jpg)

You should receive a response with a long string of characters. This is your refresh token. Write it down (*without* the surrounding quotes `'...'`), as you will need it later.

## Step 3: Obtain your NYT cookie

Since the NY Times crossword is a paid service, you will need to tell nytimes.com who you are when you make the web request.

Go to nytimes.com, and log in to your account with a paid puzzles subscription.

Next, open the developer console for your web browser.

![image](//images.ctfassets.net/gkzlwgn72prn/67t685yGkpWtIR8vzKDMsZ/d51a45326d9b45abdb42788e4f7fd33c/image.png)

Navigate to the `console` tab.

Type and enter ↴

```
document.cookie
```

This will return the full list of your unique cookies for nytimes.com. This tells nytimes.com who you are and which account to display on the webapge.

You only need a few of these, but it's easier to just copy the whole list.

![image (8)](//images.ctfassets.net/gkzlwgn72prn/2ZFVOnTCTtlJgtt6sME6wJ/e90c047b94fb03b6573948b023db8b76/image__8_.jpg)

Copy the entire output (*without* the surrounding quotes `'...'`) and write it down somewhere, you'll need this later.

## Step 4: Deploy the cron job

Sign up for an account on Render.com if you don't already have one.

Create a new *Cron job* project. A cron job is a task that runs at a specific time or times.

![image](//images.ctfassets.net/gkzlwgn72prn/1pS3X1GHk42jqMJESQFild/d9a02f23228a1a79d35580ccb8a2d365/image.png)

On the next screen, find *Public Git repository* and enter ↴

```
https://github.com/nathanbuchar/upload-daily-nyt-crossword-to-dropbox
```

This is the script that I've set up to do all the work for you. The code is open source, and [can be audited](https://github.com/nathanbuchar/upload-daily-nyt-crossword-to-dropbox) if you have any security concerns.

Alternatively, you can fork the app to your own GitHub if you have one so that you have control over the code.

![image](//images.ctfassets.net/gkzlwgn72prn/4g4eJnOtIODagtdQcro64m/c7378a21e2ee833c640eb708101396a8/image.png)

For the name, choose something like *daily-nyt*.

Choose *Node* for the runtime.

![image](//images.ctfassets.net/gkzlwgn72prn/2r5Tesq94I36m4SLiKqAoQ/927b45ac14bfb0afc3a0fd37305b389d/image.png)

For *schedule*, enter ↴

```
5 2,3,22,23 * * *
```

This means the task will run four times every day. We run it four times a day to account for the one hour shift during daylight saving time (DST) and puzzle release times on weekdays vs weekends (10pm vs 6pm). We run the task 5 minutes past the hour to increase our confidence that the NYT Crossword has been published when the task runs.

| UTC | Eastern |
| :-- | :----------- |
| 02:05 UTC | 10:05pm EDT |
| 03:05 UTC | 10:05pm EST |
| 22:05 UTC | 6:05pm EDT |
| 23:05 UTC | 6:05pm EST |

And then for *Command*, enter ↴

```
node index.js
```

![image](//images.ctfassets.net/gkzlwgn72prn/0s2wrFMvSbuiDhdndpLpF/f8845cc8188d21f5e91a2e376af33db8/image.png)

For *Instance type*, you should be more than covered with the cheapest tier, which at the time of this writing is the *Starter* tier.

Click __Advanced__. We now need to tailor the cron job for your specific Dropbox app and NY Times account.

You'll need to create *four* environment variables ↴

| Name | Value |
| :--- | :---- |
| `DROPBOX_APP_KEY` | Your Dropbox app's *App key* from Step 1. |
| `DROPBOX_APP_SECRET` | Your Dropbox app's *App secret* from Step 1. |
| `DROPBOX_REFRESH_TOKEN` | The refresh token you received from the cURL request in Step 1. |
| `NYT_COOKIE` | Your nytimes.com cookie from Step 2. |
| `DROPBOX_UPLOAD_PATH` | The path in your Dropbox folder where crosswords should be uploaded to. For the Ratta Supernote e-ink tablet, I'd recommend `/Supernote/Document/Crosswords`. __Note__: the path *must* start with a `/`. |

![image](//images.ctfassets.net/gkzlwgn72prn/7yFTA3IBa5tQIE7F47S0gv/f6f078c4aa3115430b0d97aff8d9ab2e/image.png)

Scroll down, and under *Auto-Deploy*, choose *No*. This is for your own security.

![image](//images.ctfassets.net/gkzlwgn72prn/4fkqdEVpGyHgEmSvr0u9JO/a7e7ebd57bba51a0e7abff74ccaa4439/image.png)

Scroll down and click __Create Cron Job__.

## Step 5. Sit back and wait!

Your Cron Job should be all set up now and should automatically upload a PDF of the daily NYT Crossword to your Dropbox account every day! 🎉

Note that your nytimes.com cookie expires after one year. If your app stops working, it's probably because you need to update the value of `NYT_COOKIE`.

If you run into any issues, please don't hesitate to [contact me](mailto:nate@naaaaaaaaaaaaaaaate.com).

Please consider leaving me a comment if you found any value in this guide. Take care!
	