def within(self, *timespans): for beginning, end in timespans: if type(beginning) == str: beginning = str_to_datetime(beginning) if type(end) == str: end = str_to_datetime(end) if self.timestamp < beginning or self.timestamp > end: return False return True
def to_record(self): # limit API calls time_shot_utc = self.time_shot_utc timestamp = str_to_datetime(time_shot_utc) return { 'source': self.source, 'filename': self.filename, 'path': self.path, 'timestamp': timestamp, 'time_shot_utc': time_shot_utc, 'time_shot_local': self.time_shot_local, 'time_rendered': self.time_rendered, 'geotagged': self.geotagged, 'latitude': self.latitude, 'longitude': self.longitude }
def is_later(x): if type(x.time_uploaded) == float and np.isnan(x.time_uploaded): return True else: return str_to_datetime(x.time_uploaded) < str_to_datetime(x.time_rendered)
def timestamp(self): return str_to_datetime(self.time_shot_utc)
def time_shot_utc(self): """ Four cases: 1. GPS time included --> in UTC already 2. GPS included, no GPS time --> TimeZones API to get UTC 3. No GPS, but local time --> TimeZones API to get UTC, using KW for location 4. No GPS, non-local (camera) --> constant offset to UTC """ # Case 1 if self.geotagged: try: UTC_DATE = self.exif.gps_datestamp UTC_TIME = self.exif.gps_timestamp UTC_TIMESTAMP = UTC_DATE + ' ' + '{:02d}:{:02d}:{:02d}'.format( *[int(t) for t in UTC_TIME]) # make sure GPS time matches local time (rare, but happens) to_time = lambda x: time(int(x[0]), int(x[1]), int(x[2] // 1)) LOCAL_TIME = str_to_datetime(self.exif.datetime_original) delta = lambda x, y: abs((x.minute - y.minute) * 60 + (x.second - y.second)) if delta(to_time(UTC_TIME), LOCAL_TIME.time()) > 60: raise ValueError('GPS Timestamp is off.') except: location = (self.latitude, self.longitude) naive_dt = str_to_datetime(self.time_shot_local) UTC_TIMESTAMP = query_utc(naive_dt, self.tz_keyword, location=location) else: # CASE 3 if 'iPhone' in self.source: naive_dt = str_to_datetime(self.time_shot_local) UTC_TIMESTAMP = query_utc(naive_dt, self.tz_keyword, location=None) # CASE 4: # Initially, camera was in EST, 5h behind UTC # As of 2019-10-09 camera was in PST, 8h behind UTC else: camera_dt = str_to_datetime(self.time_shot_local) if camera_dt <= str_to_datetime('2019:10:09 00:00:00'): UTC_OFFSET = timedelta(hours=5) else: UTC_OFFSET = timedelta(hours=8) utc_dt = camera_dt + UTC_OFFSET UTC_TIMESTAMP = datetime_to_str(utc_dt) return UTC_TIMESTAMP