fjxmlzn/FindMyHistory

Nextcloud PhoneTrack App Intergration & visualization

MitchellHicks opened this issue · 9 comments

I think this would provide an easy visual interface for people to follow the AirTags.

This is the Nextcloud App
https://apps.nextcloud.com/apps/phonetrack

This is the Page for Clients to send updates to the APP.
https://gitlab.com/eneiluj/phonetrack-oc/-/wikis/userdoc#logging-methods

It has a built in Post/Get option for adding History Points I am sure there are other options.

"HTTP request
You can build your own logging system and make GET or POST HTTP requests to PhoneTrack.
Here is an example of logging URL with POST:
https://your.server.org/NC_PATH_IF_NECESSARY/index.php/apps/phonetrack/logPost/TOKEN/DEVNAME
and with GET:
https://your.server.org/NC_PATH_IF_NECESSARY/index.php/apps/phonetrack/logGet/TOKEN/DEVNAME
The POST or GET parameters are:

lat (decimal latitude)
lon (decimal longitude)
alt (altitude in meters)
timestamp (epoch timestamp in seconds)
acc (accuracy in meters)
bat (battery level in percent)
sat (number of satellites)
useragent (device user agent)
speed (speed in meter per second)
bearing (bearing in decimal degrees)
"

Great Work on the Apple side..

That's a great proposal! I unfortunately do not have cycles in the near future to look into this. But anyone is welcome to contribute and make pull requests.

Chiming in to say this integration would be awesome. Unfortunately don't have the skill set to make it happen. Will be following this one for future reference though.

Yannik commented

Here is a very quick-and-dirty phonetrack integration:

diff --git a/lib/log_manager.py b/lib/log_manager.py
index fd8e79a..078ad78 100644
--- a/lib/log_manager.py
+++ b/lib/log_manager.py
@@ -79,12 +79,68 @@ class LogManager(object):
             writer = csv.writer(f)
             writer.writerow([data[k] for k in self._keys])
 
+    def _send_to_phonetrack(self, name, data):
+        #if not self.initialized:
+        import logging
+        if not hasattr(self, 'initialized'):
+            
+            logger = logging.getLogger()
+            logger.setLevel(logging.DEBUG)
+            formatter = logging.Formatter("[%(asctime)s] %(levelname)s: %(message)s")
+            
+            file_handler = logging.FileHandler('phonetrack.log')
+            file_handler.setLevel(logging.DEBUG)
+            file_handler.setFormatter(formatter)
+
+            logger.addHandler(file_handler)
+            self.initialized = True
+
+        if data['location|timeStamp'] == 'NULL':
+            logging.info("Ignoring call for %s with empty location data" % data['name'])
+            return
+
+        logging.info("New data for %s" % data['name'])
+
+        phonetrack_key = {
+            'Item Name': 'phonetrack-session-key',
+    
+        }
+        #logging.debug(data)
+
+        if data['name'] not in phonetrack_key:
+            logging.info("No phone key found for %s", data['name'])
+            return
+
+        url = 'https://XXXX/index.php/apps/phonetrack/logGet/%s/%s' % (phonetrack_key[data['name']], data["name"])
+        #logging.debug("Url: %s" % url)
+
+        params = {
+            'timestamp': data['location|timeStamp'],
+            'lat': data['location|latitude'],
+            'lon': data['location|longitude'],
+            'alt': data['location|altitude']
+        }
+
+        import requests
+        requests.get(url, params=params)
+            
+
     def refresh_log(self):
         items_dict = self._get_items_dict()
         for name in items_dict:
             if (name not in self._latest_log or
                     self._latest_log[name] != items_dict[name]):
                 self._save_log(name, items_dict[name])
+                self._send_to_phonetrack(name, items_dict[name])
                 self._latest_log[name] = items_dict[name]
                 self._log_cnt[name] += 1

Note: I will NOT provide any support for this. Use at your own risk.

I wanted to circle back after trying this out, but now so much time has passed, and it's still sitting on my to-do list. Figured I'd belatedly circle back and say thanks for the response. It's more than enough to play around with / build upon.

Awesome, no rush, but would definitely appreciate it.

Hey Mitchel, I would love to have the modded code, I just thought I would reply to remind you in case you forgot. Thank you.

I modded the code to work.. And have been out of town.. I will try to send you what I made to get it working its been running since a week after I asked. I frankly completely forgot about it.

On December 7, 2023 1:41:05 PM PST, Chris @.> wrote: I wanted to circle back after trying this out, but now so much time has passed, and it's still sitting on my to-do list. Figured I'd belatedly circle back and say thanks for the response. It's more than enough to play around with / build upon. -- Reply to this email directly or view it on GitHub: #11 (comment) You are receiving this because you authored the thread. Message ID: @.>