Example #1
0
 def get_address(self, coords):
     results = self.do_geocode({'q': coords.replace(' ', '')})
     if not results:
         return None
     address = dict(results[0]['components'])
     if 'county_code' in address and 'county' in address:
         del address['county_code']
     if 'state_code' in address and 'state' in address:
         del address['state_code']
     return Location.from_address(address, self.address_map)
Example #2
0
 def get_address(self):
     results = self.do_geocode(
         {'q': self.coords.get_value().replace(' ', '')})
     if not results:
         return
     address = dict(results[0]['components'])
     if 'county_code' in address and 'county' in address:
         del address['county_code']
     if 'state_code' in address and 'state' in address:
         del address['state_code']
     self.new_location(self.location_info.currentWidget(),
                       Location.from_address(address, self.address_map))
Example #3
0
 def _merge_metadata(self, photo_id, image):
     photo = self.session.get_info(photo_id)
     if not photo:
         return
     md = image.metadata
     # sync title
     title = html.unescape(photo['title']['_content'])
     if md.title:
         md.title = md.title.merge(
             image.name + '(title)', 'flickr title', title)
     else:
         md.title = title
     # sync description
     description = html.unescape(photo['description']['_content'])
     if md.description:
         md.description = md.description.merge(
             image.name + '(description)', 'flickr description', description)
     else:
         md.description = description
     # sync keywords
     tags = []
     for tag in photo['tags']['tag']:
         if tag['raw'] == 'uploaded:by=photini':
             continue
         if md.location_taken and tag['raw'] in (
                 md.location_taken['CountryCode'],
                 md.location_taken['CountryName'],
                 md.location_taken['ProvinceState'],
                 md.location_taken['City']):
             continue
         tags.append(tag['raw'])
     md.keywords = md.keywords.merge(
         image.name + '(keywords)', 'flickr tags', tags)
     # sync location
     if 'location' in photo:
         location = photo['location']
         latlong = LatLon((location['latitude'], location['longitude']))
         if md.latlong:
             md.latlong = md.latlong.merge(
                 image.name + '(latlong)', 'flickr location', latlong)
         else:
             md.latlong = latlong
         address = {}
         for key in location:
             if '_content' in location[key]:
                 address[key] = location[key]['_content']
         location_taken = Location.from_address(address, self._address_map)
         if md.location_taken:
             md.location_taken = md.location_taken.merge(
                 image.name + '(location_taken)', 'flickr location',
                 location_taken)
         else:
             md.location_taken = location_taken
     # sync date_taken
     if photo['dates']['takenunknown'] == '0':
         granularity = int(photo['dates']['takengranularity'])
         if granularity >= 6:
             precision = 1
         elif granularity >= 4:
             precision = 2
         else:
             precision = 6
         date_taken = DateTime((
             datetime.strptime(
                 photo['dates']['taken'], '%Y-%m-%d %H:%M:%S'),
             precision, None))
         if md.date_taken:
             md.date_taken = md.date_taken.merge(
                 image.name + '(date_taken)', 'flickr date taken', date_taken)
         else:
             md.date_taken = date_taken
Example #4
0
 def _merge_metadata(self, photo_id, image):
     try:
         rsp = self.session.photos.getInfo(photo_id=photo_id)
     except flickrapi.FlickrError as ex:
         logger.error(str(ex))
         return
     if rsp['stat'] != 'ok':
         return
     photo = rsp['photo']
     md = image.metadata
     h = HTMLParser()
     # sync title
     title = h.unescape(photo['title']['_content'])
     if md.title:
         md.title = md.title.merge(image.name + '(title)', 'flickr title',
                                   title)
     else:
         md.title = title
     # sync description
     description = h.unescape(photo['description']['_content'])
     if md.description:
         md.description = md.description.merge(image.name + '(description)',
                                               'flickr description',
                                               description)
     else:
         md.description = description
     # sync keywords
     tags = []
     for tag in photo['tags']['tag']:
         if tag['raw'] == 'uploaded:by=photini':
             continue
         if md.location_taken and tag['raw'] in (
                 md.location_taken.country_code,
                 md.location_taken.country_name,
                 md.location_taken.province_state, md.location_taken.city):
             continue
         tags.append(tag['raw'])
     md.keywords = md.keywords.merge(image.name + '(keywords)',
                                     'flickr tags', tags)
     # sync location
     if 'location' in photo:
         location = photo['location']
         latlong = LatLon((location['latitude'], location['longitude']))
         if md.latlong:
             md.latlong = md.latlong.merge(image.name + '(latlong)',
                                           'flickr location', latlong)
         else:
             md.latlong = latlong
         address = {}
         for key in location:
             if '_content' in location[key]:
                 address[key] = location[key]['_content']
         location_taken = Location.from_address(address, self._address_map)
         if md.location_taken:
             md.location_taken = md.location_taken.merge(
                 image.name + '(location_taken)', 'flickr location',
                 location_taken)
         else:
             md.location_taken = location_taken
     # sync date_taken
     if photo['dates']['takenunknown'] == '0':
         granularity = int(photo['dates']['takengranularity'])
         if granularity >= 6:
             precision = 1
         elif granularity >= 4:
             precision = 2
         else:
             precision = 6
         date_taken = DateTime(
             (datetime.strptime(photo['dates']['taken'],
                                '%Y-%m-%d %H:%M:%S'), precision, None))
         if md.date_taken:
             md.date_taken = md.date_taken.merge(
                 image.name + '(date_taken)', 'flickr date taken',
                 date_taken)
         else:
             md.date_taken = date_taken