Exemplo n.º 1
0
 def run(self):
     try:
         self.engine, self.dbsession = db_connect()
         print("Renderizando audios gerais")
         query = self.dbsession.query(File).filter(File.type_ == 'audio')
         query = self.report_bundle.filter(File, query)
         n_pages = get_page(
             query,
             only_count=True,
             per_page=config_manager.report_config['per_page']['audio'])
         for i in range(n_pages):
             page = i + 1
             pagination = get_page(
                 query,
                 page=page,
                 per_page=config_manager.report_config['per_page']['audio'])
             # Adiciona informação nos anexos se o chat foi incluido ou não
             add_chat_included(pagination['items'])
             context = {'pagination': pagination}
             dest_file = os.path.join(self.report_bundle.report_folder,
                                      'html_files',
                                      f"general-audios_page_{page}.html")
             self.renderizer.render_template('general-audios.html',
                                             dest_file, context)
     finally:
         self.engine.dispose()
 def push_buffer(self):
     '''Push the content of the buffer into callback URL'''
     if not self.push_url:
         return
     
     # FIXME: Don't expect any response
     helpers.get_page(self.push_url, method='POST',
                      headers={"content-type": "application/stratum",
                               "x-session-id": self.session_id},
                      payload=self.fetch_buffer())
Exemplo n.º 3
0
    def push_buffer(self):
        '''Push the content of the buffer into callback URL'''
        if not self.push_url:
            return

        # FIXME: Don't expect any response
        helpers.get_page(self.push_url,
                         method='POST',
                         headers={
                             "content-type": "application/stratum",
                             "x-session-id": self.session_id
                         },
                         payload=self.fetch_buffer())
Exemplo n.º 4
0
def page_edit(pageid):
    """ Edit an existing page """

    if request.method == "POST":

        # Check if url field is not empty
        if not request.form.get("url"):
            flash("Must provide an URL.", "danger")
            return redirect("/profile/" + str(session["user_id"]) + "/edit")

        # Get form data
        url = request.form.get("url")
        platform_id = request.form.get("platform")
        if platform_id == None:
            platform_id = 0

        # Checks permission for editing
        page = get_page(conn, pageid)

        if session["user_id"] != page["user_id"]:
            flash("You don't have permission to do that.", "danger")
            return redirect("/profile/" + str(session["user_id"]))

        # Update database with form data
        update_page(conn, pageid, session["user_id"], url, platform_id)

        # Redirect user to profile edit page
        flash("Page updated!", "success")
        return redirect("/profile/" + str(session["user_id"]) + "/edit")

    else:
        return redirect("/profile/" + str(session["user_id"]) + "/edit")
Exemplo n.º 5
0
def get_reviews_info(listing_id, number_of_reviews):
    url = "https://www.airbnb.com/api/v2/homes_pdp_reviews"
    params = {
        "key": os.getenv("AIRBNB_KEY"),
        "listing_id": listing_id,
        "limit": number_of_reviews + 2
    }

    response = get_page(url, params)

    none_conditions = {response is None, response.status_code != 200}

    if True in none_conditions:
        return None

    reviews = response.json()["reviews"]

    oldest = None
    newest = None
    for review in reviews:
        created_at = parse(review["created_at"])
        if oldest:
            oldest = min(created_at, oldest)
        else:
            oldest = created_at
        if newest:
            newest = max(created_at, newest)
        else:
            newest = created_at
    return newest, oldest
Exemplo n.º 6
0
 def GET(self):
     post = PostController(users)
     params = web.input()
     g_page = params.get('page', 0)
     page = get_page(g_page)
     web.header('Content-Type', 'application/json')
     articles = post.get_posts(skip_from=page, 
                                 limit_to=POSTS_PER_PAGE)
     return json.dumps(tuple(articles), default=json_util.default)
