From 0e4c1325cce4d440ffd1a062ecd8d8597c12a6d7 Mon Sep 17 00:00:00 2001 From: KaroD123 Date: Mon, 11 Oct 2021 18:00:53 +0200 Subject: [PATCH] save --- .ipynb_checkpoints/Solution-checkpoint.ipynb | 276 +++++++++++++++++++ Solution.ipynb | 276 +++++++++++++++++++ 2 files changed, 552 insertions(+) create mode 100644 .ipynb_checkpoints/Solution-checkpoint.ipynb create mode 100644 Solution.ipynb diff --git a/.ipynb_checkpoints/Solution-checkpoint.ipynb b/.ipynb_checkpoints/Solution-checkpoint.ipynb new file mode 100644 index 0000000..ae39693 --- /dev/null +++ b/.ipynb_checkpoints/Solution-checkpoint.ipynb @@ -0,0 +1,276 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"Places\" : [ {\n", + " \"PlaceId\" : \"STOC-sky\",\n", + " \"PlaceName\" : \"Stockholm\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " }, {\n", + " \"PlaceId\" : \"ARN-sky\",\n", + " \"PlaceName\" : \"Stockholm Arlanda\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " }, {\n", + " \"PlaceId\" : \"NYO-sky\",\n", + " \"PlaceName\" : \"Stockholm Skavsta\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " }, {\n", + " \"PlaceId\" : \"BMA-sky\",\n", + " \"PlaceName\" : \"Stockholm Bromma\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " }, {\n", + " \"PlaceId\" : \"VST-sky\",\n", + " \"PlaceName\" : \"Stockholm Vasteras\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " } ]\n", + "}\n" + ] + } + ], + "source": [ + "import requests\n", + "\n", + "url = \"https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/autosuggest/v1.0/UK/GBP/en-GB/\"\n", + "\n", + "querystring = {\"query\":\"Stockholm\"}\n", + "\n", + "headers = {\n", + " 'x-rapidapi-host': \"skyscanner-skyscanner-flight-search-v1.p.rapidapi.com\",\n", + " 'x-rapidapi-key': \"9c8d07c07emsh4f918e8fccf6096p166317jsna5619b1b6eec\"\n", + " }\n", + "\n", + "response = requests.request(\"GET\", url, headers=headers, params=querystring)\n", + "\n", + "print(response.text)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"Quotes\" : [ {\n", + " \"QuoteId\" : 1,\n", + " \"MinPrice\" : 68,\n", + " \"Direct\" : true,\n", + " \"OutboundLeg\" : {\n", + " \"CarrierIds\" : [ 851 ],\n", + " \"OriginId\" : 81727,\n", + " \"DestinationId\" : 60987,\n", + " \"DepartureDate\" : \"2021-11-11T00:00:00\"\n", + " },\n", + " \"QuoteDateTime\" : \"2021-10-11T10:15:00\"\n", + " } ],\n", + " \"Carriers\" : [ {\n", + " \"CarrierId\" : 851,\n", + " \"Name\" : \"Alaska Airlines\"\n", + " } ],\n", + " \"Places\" : [ {\n", + " \"Name\" : \"New York John F. Kennedy\",\n", + " \"Type\" : \"Station\",\n", + " \"PlaceId\" : 60987,\n", + " \"IataCode\" : \"JFK\",\n", + " \"SkyscannerCode\" : \"JFK\",\n", + " \"CityName\" : \"New York\",\n", + " \"CityId\" : \"NYCA\",\n", + " \"CountryName\" : \"United States\"\n", + " }, {\n", + " \"Name\" : \"San Francisco International\",\n", + " \"Type\" : \"Station\",\n", + " \"PlaceId\" : 81727,\n", + " \"IataCode\" : \"SFO\",\n", + " \"SkyscannerCode\" : \"SFO\",\n", + " \"CityName\" : \"San Francisco\",\n", + " \"CityId\" : \"SFOA\",\n", + " \"CountryName\" : \"United States\"\n", + " } ],\n", + " \"Currencies\" : [ {\n", + " \"Code\" : \"USD\",\n", + " \"Symbol\" : \"$\",\n", + " \"ThousandsSeparator\" : \",\",\n", + " \"DecimalSeparator\" : \".\",\n", + " \"SymbolOnLeft\" : true,\n", + " \"SpaceBetweenAmountAndSymbol\" : false,\n", + " \"RoundingCoefficient\" : 0,\n", + " \"DecimalDigits\" : 2\n", + " } ]\n", + "}\n" + ] + } + ], + "source": [ + "\n", + "url = \"https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/browsequotes/v1.0/US/USD/en-US/SFO-sky/JFK-sky/2021-11-11\"\n", + "\n", + "querystring = {\"inboundpartialdate\":\"2021-11-11\"}\n", + "\n", + "headers = {\n", + " 'x-rapidapi-host': \"skyscanner-skyscanner-flight-search-v1.p.rapidapi.com\",\n", + " 'x-rapidapi-key': \"9c8d07c07emsh4f918e8fccf6096p166317jsna5619b1b6eec\"\n", + " }\n", + "\n", + "response = requests.request(\"GET\", url, headers=headers, params=querystring)\n", + "\n", + "print(response.text)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.DataFrame(response.json().items())" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
01new_col
0Quotes[{'QuoteId': 1, 'MinPrice': 68, 'Direct': True...{'QuoteId': 1, 'MinPrice': 68, 'Direct': True,...
1Carriers[{'CarrierId': 851, 'Name': 'Alaska Airlines'}]{'CarrierId': 851, 'Name': 'Alaska Airlines'}
2Places[{'Name': 'New York John F. Kennedy', 'Type': ...{'Name': 'New York John F. Kennedy', 'Type': '...
3Currencies[{'Code': 'USD', 'Symbol': '$', 'ThousandsSepa...{'Code': 'USD', 'Symbol': '$', 'ThousandsSepar...
\n", + "
" + ], + "text/plain": [ + " 0 1 \\\n", + "0 Quotes [{'QuoteId': 1, 'MinPrice': 68, 'Direct': True... \n", + "1 Carriers [{'CarrierId': 851, 'Name': 'Alaska Airlines'}] \n", + "2 Places [{'Name': 'New York John F. Kennedy', 'Type': ... \n", + "3 Currencies [{'Code': 'USD', 'Symbol': '$', 'ThousandsSepa... \n", + "\n", + " new_col \n", + "0 {'QuoteId': 1, 'MinPrice': 68, 'Direct': True,... \n", + "1 {'CarrierId': 851, 'Name': 'Alaska Airlines'} \n", + "2 {'Name': 'New York John F. Kennedy', 'Type': '... \n", + "3 {'Code': 'USD', 'Symbol': '$', 'ThousandsSepar... " + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df['new_col'] = df[1].apply(lambda x: x[0])\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Solution.ipynb b/Solution.ipynb new file mode 100644 index 0000000..ae39693 --- /dev/null +++ b/Solution.ipynb @@ -0,0 +1,276 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"Places\" : [ {\n", + " \"PlaceId\" : \"STOC-sky\",\n", + " \"PlaceName\" : \"Stockholm\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " }, {\n", + " \"PlaceId\" : \"ARN-sky\",\n", + " \"PlaceName\" : \"Stockholm Arlanda\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " }, {\n", + " \"PlaceId\" : \"NYO-sky\",\n", + " \"PlaceName\" : \"Stockholm Skavsta\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " }, {\n", + " \"PlaceId\" : \"BMA-sky\",\n", + " \"PlaceName\" : \"Stockholm Bromma\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " }, {\n", + " \"PlaceId\" : \"VST-sky\",\n", + " \"PlaceName\" : \"Stockholm Vasteras\",\n", + " \"CountryId\" : \"SE-sky\",\n", + " \"RegionId\" : \"\",\n", + " \"CityId\" : \"STOC-sky\",\n", + " \"CountryName\" : \"Sweden\"\n", + " } ]\n", + "}\n" + ] + } + ], + "source": [ + "import requests\n", + "\n", + "url = \"https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/autosuggest/v1.0/UK/GBP/en-GB/\"\n", + "\n", + "querystring = {\"query\":\"Stockholm\"}\n", + "\n", + "headers = {\n", + " 'x-rapidapi-host': \"skyscanner-skyscanner-flight-search-v1.p.rapidapi.com\",\n", + " 'x-rapidapi-key': \"9c8d07c07emsh4f918e8fccf6096p166317jsna5619b1b6eec\"\n", + " }\n", + "\n", + "response = requests.request(\"GET\", url, headers=headers, params=querystring)\n", + "\n", + "print(response.text)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"Quotes\" : [ {\n", + " \"QuoteId\" : 1,\n", + " \"MinPrice\" : 68,\n", + " \"Direct\" : true,\n", + " \"OutboundLeg\" : {\n", + " \"CarrierIds\" : [ 851 ],\n", + " \"OriginId\" : 81727,\n", + " \"DestinationId\" : 60987,\n", + " \"DepartureDate\" : \"2021-11-11T00:00:00\"\n", + " },\n", + " \"QuoteDateTime\" : \"2021-10-11T10:15:00\"\n", + " } ],\n", + " \"Carriers\" : [ {\n", + " \"CarrierId\" : 851,\n", + " \"Name\" : \"Alaska Airlines\"\n", + " } ],\n", + " \"Places\" : [ {\n", + " \"Name\" : \"New York John F. Kennedy\",\n", + " \"Type\" : \"Station\",\n", + " \"PlaceId\" : 60987,\n", + " \"IataCode\" : \"JFK\",\n", + " \"SkyscannerCode\" : \"JFK\",\n", + " \"CityName\" : \"New York\",\n", + " \"CityId\" : \"NYCA\",\n", + " \"CountryName\" : \"United States\"\n", + " }, {\n", + " \"Name\" : \"San Francisco International\",\n", + " \"Type\" : \"Station\",\n", + " \"PlaceId\" : 81727,\n", + " \"IataCode\" : \"SFO\",\n", + " \"SkyscannerCode\" : \"SFO\",\n", + " \"CityName\" : \"San Francisco\",\n", + " \"CityId\" : \"SFOA\",\n", + " \"CountryName\" : \"United States\"\n", + " } ],\n", + " \"Currencies\" : [ {\n", + " \"Code\" : \"USD\",\n", + " \"Symbol\" : \"$\",\n", + " \"ThousandsSeparator\" : \",\",\n", + " \"DecimalSeparator\" : \".\",\n", + " \"SymbolOnLeft\" : true,\n", + " \"SpaceBetweenAmountAndSymbol\" : false,\n", + " \"RoundingCoefficient\" : 0,\n", + " \"DecimalDigits\" : 2\n", + " } ]\n", + "}\n" + ] + } + ], + "source": [ + "\n", + "url = \"https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/browsequotes/v1.0/US/USD/en-US/SFO-sky/JFK-sky/2021-11-11\"\n", + "\n", + "querystring = {\"inboundpartialdate\":\"2021-11-11\"}\n", + "\n", + "headers = {\n", + " 'x-rapidapi-host': \"skyscanner-skyscanner-flight-search-v1.p.rapidapi.com\",\n", + " 'x-rapidapi-key': \"9c8d07c07emsh4f918e8fccf6096p166317jsna5619b1b6eec\"\n", + " }\n", + "\n", + "response = requests.request(\"GET\", url, headers=headers, params=querystring)\n", + "\n", + "print(response.text)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.DataFrame(response.json().items())" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
01new_col
0Quotes[{'QuoteId': 1, 'MinPrice': 68, 'Direct': True...{'QuoteId': 1, 'MinPrice': 68, 'Direct': True,...
1Carriers[{'CarrierId': 851, 'Name': 'Alaska Airlines'}]{'CarrierId': 851, 'Name': 'Alaska Airlines'}
2Places[{'Name': 'New York John F. Kennedy', 'Type': ...{'Name': 'New York John F. Kennedy', 'Type': '...
3Currencies[{'Code': 'USD', 'Symbol': '$', 'ThousandsSepa...{'Code': 'USD', 'Symbol': '$', 'ThousandsSepar...
\n", + "
" + ], + "text/plain": [ + " 0 1 \\\n", + "0 Quotes [{'QuoteId': 1, 'MinPrice': 68, 'Direct': True... \n", + "1 Carriers [{'CarrierId': 851, 'Name': 'Alaska Airlines'}] \n", + "2 Places [{'Name': 'New York John F. Kennedy', 'Type': ... \n", + "3 Currencies [{'Code': 'USD', 'Symbol': '$', 'ThousandsSepa... \n", + "\n", + " new_col \n", + "0 {'QuoteId': 1, 'MinPrice': 68, 'Direct': True,... \n", + "1 {'CarrierId': 851, 'Name': 'Alaska Airlines'} \n", + "2 {'Name': 'New York John F. Kennedy', 'Type': '... \n", + "3 {'Code': 'USD', 'Symbol': '$', 'ThousandsSepar... " + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df['new_col'] = df[1].apply(lambda x: x[0])\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}