def __init__(self, record=None):
        if record is None:
            record = lbsn.Event()

        self.origin_id = record.pkey.origin.origin_id
        self.event_guid = record.pkey.id
        self.name = HF.null_check(record.name)
        self.event_latlng = HF.null_geom_check(record.event_latlng)
        self.event_area = HF.null_check(record.event_area)
        self.event_website = HF.null_check(record.event_website)
        self.event_date = HF.null_check_datetime(record.event_date)
        self.event_date_start = HF.null_check_datetime(record.event_date_start)
        self.event_date_end = HF.null_check_datetime(record.event_date_end)
        self.duration = HF.null_check(record.duration)
        self.place_guid = HF.null_check(record.place_pkey.id)
        self.city_guid = HF.null_check(record.city_pkey.id)
        self.country_guid = HF.null_check(record.country_pkey.id)
        self.user_guid = HF.null_check(record.user_pkey.id)
        self.event_description = HF.null_check(record.event_description)
        self.event_type = HF.null_check(record.event_type)
        self.event_share_count = HF.null_check(record.event_share_count)
        self.event_like_count = HF.null_check(record.event_like_count)
        self.event_comment_count = HF.null_check(record.event_comment_count)
        self.event_views_count = HF.null_check(record.event_views_count)
        self.event_engage_count = HF.null_check(record.event_engage_count)
Ejemplo n.º 2
0
 def type_sql_mapper(cls):
     """Assigns record types to SQL Insert SQLs"""
     type_sql_mapping = {
         lbsn.Origin().DESCRIPTOR.name: cls.origin_insertsql,
         lbsn.Country().DESCRIPTOR.name: cls.country_insertsql,
         lbsn.City().DESCRIPTOR.name: cls.city_insertsql,
         lbsn.Place().DESCRIPTOR.name: cls.place_insertsql,
         lbsn.User().DESCRIPTOR.name: cls.user_insertsql,
         lbsn.UserGroup().DESCRIPTOR.name: cls.usergroup_insertsql,
         lbsn.Post().DESCRIPTOR.name: cls.post_insertsql,
         lbsn.Event().DESCRIPTOR.name: cls.event_insertsql,
         lbsn.PostReaction().DESCRIPTOR.name: cls.postreaction_insertsql,
     }
     return type_sql_mapping
 def func_prepare_selector(self, record):
     """Select correct prepare function according to record type"""
     dict_switcher = {
         lbsn.Origin().DESCRIPTOR.name: self.prepare_lbsn_origin,
         lbsn.Country().DESCRIPTOR.name: self.prepare_lbsn_country,
         lbsn.City().DESCRIPTOR.name: self.prepare_lbsn_city,
         lbsn.Place().DESCRIPTOR.name: self.prepare_lbsn_place,
         lbsn.User().DESCRIPTOR.name: self.prepare_lbsn_user,
         lbsn.UserGroup().DESCRIPTOR.name: self.prepare_lbsn_usergroup,
         lbsn.Post().DESCRIPTOR.name: self.prepare_lbsn_post,
         lbsn.Event().DESCRIPTOR.name: self.prepare_lbsn_event,
         lbsn.PostReaction().DESCRIPTOR.name:
         self.prepare_lbsn_postreaction,
         lbsn.Relationship().DESCRIPTOR.name: self.prepare_lbsn_relation
     }
     prepare_function = dict_switcher.get(record.DESCRIPTOR.name)
     return prepare_function(record)
Ejemplo n.º 4
0
 def extract_event(cls, record, origin):
     event = HF.new_lbsn_record_with_id(lbsn.Event(),
                                        record.get('event_guid'), origin)
     set_lbsn_attr(event, "name", record)
     event_latlng = record.get("event_latlng")
     if event_latlng:
         setattr(event, "event_latlng", parse_geom(event_latlng))
     event_area = record.get("event_area")
     if event_area:
         setattr(event, "event_area", parse_geom(event_area))
     set_lbsn_attr(event, "event_website", record)
     event_date = record.get('event_date')
     if event_date:
         copydate_lbsn_attr(event.event_date, event_date)
     event_date_start = record.get('event_date_start')
     if event_date_start:
         copydate_lbsn_attr(event.event_date_start, event_date_start)
     event_date_end = record.get('event_date_end')
     if event_date_end:
         copydate_lbsn_attr(event.event_date_end, event_date_end)
     duration = record.get('duration')
     if duration:
         copyduration_lbsn_attr(event.duration, duration)
     place_guid = record.get('place_guid')
     if place_guid:
         set_lbsn_pkey(event.place_pkey, lbsn.Place(),
                       record.get('place_guid'), origin)
     city_guid = record.get('city_guid')
     if city_guid:
         set_lbsn_pkey(event.city_pkey, lbsn.City(),
                       record.get('city_guid'), origin)
     country_guid = record.get('country_guid')
     if country_guid:
         set_lbsn_pkey(event.country_pkey, lbsn.Country(),
                       record.get('country_guid'), origin)
     set_lbsn_pkey(event.user_pkey, lbsn.User(), record.get('user_guid'),
                   origin)
     set_lbsn_attr(event, "event_description", record)
     set_lbsn_attr(event, "event_type", record)
     set_lbsn_attr(event, "event_share_count", record)
     set_lbsn_attr(event, "event_like_count", record)
     set_lbsn_attr(event, "event_comment_count", record)
     set_lbsn_attr(event, "event_views_count", record)
     set_lbsn_attr(event, "event_engage_count", record)
     return event
Ejemplo n.º 5
0
 def get_func_record(cls,
                     record: Dict[str, Any],
                     input_type: Optional[str] = None):
     """Returns mapping function for input_type"""
     FUNC_MAP = {
         lbsn.Origin().DESCRIPTOR.name: cls.extract_origin,
         lbsn.Country().DESCRIPTOR.name: cls.extract_country,
         lbsn.City().DESCRIPTOR.name: cls.extract_city,
         lbsn.Place().DESCRIPTOR.name: cls.extract_place,
         lbsn.UserGroup().DESCRIPTOR.name: cls.extract_usergroup,
         lbsn.User().DESCRIPTOR.name: cls.extract_user,
         lbsn.Post().DESCRIPTOR.name: cls.extract_post,
         lbsn.PostReaction().DESCRIPTOR.name: cls.extract_postreaction,
         lbsn.Event().DESCRIPTOR.name: cls.extract_event,
     }
     func_map = FUNC_MAP.get(input_type)
     # create origin always the same
     origin = lbsn.Origin()
     origin.origin_id = record.get('origin_id')
     return func_map(record, origin)