示例#1
0
def logo(url):
    html_tree = helpers.open_url(url)
    img_url = helpers.get_logo(html_tree)
    image = urllib2.urlopen(img_url)
    mime_type = image.info()['Content-Type']


    return Response(image, status=200, mimetype=mime_type)
示例#2
0
def get_stations():
    import helpers
    from BeautifulSoup import BeautifulSoup
    
    stations = cache.get('stations')
    if not stations:
        page = helpers.open_url('http://www.bn.ru/zap_fl_w.phtml')
        soup = BeautifulSoup(page.read(), fromEncoding='utf-8')
        metro = soup.find('select', id='metro')
        stations = [(int(s['value']), s.string) for s in metro.contents]
        cache.set('stations', 'stations')
    return stations
示例#3
0
def search_results(request):
    stations = request.GET.getlist('stations')
    metro = '&metro[]=' + '&metro[]='.join(stations)
    for station in stations:
        metro += '&metro[]=%s' % station
    url = 'http://www.bn.ru/zap_fl.phtml?kkv1=%s&kkv2=%s&price1=%s&price2=%s' % (
             request.GET['rooms_from'], request.GET['rooms_to'],
             request.GET['price_from'], request.GET['price_to'],
         ) + metro + '&sorttype=0&sort_ord=0'
    print url
    page = helpers.open_url(url)
    soup = BeautifulSoup(page.read(), fromEncoding='utf-8')
    results = soup.find('table', 'results')
    apartments_soup = results.findAll(lambda tag: tag.name == 'a' and
                                 tag.get('href', '').endswith('search') and
                                 not tag.img)
    apartments = []
    for ap in apartments_soup:
        page = helpers.open_url('http://www.bn.ru' + ap['href'])
        soup = BeautifulSoup(page.read(), fromEncoding='utf-8')
        info = soup.find('div', 'inf_obj2_wr3')
        price = info.contents[0].contents[0].contents[1].contents[1].string
        subject = info.contents[0].contents[1].contents[1].contents[0].string
        if not subject:
            subject = info.contents[0].contents[1].contents[1].contents[0].\
                      contents[0].string
        try:
            phone = info.contents[0].contents[2].contents[1].contents[0].string
        except IndexError:
            phone = None
        apartments.append(Apartment(price, subject, phone))
    if request.GET.get('format', False) == 'ajax':
        template = 'results_ajax.html'
    else:
        template = 'results.html'
    return render(request, template, {'apartments': apartments})
示例#4
0
def images(url):
    html_tree = helpers.open_url(url)
    images = helpers.get_images(html_tree)
    dict = {'images': images}
    return jsonify(dict)
示例#5
0
def twitter(url):
    html_tree = helpers.open_url(url)
    twitter = helpers.get_twitter(html_tree)
    return jsonify(twitter)
示例#6
0
def og(url):
    html_tree = helpers.open_url(url)
    og = helpers.get_og(html_tree)
    return jsonify(og)
示例#7
0
def links(url):
    html_tree = helpers.open_url(url)
    links = helpers.get_links(html_tree)
    dict = {'links': links}
    return jsonify(dict)
示例#8
0
def meta(url):
    html_tree = helpers.open_url(url)
    meta = helpers.get_meta(html_tree)
    dict = {'meta': meta}
    return jsonify(dict)