Exemplo n.º 7
0
def get_calendar_info(listing_id):
    url = "https://www.airbnb.com/api/v2/homes_pdp_availability_calendar"
    check_in = None
    check_out = None
    min_nights = None
    current_year_full = datetime.datetime.now().strftime("%Y")
    current_month = datetime.datetime.now().strftime("%m")
    params = {
        "key": os.getenv("AIRBNB_KEY"),
        "listing_id": listing_id,
        "year": current_year_full,
        "month": current_month,
        "count": 12
    }

    response = get_page(url, params)

    none_conditions = {response is None, response.status_code != 200}

    if True in none_conditions:
        return None

    results = response.json()
    data = {}

    for month in results["calendar_months"]:
        for day in month["days"]:
            price = None
            bookable = False
            available_for_checkin = False
            if "local_price_formatted" in day["price"]:
                price = day["price"]["local_price_formatted"]

            data[day["date"]] = {
                "available": day["available"],
                "max_nights": day["max_nights"],
                "min_nights": day["min_nights"],
                "price": price
            }

            if 'bookable' in day:
                bookable = day['bookable']
                data[day["date"]]['bookable'] = day['bookable']
            if 'available_for_checkin' in day:
                available_for_checkin = day['available_for_checkin']
                data[day['date']]['available_for_checkin'] = day[
                    'available_for_checkin']
            if bookable and available_for_checkin:
                check_in = day["date"]
                check_in_date = datetime.datetime.strptime(
                    day["date"], "%Y-%m-%d")
                min_nights = day['min_nights']
                delta = datetime.timedelta(days=min_nights)
                check_out = (check_in_date + delta).strftime("%Y-%m-%d")

    return json.dumps(data), check_in, check_out, min_nights
Exemplo n.º 8
0
    def process_response(self, request, response):
        if response.status_code == 404:
            try:
                response = helpers.get_page(request)
            except ObjectDoesNotExist:
                pass
            except:
                pass

        return response
Exemplo n.º 9
0
 def GET(self):
     post = PostController(users)
     params = web.input()
     pagination = {}
     g_page = params.get('page', 0)
     page = get_page(g_page)
     if page > 0:
         pagination['left'] = page - POSTS_PER_PAGE
     if page < post.get_posts_count() - POSTS_PER_PAGE:
         pagination['right'] = page + POSTS_PER_PAGE    
     return render_template('index.html', 
                             posts_data=post.get_posts(skip_from=page, 
                                                         limit_to=POSTS_PER_PAGE), 
                             page=page, pagination=pagination)
Exemplo n.º 10
0
def page_delete(pageid):
    """ Enables a user to delete a page """

    if request.method == "POST":

        # Check instrument ownership
        page = get_page(conn, pageid)

        if session["user_id"] != page["user_id"]:
            flash("You don't have permission to do that.", "danger")
            return redirect("/profile/" + str(session["user_id"]) + "/edit")

        # Delete post from database
        delete_page(conn, session["user_id"], pageid)

        # Redirect to feed
        flash("Page deleted!", "success")
        return redirect("/profile/" + str(session["user_id"]) + "/edit")

    else:

        # Get occupation
        page = get_page(conn, pageid)

        # Check post ownership
        if session["user_id"] != page["user_id"]:
            flash("You don't have permission to do that.", "danger")
            return redirect("/profile/" + str(session["user_id"]) + "/edit")

        content = {}
        content["id"] = page["id"]
        content["type"] = "Page"
        content["delete_url"] = "/pages/" + pageid + "/delete"
        content["cancel_url"] = "/profile/" + str(session["user_id"]) + "/edit"

        return render_template("delete.html", content=content)
