Skip to content

Instantly share code, notes, and snippets.

@hallahan
Created May 18, 2020 20:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hallahan/15125ea6298fd0f13c86aa3b85e8c5d0 to your computer and use it in GitHub Desktop.
Save hallahan/15125ea6298fd0f13c86aa3b85e8c5d0 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const axios = require('axios')
const headers = {
cookie: '<insert cookie contents from your request headers once loged into site here>'
}
const PHOTOS_URL = 'https://www.gaiagps.com/api/objects/photo/?count=50000&page=1&routepoints=false&show_archived=true&show_filed=true&sort_direction=desc&sort_field=create_date'
const TRACKS_URL = 'https://www.gaiagps.com/api/objects/track?count=50000&page=1&routepoints=false&show_archived=true&show_filed=true&sort_direction=desc&sort_field=create_date'
const photoQueue = []
const photoTs = new Set()
getPhotos()
function getPhotos() {
axios({
method: 'GET',
url: PHOTOS_URL,
headers
}).then(response => {
const photos = response.data
for (let photo of photos) {
const fileName = `${photo.time_created}_${photo.id}.jpg`
const photoUrl = `https://www.gaiagps.com/api/objects/photo/${photo.id}/image/full/`
// lots of duplicates
if (!photoTs.has(photo.time_created)) {
photoQueue.push({ fileName, photoUrl })
photoTs.add(photo.time_created)
}
}
dlPhotos()
}).catch(err => {
console.error([`photos err`, err])
})
}
function dlPhotos() {
if (photoQueue.length === 0) {
console.log('done dl photos')
return
}
const { fileName, photoUrl } = photoQueue.pop()
const path = `${__dirname}/photos/${fileName}`
if (fs.existsSync(path)) {
console.log(`Photo exists: ${path}`)
dlPhotos()
return
}
axios({
method: 'GET',
url: photoUrl,
headers,
responseType: 'stream'
}).then(r => {
r.data.pipe(fs.createWriteStream(path))
console.log(`Saving photo: ${path}`)
dlPhotos()
}).catch(err => {
console.error([`photo err`, err])
dlPhotos()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment