Skip to content

Commit

Permalink
First stable Flickr mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieboldianus committed Dec 4, 2018
1 parent 5ec719d commit ff61db4
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lbsntransform/classes/field_mapping_flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
from .helper_functions import HelperFunctions as HF
from .helper_functions import LBSNRecordDicts
from lbsnstructure.lbsnstructure_pb2 import *
from google.protobuf.timestamp_pb2 import Timestamp
#from google.protobuf.timestamp_pb2 import Timestamp
#from lbsnstructure.external.timestamp_pb2 import Timestamp
import shapely.geometry as geometry
from shapely.geometry.polygon import Polygon
#import shapely.geometry as geometry
#from shapely.geometry.polygon import Polygon
import logging
import re
#import re
from decimal import Decimal
# for debugging only:
from google.protobuf import text_format


class FieldMappingFlickr():
def __init__(self, disableReactionPostReferencing=False, geocodes=False, mapFullRelations=False):
# We're dealing with Twitter in this class, lets create the OriginID
Expand Down Expand Up @@ -39,7 +41,7 @@ def parse_csv_record(self, record):
skippedCount += 1
return
else:
self.parse_flickr_post(record)
self.extract_flickr_post(record)

def extract_flickr_post(self, record):
"""Main function for processing Flickr CSV entry.
Expand All @@ -62,9 +64,7 @@ def extract_flickr_post(self, record):
if userRecord:
postRecord.user_pkey.CopyFrom(userRecord.pkey)
self.lbsnRecords.AddRecordsToDict(userRecord)
l_lng = Decimal(record[2])
l_lat = Decimal(record[1])
postRecord.post_latlng = self.flickr_extract_postlatlng(l_lat, l_lng)
postRecord.post_latlng = self.flickr_extract_postlatlng(record)
geoaccuracy = FieldMappingFlickr.flickr_map_geoaccuracy(record[13])
if geoaccuracy:
postRecord.post_geoaccuracy = geoaccuracy
Expand Down Expand Up @@ -94,9 +94,9 @@ def extract_flickr_post(self, record):
if record_media_type and record_media_type == "video":
postRecord.post_type = lbsnPost.VIDEO
else:
postRecord.post_type = lbsnPost.PHOTO
postRecord.post_content_license = record[14]
return postRecord
postRecord.post_type = lbsnPost.IMAGE
postRecord.post_content_license = valueCount(record[14])
self.lbsnRecords.AddRecordsToDict(postRecord)

@staticmethod
def reverse_csv_comma_replace(csv_string):
Expand All @@ -117,12 +117,14 @@ def flickr_map_geoaccuracy(flickr_geo_accuracy_level):
flickr_geo_accuracy_level Geoaccuracy Level returned from Flickr (String, e.g.: "Level12")
"""
lbsn_geoaccuracy = False
if isinstance(flickr_geo_accuracy_level.lstrip('Level'), int):
if flickr_geo_accuracy_level >= 15:
stripped_level = flickr_geo_accuracy_level.lstrip('Level').strip()
if stripped_level.isdigit():
stripped_level = int(stripped_level)
if stripped_level >= 15:
lbsn_geoaccuracy = lbsnPost.LATLNG
elif flickr_geo_accuracy_level >= 12:
elif stripped_level >= 12:
lbsn_geoaccuracy = lbsnPost.PLACE
elif flickr_geo_accuracy_level >= 8:
elif stripped_level >= 8:
lbsn_geoaccuracy = lbsnPost.CITY
else:
lbsn_geoaccuracy = lbsnPost.COUNTRY
Expand Down

0 comments on commit ff61db4

Please sign in to comment.