|  | @@ -1,17 +1,8 @@
 | 
	
		
			
				|  |  |  #!/data/data/com.termux/files/usr/bin/python3
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import datetime as dt
 | 
	
		
			
				|  |  | -import json
 | 
	
		
			
				|  |  |  import os
 | 
	
		
			
				|  |  | -import pytz
 | 
	
		
			
				|  |  | -import subprocess
 | 
	
		
			
				|  |  |  import sys
 | 
	
		
			
				|  |  | -import yaml
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -def to_iso6801_basic(dt):
 | 
	
		
			
				|  |  | -    return dt.isoformat().replace(':', '').replace('-', '') \
 | 
	
		
			
				|  |  | -        .replace('+0000', 'Z')
 | 
	
		
			
				|  |  | +import termux_log_location
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  def symlink(src, dst, force=False):
 | 
	
	
		
			
				|  | @@ -20,48 +11,8 @@ def symlink(src, dst, force=False):
 | 
	
		
			
				|  |  |      os.symlink(src=src, dst=dst)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -class Position:
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    def __init__(self, timestamp, latitude, longitude, altitude):
 | 
	
		
			
				|  |  | -        self.timestamp = timestamp
 | 
	
		
			
				|  |  | -        self.latitude = latitude
 | 
	
		
			
				|  |  | -        self.longitude = longitude
 | 
	
		
			
				|  |  | -        self.altitude = altitude
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @classmethod
 | 
	
		
			
				|  |  | -    def from_termux_location(cls, provider='network'):
 | 
	
		
			
				|  |  | -        loc_json = subprocess.check_output(['termux-location', '-p', provider]) \
 | 
	
		
			
				|  |  | -            .decode(sys.stdout.encoding)
 | 
	
		
			
				|  |  | -        req_ts = dt.datetime.now(pytz.utc)
 | 
	
		
			
				|  |  | -        loc_attr = yaml.load(loc_json)
 | 
	
		
			
				|  |  | -        if not loc_attr:
 | 
	
		
			
				|  |  | -            return None
 | 
	
		
			
				|  |  | -        else:
 | 
	
		
			
				|  |  | -            return cls(
 | 
	
		
			
				|  |  | -                timestamp=req_ts -
 | 
	
		
			
				|  |  | -                    dt.timedelta(milliseconds=loc_attr['elapsedMs']),
 | 
	
		
			
				|  |  | -                latitude=loc_attr['latitude'],
 | 
	
		
			
				|  |  | -                longitude=loc_attr['longitude'],
 | 
	
		
			
				|  |  | -                altitude=loc_attr['altitude'],
 | 
	
		
			
				|  |  | -            )
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    def save_yaml(self, target_dir_path):
 | 
	
		
			
				|  |  | -        path = os.path.join(
 | 
	
		
			
				|  |  | -            target_dir_path,
 | 
	
		
			
				|  |  | -            '{}.yml'.format(to_iso6801_basic(self.timestamp)),
 | 
	
		
			
				|  |  | -        )
 | 
	
		
			
				|  |  | -        attr = {
 | 
	
		
			
				|  |  | -            'lat': self.latitude,
 | 
	
		
			
				|  |  | -            'lon': self.longitude,
 | 
	
		
			
				|  |  | -            'alt': self.altitude,
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        with open(path, 'w') as f:
 | 
	
		
			
				|  |  | -            f.write(yaml.dump(attr, default_flow_style=False))
 | 
	
		
			
				|  |  | -        return path
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  def compute(target_dir_path):
 | 
	
		
			
				|  |  | -    cur = Position.from_termux_location()
 | 
	
		
			
				|  |  | +    cur = termux_log_location.Position.from_termux_location()
 | 
	
		
			
				|  |  |      if cur:
 | 
	
		
			
				|  |  |          cur_path = cur.save_yaml(target_dir_path)
 | 
	
		
			
				|  |  |          symlink(
 |