favorites.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const log = require('../../../util/log')
  2. const path = require('path')
  3. const sqlite3 = require('sqlite3')
  4. const fs = require('fs')
  5. // Derive filenames based on domain + file path
  6. const fileHash = require('../../../util/backup_filehash')
  7. const database = fileHash('Documents/user.db', 'AppDomain-com.waze.iphone')
  8. module.exports = {
  9. version: 4,
  10. name: 'waze_favorites',
  11. description: `List Waze app favorite places`,
  12. requiresBackup: true,
  13. // Run on a v3 lib / backup object.
  14. run (lib, { backup }) {
  15. return wazeReport(backup)
  16. },
  17. // Fields for apps report
  18. output: {
  19. 'Name': el => el.name,
  20. 'Modified Date': el => (new Date((el.modified_time) * 1000).toDateString()) + ' ' + (new Date((el.modified_time) * 1000).toTimeString()) ,
  21. 'Latitude': el => el.latitude / 1000000,
  22. 'Longitude': el => el.longitude / 1000000,
  23. 'Street': el => el.street,
  24. 'City': el => el.city,
  25. 'State': el => el.state,
  26. 'Country': el => el.country
  27. }
  28. }
  29. function KeyValue (property, plist) {
  30. this.key = property
  31. this.value = plist[property] ? plist[property] : 'N/A'
  32. }
  33. const wazeReport = (backup) => {
  34. return new Promise((resolve, reject) => {
  35. const query = `
  36. select FAVORITES.name, FAVORITES.created_time, FAVORITES.modified_time, FAVORITES.rank, PLACES.latitude, PLACES.longitude, PLACES.street, PLACES.city, PLACES.state, PLACES.country from FAVORITES
  37. left join PLACES on FAVORITES.place_id = PLACES.id
  38. order by rank `
  39. backup.openDatabase(database).then(database => {
  40. database.all(query, (err, rows) => {
  41. if (err) resolve(err)
  42. resolve(rows);
  43. })
  44. }).catch(reject)
  45. })
  46. }