Exemplo n.º 11
0
def process_product_page(product_url):
	"""Scrapes and returns all the data in the given product url"""
	if helpers.get_debug_config():
		print "[DEBUG] Extracting manufacturer, price, and sold by from \
		product page: " + product_url
	product_page_lxml = helpers.get_page(product_url)
	if product_page_lxml == False:
		print "Scrape of product page failed!!! URL: " + product_url
		helpers.log("Scrape of product page failed!!! URL: " + product_url)
		return 'Error', 'Error', 'Error'
	try:
		manufacturer = extract_manufacturer(product_page_lxml)
		price = extract_price(product_page_lxml)
		sold_by = extract_sold_by(product_page_lxml)
	except Exception, e:
		print e
		print traceback.print_exc()
		helpers.log('Error with url: ' + product_url)
		raise
Exemplo n.º 12
0
def go_through_pages_in_range(query, price_min, price_max):
    listing_ids = []

    has_next_page = True

    attempts = 0
    page = 0
    items_per_grid = 50
    max_attempts = 3
    estimated_range = 0
    place_id = None
    federated_search_session_id = None
    s_tag = None
    search_session_id = None
    offset_factor = items_per_grid // 5

    url = 'https://www.airbnb.com/api/v2/explore_tabs'

    while has_next_page:
        params = {
            '_format': 'for_explore_search_native',
            'auto_ib': 'false',
            'currency': 'USD',
            'current_tab_id': 'home_tab',
            'experiences_per_grid': '20',
            'fetch_filters': 'true',
            'guidebooks_per_grid': '20',
            'has_zero_guest_treatment': 'true',
            'hide_dates_and_guests_filters': 'false',
            'is_guided_search': 'true',
            'is_new_cards_experiment': 'true',
            'is_standard_search': 'true',
            'locale': 'en',
            'metadata_only': 'false',
            'query_understanding_enabled': 'true',
            'satori_version': '1.2.5',
            'section_offset': '4',
            'show_groupings': 'true',
            'supports_for_you_v3': 'true',
            'timezone_offset': '-360',
            'version': '1.7.0',
            'items_per_grid': items_per_grid,
            'key': os.getenv("AIRBNB_KEY"),
            'query': f'{query}',
            'search_type': 'pagination',
            'selected_tab_id': 'home_tab',
            'price_min': price_min,
            'items_offset': offset_factor * page
        }

        if price_max:
            params['price_max'] = price_max

        if place_id and federated_search_session_id and s_tag and \
                search_session_id:
            params['place_id'] = place_id
            params['s_tag'] = s_tag
            params['federated_search_session_id'] = federated_search_session_id
            params['last_search_session_id'] = search_session_id

        response = get_page(url, params)
        results = response.json()['explore_tabs'][0]
        metadata = response.json()['metadata']
        home_tab_meta_data = results['home_tab_metadata']

        place_id = metadata['geography']['place_id']
        federated_search_session_id = metadata['federated_search_session_id']
        s_tag = home_tab_meta_data['search']['mobile_session_id']

        estimated_range = home_tab_meta_data['listings_count']
        has_next_page = results['pagination_metadata']['has_next_page']

        if has_next_page:
            search_session_id = results['pagination_metadata'][
                'search_session_id']

        sections = results['sections']
        page_listing_ids = [
            listing['listing']['id'] for section in sections
            if 'listings' in section for listing in section['listings']
        ]

        break_conditions = {attempts >= max_attempts, estimated_range > 306}
        attempts_conditions = {response is None}

        if True in break_conditions:
            print(break_conditions)
            break
        if True in attempts_conditions:
            print("\n")
            print("Attempting Again...")
            print(f"Attempt number {attempts + 1}")
            attempts += 1
            place_id = None
            federated_search_session_id = None
            s_tag = None
            search_session_id = None
            page = 0
            listing_ids = []
            has_next_page = True
            continue

        page += 1
        listing_ids += page_listing_ids
        if page == 1:
            print("Estimated Listings in Range: ", estimated_range)
            print("\n")

        sys.stdout.write("\r")
        sys.stdout.write(f"Page: {page}")
        sys.stdout.flush()

    sys.stdout.write(
        f"\rDone Getting {len(set(listing_ids))} Listing Ids!            \n")

    return list(set(listing_ids)), estimated_range
