Example #1
0
 def from_json(json):
     if json:
         item = YelpItem(
             id=json.get('id'),
             name=json.get('name'),
             image_url=json.get('image_url'),
             url=json.get('url'),
             phone=json.get('phone'),
             rating=json.get('rating'),
             review_count=json.get('review_count'),
             location=Location.from_json(json.get('location'))
         )
         return item
     return None
Example #2
0
 def from_json(json):
     item = Item(
         name=json.get('name'),
         yelp_category_id=json.get('yelp_category', {}).get('id'),
         yelp_category = YelpCategory.from_json(json.get('yelp_category')),
         plan_id=json.get('plan_id'),
         start_time=datetime.strptime(json.get('start_time'), "%Y-%m-%d %H:%M:%S %z") if json.get('start_time') is not None else None,
         end_time=datetime.strptime(json.get('end_time'), "%Y-%m-%d %H:%M:%S %z") if json.get('end_time') is not None else None,
         description=json.get("description"),
         type=json.get("type"),
         yelp_item_id=json.get('yelp_item', {}).get('id'),
         yelp_item=YelpItem.from_json(json.get('yelp_item')),
         location_id=json.get('location', {}).get('id'),
         location=Location.from_json(json.get('location'))
     )
     return item
Example #3
0
    def create_from_dict(dict):
        categories = []
        for tup in dict['categories']:
            categories += YelpCategory.get_from_yelp_tuple(tup)

        if len(categories) == 0:
            categories.append(YelpCategory.get_default())

        item = YelpItem(
            id=dict['id'],
            name=dict['name'],
            image_url=dict['image_url'] if 'image_url' in dict else None,
            url=dict['url'],
            phone=dict['phone'] if 'phone' in dict else None,
            rating=dict['rating'],
            review_count=dict['review_count'],
            location=Location.create_from_yelp_dict(dict['location']),
            categories=categories
        )
        return item