waze_favorites.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const log = require('../util/log')
  2. const path = require('path')
  3. const sqlite3 = require('sqlite3')
  4. const bplist = require('bplist-parser')
  5. const fs = require('fs')
  6. const plist = require('plist')
  7. // Derive filenames based on domain + file path
  8. const fileHash = require('../util/backup_filehash')
  9. const database = fileHash('Documents/user.db', 'AppDomain-com.waze.iphone')
  10. module.exports.name = 'waze_favorites'
  11. module.exports.description = 'List Waze app favorite places'
  12. // Specify this reporter requires a backup.
  13. // The second parameter to func() is now a backup instead of the path to one.
  14. module.exports.requiresBackup = true
  15. // Specify this reporter supports the promises API for allowing chaining of reports.
  16. module.exports.usesPromises = true
  17. module.exports.func = function (program, backup, resolve, reject) {
  18. wazeReport(backup)
  19. .then((items) => {
  20. var result = program.formatter.format(items, {
  21. program: program,
  22. columns: {
  23. 'Name': el => el.name,
  24. 'Modified Date': el => (new Date((el.modified_time) * 1000).toDateString()) + ' ' + (new Date((el.modified_time) * 1000).toTimeString()) ,
  25. 'Latitude': el => el.latitude / 1000000,
  26. 'Longitude': el => el.longitude / 1000000,
  27. 'Street': el => el.street,
  28. 'City': el => el.city,
  29. 'State': el => el.state,
  30. 'Country': el => el.country
  31. }
  32. })
  33. resolve(result)
  34. })
  35. .catch(reject)
  36. }
  37. function KeyValue (property, plist) {
  38. this.key = property
  39. this.value = plist[property] ? plist[property] : 'N/A'
  40. }
  41. const wazeReport = (backup) => {
  42. return new Promise((resolve, reject) => {
  43. var wazedb = backup.getDatabase(database)
  44. try {
  45. const query = `
  46. 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
  47. left join PLACES on FAVORITES.place_id = PLACES.id
  48. order by rank
  49. `
  50. wazedb.all(query, async function (err, rows) {
  51. if (err) reject(err)
  52. resolve(rows)
  53. })
  54. } catch (e) {
  55. reject(e)
  56. }
  57. })
  58. }