Exemplo n.º 13
0
def get_location_by_zipcode(zipcode):
    data = get_page('https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s'% (zipcode,key))
    return data
Exemplo n.º 14
0
    def run(self, chat_id):
        self.engine, self.dbsession = db_connect()

        chat = self.dbsession.query(Chat).get(chat_id)
        print(f"Renderizando chat {chat.friendly_identifier} ({chat.source})")
        query = self.dbsession.query(Message).filter(
            Message.analise_attachment_types.like("%image%"),
            Message.chat == chat)
        total_images = self.report_bundle.filter(Message, query).count()
        query = self.dbsession.query(Message).filter(
            Message.analise_attachment_types.like("%audio%"),
            Message.chat == chat)
        total_audios = self.report_bundle.filter(Message, query).count()
        query = self.dbsession.query(Message).filter(
            Message.analise_attachment_types.like("%video%"),
            Message.chat == chat)
        total_videos = self.report_bundle.filter(Message, query).count()
        query = self.dbsession.query(Message).filter_by(
            chat_id=chat.id).order_by(Message.timestamp.asc())

        query = self.report_bundle.filter(Message, query)
        n_pages = get_page(
            query,
            only_count=True,
            per_page=config_manager.report_config['per_page']['chat'])
        for i in range(n_pages):
            page = i + 1
            pagination = get_page(
                query,
                page=page,
                per_page=config_manager.report_config['per_page']['chat'])
            context = {
                "pagination": pagination,
                'chat': chat,
                'total_images': total_images,
                'total_videos': total_videos,
                'total_audios': total_audios
            }
            dest_file = os.path.join(self.report_bundle.report_folder,
                                     'html_files',
                                     f"chat{chat.id}_page_{page}.html")
            self.renderizer.render_template('chat.html', dest_file, context)
            for message in pagination['items']:
                message.page_renderized = page
                self.dbsession.add(message)
        self.dbsession.commit()

        # Audio pages
        query = self.dbsession.query(Message).filter(
            Message.analise_attachment_types.like("%audio%"),
            Message.chat == chat)
        query = self.report_bundle.filter(Message, query)
        n_pages = get_page(
            query,
            only_count=True,
            per_page=config_manager.report_config['per_page']['audio'])
        for i in range(n_pages):
            page = i + 1
            pagination = get_page(
                query,
                page=page,
                per_page=config_manager.report_config['per_page']['audio'])
            context = {'pagination': pagination, 'chat': chat}
            dest_file = os.path.join(self.report_bundle.report_folder,
                                     'html_files',
                                     f"audios{chat.id}_page_{page}.html")
            self.renderizer.render_template('audios.html', dest_file, context)

        # Image pages
        query = self.dbsession.query(Message).filter(
            Message.analise_attachment_types.like("%image%"),
            Message.chat == chat)
        query = self.report_bundle.filter(Message, query)
        n_pages = get_page(
            query,
            only_count=True,
            per_page=config_manager.report_config['per_page']['image'])
        for i in range(n_pages):
            page = i + 1
            pagination = get_page(
                query,
                page=page,
                per_page=config_manager.report_config['per_page']['image'])
            context = {'pagination': pagination, 'chat': chat}
            dest_file = os.path.join(self.report_bundle.report_folder,
                                     'html_files',
                                     f"images{chat.id}_page_{page}.html")
            self.renderizer.render_template('images.html', dest_file, context)

        # Video pages
        query = self.dbsession.query(Message).filter(
            Message.analise_attachment_types.like("%video%"),
            Message.chat == chat)
        query = self.report_bundle.filter(Message, query)
        n_pages = get_page(
            query,
            only_count=True,
            per_page=config_manager.report_config['per_page']['video'])
        for i in range(n_pages):
            page = i + 1
            pagination = get_page(
                query,
                page=page,
                per_page=config_manager.report_config['per_page']['video'])
            context = {'pagination': pagination, 'chat': chat}
            dest_file = os.path.join(self.report_bundle.report_folder,
                                     'html_files',
                                     f"videos{chat.id}_page_{page}.html")
            self.renderizer.render_template('videos.html', dest_file, context)

        # Participants
        context = {'participants': chat.participants, 'chat': chat}
        dest_file = os.path.join(self.report_bundle.report_folder,
                                 'html_files', f"participants{chat.id}.html")
        self.renderizer.render_template('participants.html', dest_file,
                                        context)

        sources = get_chat_sources(self.report_bundle.filter(Chat))
        for source in sources:
            print(
                f"Renderizando todos os áudios de bate-papo do aplicativo {source}"
            )
            # All Audios
            query = self.dbsession.query(Message).join(Chat).filter(
                Message.analise_attachment_types.like("%audio%"),
                Chat.source == source)
            query = self.report_bundle.filter(Message, query)
            n_pages = get_page(
                query,
                only_count=True,
                per_page=config_manager.report_config['per_page']['audio'])
            for i in range(n_pages):
                page = i + 1
                pagination = get_page(
                    query,
                    page=page,
                    per_page=config_manager.report_config['per_page']['audio'])
                context = {'pagination': pagination, 'source': source}
                dest_file = os.path.join(
                    self.report_bundle.report_folder, 'html_files',
                    f"all-audios{source}_page_{page}.html")
                self.renderizer.render_template('all-audios.html', dest_file,
                                                context)

            # All Images
            print(
                f"Renderizando todas as imagens de bate-papo do aplicativo {source}"
            )
            query = self.dbsession.query(Message).join(Chat).filter(
                Message.analise_attachment_types.like("%image%"),
                Chat.source == source)
            query = self.report_bundle.filter(Message, query)
            n_pages = get_page(
                query,
                only_count=True,
                per_page=config_manager.report_config['per_page']['image'])
            for i in range(n_pages):
                page = i + 1
                pagination = get_page(
                    query,
                    page=page,
                    per_page=config_manager.report_config['per_page']['image'])
                context = {'pagination': pagination, 'source': source}
                dest_file = os.path.join(
                    self.report_bundle.report_folder, 'html_files',
                    f"all-images{source}_page_{page}.html")
                self.renderizer.render_template('all-images.html', dest_file,
                                                context)

            # All Videos
            print(
                f"Renderizando todos os videos de bate-papo do aplicativo {source}"
            )
            query = self.dbsession.query(Message).join(Chat).filter(
                Message.analise_attachment_types.like("%video%"),
                Chat.source == source)
            query = self.report_bundle.filter(Message, query)
            n_pages = get_page(
                query,
                only_count=True,
                per_page=config_manager.report_config['per_page']['video'])
            for i in range(n_pages):
                page = i + 1
                pagination = get_page(
                    query,
                    page=page,
                    per_page=config_manager.report_config['per_page']['video'])
                context = {'pagination': pagination, 'source': source}
                dest_file = os.path.join(
                    self.report_bundle.report_folder, 'html_files',
                    f"all-videos{source}_page_{page}.html")
                self.renderizer.render_template('all-videos.html', dest_file,
                                                context)

            context = {}
            query = self.report_bundle.filter(
                Chat,
                self.dbsession.query(Chat).filter(Chat.source == source))
            context['chats'] = query.all()
            query = self.dbsession.query(Message).join(Chat).filter(
                Message.analise_attachment_types.like("%audio%"),
                Chat.source == source)
            query = self.report_bundle.filter(Message, query)
            context['total_audios'] = query.count()
            query = self.dbsession.query(Message).join(Chat).filter(
                Message.analise_attachment_types.like("%video%"),
                Chat.source == source)
            query = self.report_bundle.filter(Message, query)
            context['total_videos'] = query.count()
            query = self.dbsession.query(Message).join(Chat).filter(
                Message.analise_attachment_types.like("%image%"),
                Chat.source == source)
            query = self.report_bundle.filter(Message, query)
            context['total_images'] = query.count()
            context['source'] = source
            dest_file = os.path.join(self.report_bundle.report_folder,
                                     'html_files', f"chats_{source}.html")
            self.renderizer.render_template('chats.html', dest_file, context)
        self.engine.dispose()
