waze_recents.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_recents'
  11. module.exports.description = 'List Waze app recent destinations'
  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. 'Id': el => el.id,
  24. 'Name': el => el.name,
  25. 'Created Date': el => (new Date((el.created_time) * 1000).toDateString()) + ' ' + (new Date((el.created_time) * 1000).toTimeString()) ,
  26. 'Access Date': el => (new Date((el.access_time) * 1000).toDateString()) + ' ' + (new Date((el.access_time) * 1000).toTimeString()) ,
  27. 'Latitude': el => el.latitude / 1000000,
  28. 'Longitude': el => el.longitude / 1000000,
  29. 'Street': el => el.street,
  30. 'City': el => el.city,
  31. 'State': el => el.state,
  32. 'Country': el => el.country
  33. }
  34. })
  35. resolve(result)
  36. })
  37. .catch(reject)
  38. }
  39. function KeyValue (property, plist) {
  40. this.key = property
  41. this.value = plist[property] ? plist[property] : 'N/A'
  42. }
  43. const wazeReport = (backup) => {
  44. return new Promise((resolve, reject) => {
  45. var wazedb = backup.getDatabase(database)
  46. try {
  47. const query = `
  48. select RECENTS.name, RECENTS.created_time, RECENTS.access_time, RECENTS.id, PLACES.latitude, PLACES.longitude, PLACES.street, PLACES.city, PLACES.state, PLACES.country from RECENTS
  49. left join PLACES on RECENTS.place_id = PLACES.id
  50. order by RECENTS.id
  51. `
  52. wazedb.all(query, async function (err, rows) {
  53. if (err) reject(err)
  54. resolve(rows)
  55. })
  56. } catch (e) {
  57. reject(e)
  58. }
  59. })
  60. }