コード例 #1
0
ファイル: tasks.py プロジェクト: relique/izba
def facebook_apartments():
    try:
        item = Apartment.objects.filter(
            published=True, 
            section='sale',
            rooms__gt=0,
            pub_date__range=[datetime.datetime.now()-datetime.timedelta(days=2), 
                             datetime.datetime.now()]
        ).exclude(image_1='').exclude(area='').order_by('-pub_date')[0]
    except IndexError as e:
        return

    try:
        social.FacebookPost.objects.get(item=item)
    except social.FacebookPost.DoesNotExist:
        pass
    else:
        return

    data = {'comment': u'Еженедельная подборка: %s-комн. квартира' % item.rooms,
            'name': u'%s-комн. квартира' % item.rooms,
            'link': BASEURL + item.get_absolute_url(),
            'caption': u'Цена: $' + humanize.intcomma(currency.convert_currency(item.price, 'USD')),
            'picture': BASEURL + item.image_1.url}
    
    if item.desc:
        data['description'] = item.desc
    else:
        data['description'] = u'Продаётся %s-комнатная квартира. Площадь %s \
                                кв.м.' % (item.rooms, item.area)

    social.FacebookPost.objects.create(item=item)
    post_to_fb(**data)
コード例 #2
0
ファイル: tasks.py プロジェクト: relique/izba
def facebook_telephones():
    try:
        item = Telephone.objects.filter(
            published=True, 
            pub_date__range=[datetime.datetime.now()-datetime.timedelta(hours=3*24), 
                             datetime.datetime.now()]
        ).exclude(image_1='').order_by('-pub_date')[0]
    except IndexError as e:
        return

    try:
        social.FacebookPost.objects.get(item=item)
    except social.FacebookPost.DoesNotExist:
        pass
    else:
        return

    data = {'comment': u'Ежедневная подборка: {0} {1}'.format(item.brand, 
                                                              item.model),
            'name': u'{0} {1}'.format(item.brand, item.model),
            'link': BASEURL + item.get_absolute_url(),
            'caption': u'Цена: {0} c.'.format(humanize.intcomma(item.price)),
            'picture': BASEURL + item.image_1.url}

    if item.desc:
        data['description'] = item.desc
    else:
        data['description'] = u'Продаётся телефон {0} {1} стандарта {2}.'\
                              .format(item.brand, 
                                      item.model, 
                                      item.conn_type.upper())

    social.FacebookPost.objects.create(item=item)
    post_to_fb(**data)
コード例 #3
0
ファイル: tasks.py プロジェクト: relique/izba
def facebook_autos():
    try:
        item = Automobile.objects.filter(
            published=True, 
            year__range=[1998, datetime.date.today().year],
            pub_date__range=[datetime.datetime.now()-datetime.timedelta(hours=10), 
                             datetime.datetime.now()]
        ).exclude(image_1='').order_by('-pub_date')[0]
    except IndexError as e:
        return

    try:
        social.FacebookPost.objects.get(item=item)
    except social.FacebookPost.DoesNotExist:
        pass
    else:
        return

    data = {'comment': u'Еженедельная подборка: %s %s' % (item.brand, item.model),
            'name': u'%s %s, %s г.' % (item.brand, item.model, item.year),
            'link': BASEURL + item.get_absolute_url(),
            'caption': u'Цена: $' + humanize.intcomma(currency.convert_currency(item.price, 'USD')),
            'picture': BASEURL + item.image_1.url}

    if item.desc:
        data['description'] = item.desc
    else:
        data['description'] = u'Продаётся автомобиль %s %s %s года.' \
                              % (item.brand, item.model, item.year)

    social.FacebookPost.objects.create(item=item)
    post_to_fb(**data)