Exemplo n.º 15
0
def process_category(rank_page_url, start_rank = 1, max_rank = 9600):
	"""Scrapes all the data in the given category url"""
	try:
	
		#Set basic variables and hit next to reach start_rank page, if required
		rank_page_lxml = helpers.get_page(rank_page_url)
		category = extract_category(rank_page_lxml)
		rank_per_page = 24
		if start_rank >= max_rank:
			return False, category
		elif start_rank > rank_per_page:
			next_times = start_rank / rank_per_page
			print 'Hitting next ' + str(next_times) + ' times...'
			for times in range(next_times):
				previous_rank_page_lxml = rank_page_lxml
				rank_page_lxml = helpers.hit_next(rank_page_lxml)
				if rank_page_lxml == False:
					retries = 0
					while True:
						print "Error with reaching start page on \
						rank_page_lxml: " + previous_rank_page_lxml.base_url
						helpers.log("Error with reaching start page on rank_page_lxml:\
						 " + previous_rank_page_lxml.base_url)
						if retries > 50:
							return False, category
						retries += 1
						print "Retrying..."
						rank_page_lxml = \
						helpers.get_page(previous_rank_page_lxml.base_url)
						rank_page_lxml = helpers.hit_next(rank_page_lxml)
						if rank_page_lxml != False:
							retries = 0
							break
	
		#Start extracting
		retries = 0
		while True:
			try:
				ranks_names_urls = extract_ranks_names_urls(rank_page_lxml)
			except Exception, e:
				print "Error in extracting ranks, names, and urls from rank \
				page: " + rank_page_lxml.base_url
				print e
				helpers.log(e)
				helpers.log(traceback.print_exc())
				raise
			
			if ranks_names_urls == []:
				print 'retries: ' + str(retries)
				if retries > 50:
					helpers.log("Error in extracting ranks names and urls from: " + \
						rank_page_lxml.base_url)
					raise Exception("Error in extracting ranks names and urls \
						from: " + rank_page_lxml.base_url)
				retries += 1
				print "Rank name url list is empty! Retrying..."
				rank_page_lxml = helpers.get_page(rank_page_lxml.base_url)
				continue
			else:
				retries = 0
			
			for rank_name_url in ranks_names_urls:
				rank = rank_name_url[0]
				name = rank_name_url[1]
				url = rank_name_url[2]
				asin = helpers.extract_asin(url)
				manufacturer, price, sold_by = productpage.process_product_page(url)
				todays_date = str(datetime.date.today())
				#[category_url, rank, asin, product_name, manufacturer_name,
				# price, selling_status, product_url, scrape_date]
				dbdo.save_product([rank_page_url, rank, asin, name, manufacturer, \
					price, sold_by, url, todays_date])
	
			try:
				last_rank = ranks_names_urls[-1][0]
				if last_rank >= max_rank:
					break
			except Exception, e:
				print 'Error in finding last rank'
				print ranks_names_urls
				helpers.log(rank_page_lxml.text_content())
				raise

			rank_page_lxml = helpers.hit_next(rank_page_lxml)
			if rank_page_lxml == False or None:
				return True, category
