Exemplo n.º 1
0
def fbpage_to_place(fbpage, save=False):
    if not fbpage.valid:
        return None

    p = Place()

    # special parking/hours objects used to serialize to DB
    # TODO: this is temporary. dig into django custom model field to make less hacky
    p.hours = fbpage.get_hours()
    parking = fbpage.get_parking()
    if parking:
        p.set_parking(parking)

    location = fbpage.get_location()
    if location is not None and save:
        location.save()

    p.location = location
    p.name = fbpage.get_field('name', '').strip()[:200]
    p.fb_id = fbpage.get_field('id', '').strip()[:50]
    p.description = fbpage.get_field('description', '').strip()
    # if no description, try 'about'
    if not p.description:
        p.description = fbpage.get_field('about', '').strip()
    p.phone = fbpage.get_field('phone', '').strip()[:200]
    p.url = fbpage.get_field('website', '').strip()
    if p.url:
        p.url = p.url.split()[0][:200]

    try:
        im_url = fbpage.get_picture_url(size='large')
        p.image = imagefile_from_url(im_url)
    except IOError:
        # TODO: log network/image format error
        pass

    if save:
        p.save()
    return p