Skip to content

Instantly share code, notes, and snippets.

@benjuang
Last active May 28, 2018 21:22
Show Gist options
  • Save benjuang/ffef87ba1ca7bf833ef76226830d4e93 to your computer and use it in GitHub Desktop.
Save benjuang/ffef87ba1ca7bf833ef76226830d4e93 to your computer and use it in GitHub Desktop.
Foodspotting json to curl

Note Alternative here for the less technically inclined: https://codepen.io/benjuang/full/mKbGaV. It does not download files with nicer filenames, but you'll have a copy of all of your images.

What this does

This converts each json object from something like:

  {
    "title": "Seafood Mos Burger",
    "caption": "Wheee rice bun. Why don't they have this in the US?",
    "restaurantName": "Mos Burger",
    "url": "http://ot-foodspotting-production.s3.amazonaws.com/extract/126b9e83-1749-41d5-87ca-4ff5f31fb41e/1140198.jpg",
    "whenTaken": "2011-12-19T07:39:06Z"
  },

to:

curl "http://ot-foodspotting-production.s3.amazonaws.com/extract/126b9e83-1749-41d5-87ca-4ff5f31fb41e/1140198.jpg" --output "2011-12-19T07:39:06Z-Mos Burger-Seafood Mos Burger-1140198.jpg"

making it easy to run the entire file as a shell script and download all of your images in one go.

Note: Captions are not included in the filenames. Also, certain filesystems don't support the : character, so that may get converted to / characters.

Instructions

Step 1:

Open your foodspotting.json file in Sublime Text (or any other editor like Notepad++ that'll do regex searches)

Step 2:

In Sublime Text, go to View > Line Endings and switch it over to Unix and then save. Google "your editor name here Line endings" for other text editors.

Now use "Save as.." and save your file as foodspotting.sh

Step 3:

Use the Search and replace tool. In Sublime Text, it's in the Find menu > Replace...

Find:

  {
    "title": "(.*)",(?:
    "caption": ".*",)?
    "restaurantName": "(.*)",
    "url": "(.*)/(\d+\.jpg)",
    "whenTaken": "(.*)"
  },?

Replace:

curl "\3/\4" --output "\5-\2-\1-\4"

Step 4:

Find and Replace again (this replaces any / characters in the output file name with -s). It might be a good idea to do this multiple times (or until it tells you that no matches were found)

Find:

--output (.*)/(.*)

Replace:

--output \1-\2

Step 5:

Remove the [ and ] at the first and last lines of the file.

Step 6:

Open a terminal, type chmod 777 and then either drag the file onto the terminal window or type in the file. Something like: Computer:~ ben$ chmod 777 /Users/ben/Downloads/foodspotting/foodspotting.sh or Computer:~ ben$ chmod 777 foodspotting.sh (if you're in the same directory as the foodspotting.sh file) Hit enter to make the file executable.

Step 6:

Run foodspotting.sh. If you're in the same directory as the foodspotting.sh file, typing ./foodspotting.sh and hitting enter should work. You should see lots of messages indicating it's downloading stuff. Check the directory the foodspotting.sh file is in - that's where images should show up.

Step 7:

Make a backup for your original foodspotting.json file. Backup these images.

Disclaimer: I don't work for foodspotting, I'm just a sad user.

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