Exemplo n.º 16
0
def get_photo_url():
    url = 'https://api.nasa.gov/planetary/apod?concept_tags=True&api_key=%s' % key
    data = get_page(url)
    return data['url']
Exemplo n.º 17
0
def get_listing_info(listing_id):
    url = "https://www.airbnb.com/api/v2/pdp_listing_details/" + str(
        listing_id)

    params = {"_format": "for_rooms_show", "key": os.getenv("AIRBNB_KEY")}

    response = get_page(url, params)

    # TODO check response is not none in getting info in loop on other page
    none_conditions = {response is None, response.status_code != 200}

    if True in none_conditions:
        return None

    results = response.json()["pdp_listing_detail"]

    additional_house_rules = results["additional_house_rules"]
    bathroom_label = results["bathroom_label"]
    bed_label = results["bed_label"]
    bedroom_label = results["bedroom_label"]
    guest_label = results["guest_label"]
    name = results["name"]
    person_capacity = results["person_capacity"]
    photos = results["photos"]
    photo_count = len(photos)
    default_photo = photos[0]["large"]
    number_of_professional_photos = sum(photo["is_professional"]
                                        for photo in photos)
    host_name = results["primary_host"]["host_name"]
    languages = json.dumps(results["primary_host"]["languages"])
    room_and_property_type = results["room_and_property_type"]
    room_type_category = results["room_type_category"]
    is_plus = bool(results["tier_id"])
    min_nights = results["min_nights"]
    location_title = results["location_title"]
    localized_check_in_time_window = results["localized_check_in_time_window"]
    localized_check_out_time = results["localized_check_out_time"]
    lat = results["lat"]
    lng = results["lng"]
    neighborhood_id = results["neighborhood_id"]
    license_number = results["license"]
    requires_license = results["requires_license"]
    support_cleaner_living_wage = results["support_cleaner_living_wage"]
    host_other_property_review_count = results["review_details_interface"][
        "host_other_property_review_count"]
    listing_review_count = results["review_details_interface"]["review_count"]
    listing_review_score = results["review_details_interface"]["review_score"]
    visible_review_count = results["visible_review_count"]
    host_interaction = results["host_interaction"]
    host_quote = results["host_quote"]
    is_select_market = results["is_select_market"]
    nearby_airport_distance_descriptions = json.dumps(
        results["nearby_airport_distance_descriptions"])
    is_hotel = results["is_hotel"]
    is_representative_inventory = results["is_representative_inventory"]
    has_essentials_amenity = results["has_essentials_amenity"]
    localized_overall_rating = results["reviews_module"][
        "localized_overall_rating"]
    discount_phrase = results["availability_module"]["discount_phrase"]
    host_badges = results["primary_host"]["badges"]
    host_intro_tags = results["primary_host"]["host_intro_tags"]

    amenities = json.dumps(results["listing_amenities"])
    highlights = json.dumps(results["highlights"])
    expectations = json.dumps(results["listing_expectations"])
    additional_hosts = json.dumps(results["additional_hosts"])
    review_summaries = json.dumps(
        results["review_details_interface"]["review_summary"])
    appreciation_tags = json.dumps(
        results["reviews_module"]["appreciation_tags"])
    rooms = json.dumps(results["listing_rooms"])
    primary_host = json.dumps(results["primary_host"])
    sectioned_description = json.dumps(results["sectioned_description"])
    guest_controls = json.dumps(results['guest_controls'])

    listing = {
        "additional_house_rules": additional_house_rules,
        "bathroom_label": bathroom_label,
        "bed_label": bed_label,
        "bedroom_label": bedroom_label,
        "guest_label": guest_label,
        "id": results["id"],
        "name": name,
        "person_capacity": person_capacity,
        "photo_count": photo_count,
        "default_photo": default_photo,
        "number_of_professional_photos": number_of_professional_photos,
        "host_name": host_name,
        "languages": languages,
        "room_and_property_type": room_and_property_type,
        "room_type_category": room_type_category,
        "is_plus": is_plus,
        "min_nights": min_nights,
        "location_title": location_title,
        "localized_check_in_time_window": localized_check_in_time_window,
        "localized_check_out_time": localized_check_out_time,
        "lat": lat,
        "lng": lng,
        "neighborhood_id": neighborhood_id,
        "license": license_number,
        "requires_license": requires_license,
        "support_cleaner_living_wage": support_cleaner_living_wage,
        "host_other_property_review_count": host_other_property_review_count,
        "host_badges": host_badges,
        "host_intro_tags": host_intro_tags,
        "listing_review_count": listing_review_count,
        "listing_review_score": listing_review_score,
        "visible_review_count": visible_review_count,
        "host_interaction": host_interaction,
        "host_quote": host_quote,
        "is_select_market": is_select_market,
        "nearby_airport_descriptions": nearby_airport_distance_descriptions,
        "is_hotel": is_hotel,
        "is_representative_inventory": is_representative_inventory,
        "has_essentials_amenity": has_essentials_amenity,
        "localized_overall_rating": localized_overall_rating,
        "discount_phrase": discount_phrase,
        "amenities": amenities,
        "highlights": highlights,
        "expectations": expectations,
        "additional_hosts": additional_hosts,
        "review_summaries": review_summaries,
        "appreciation_tags": appreciation_tags,
        "rooms": rooms,
        'primary_host': primary_host,
        "sectioned_description": sectioned_description,
        "guest_controls": guest_controls
    }

    return listing
Exemplo n.º 18
0
def get_booking_info(listing_id, check_in, check_out, max_guests, min_nights):
    cleaning_fees = set()
    cancelation_policies = []
    non_refundable_discount_amount = 0
    extra_guest_fee = 0
    extra_guest_fee_at = 0

    params = {
        "_format": "for_web_with_date",
        "key": os.getenv("AIRBNB_KEY"),
        "listing_id": listing_id,
        "check_in": check_in,
        "check_out": check_out,
        "number_of_children": 0,
        "number_of_infants": 0,
    }

    url = "https://www.airbnb.com/api/v2/pdp_listing_booking_details"
    for number_of_adults in range(1, max_guests + 1):

        params["number_of_adults"] = number_of_adults

        response = get_page(url, params)

        break_conditions = {response is None, response.status_code != 200}

        if True in break_conditions:
            break

        results = response.json()["pdp_listing_booking_details"][0]

        for price_item in results["price"]["price_items"]:
            if price_item["type"] == "CLEANING_FEE":
                cleaning_fees.add(price_item["total"]["amount"])

        if number_of_adults == 1:

            policy_keys = [
                "localized_cancellation_policy_name",
                "cancellation_policy_label", "cancellation_policy_price_type",
                "cancellation_policy_price_factor", "cancellation_policy_id",
                "book_it_module_tooltip", "subtitle"
            ]
            policy_milestone_keys = ["titles", "subtitles", "type"]
            for policy in results["cancellation_policies"]:
                features = {"milestones": {}}
                for milestone in policy["milestones"]:
                    for key in policy_milestone_keys:
                        features["milestones"][key] = milestone[key]
                for key in policy_keys:
                    features[key] = policy[key]
                    if (key == "cancellation_policy_price_factor") and \
                            policy[
                                key] \
                            != 0:
                        non_refundable_discount_amount = policy[key]
                cancelation_policies.append(features)

        if results["extra_guest_fee"]["amount"] != 0:
            extra_guest_fee = results["extra_guest_fee"]["amount"] / min_nights
            extra_guest_fee_at = number_of_adults - 1
            break

    data = [
        list(cleaning_fees), cancelation_policies,
        non_refundable_discount_amount, extra_guest_fee, extra_guest_fee_at,
        check_in, check_out
    ]

    return data
Exemplo n.º 19
0
def get_location_by_long_lat(longitude,latitude):
    data = get_page('https://maps.googleapis.com/maps/api/geocode/json?address=%s+%s&key=%s'% (latitude,longitude,key))
    return data
Exemplo n.º 20
0
def get_location():
    data = get_page('http://api.open-notify.org/iss-now.json')
    location = data['iss_position']
    longitude = get_longitude(location)
    latitude = get_latitude(location)
    return {'lat': latitude, 'long': longitude}