403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/api.hellogtx.com/apihellogtx/goflysmartapi/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/api.hellogtx.com/apihellogtx/goflysmartapi/views___30042024.py
from django.shortcuts import render
import requests
import datetime
import json
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.status import (
    HTTP_400_BAD_REQUEST,
    HTTP_404_NOT_FOUND,
    HTTP_200_OK,
    HTTP_500_INTERNAL_SERVER_ERROR
)
from goflysmartapi.models import TbAgencyApiKey, TbAgencyApiToken
from goflysmartapi.serializers import TbAgencyApiTokenSerializer


class Login(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            api_source = request.data.get("api_source", None)
            if api_source == 'go_fly_smart' or api_source == 'air_iq':
                if api_source == 'air_iq':
                    TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                        SecurityKey=Security_Key).first()
                    url = "https://omairiq.azurewebsites.net/login"
                    payload = json.dumps({
                        "Username": TbAgencyApiKeyArray.UserName,
                        "Password": TbAgencyApiKeyArray.SecretKey
                    })
                else:
                    TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                        SecurityKey=Security_Key).first()
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/api/login"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/api/login"
                    payload = json.dumps({
                        "email": TbAgencyApiKeyArray.UserName,
                        "password": TbAgencyApiKeyArray.SecretKey
                    })
                if TbAgencyApiKeyArray is not None:
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Content-Type': 'application/json'
                    }
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload)
                        x = response.text
                        json_data = json.loads(x)
                        if api_source == 'air_iq':
                            token = json_data.get("token", None)
                            expiration = json_data.get("expiration", None)
                        else:
                            token = json_data.get("access_token", None)
                            expiration = json_data.get("expires_in", None)
                        if token is not None:
                            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(
                                TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                                .first()
                            if TbAgencyApiTokenArray is not None:
                                tokenArray = {'Token': token, 'ExpireTime': expiration}
                                TbAgencyApiToken.objects.filter(id=TbAgencyApiTokenArray.id).update(**tokenArray)
                            else:
                                tokenArray = {'TbAgencyApiKey': TbAgencyApiKeyArray,
                                              'SecurityKey': Security_Key,
                                              'Token': token, 'ExpireTime': expiration}
                                TbAgencyApiToken.objects.create(**tokenArray)
                            return Response(json_data)
                        else:
                            return Response({'error': 'Please check username and password', "status": False},
                                            status=HTTP_500_INTERNAL_SERVER_ERROR)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please contact to administrator", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please contact to administrator", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please contact to administrator", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class SearchResults(APIView):
    def post(self, request, format=None):
        json_return = {}
        h = s = k = 0
        json_return_supplier = {}
        json_return_x = {}
        json_return_arr = {}
        json_return_arr_supplier = {}
        ddd = {}
        json_return_xarr = {}
        json_travel_z_gear_x = {}
        json_travel_z_gear = {}
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            air_iq_source = request.data.get("air_iq_source", False)
            go_fly_smart_source = request.data.get("go_fly_smart_source", False)
            travel_z_gear = request.data.get("travel_z_gear", False)
            origin = request.data.get("origin", None)
            destination = request.data.get("destination", None)
            adults = request.data.get("adults", None)
            child = request.data.get("child", None)
            infant = request.data.get("infant", None)
            airline = request.data.get("airline", None)
            departure_date = request.data.get("departure_date", None)
            if air_iq_source:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None:
                    air_iq_url = "https://omairiq.azurewebsites.net/search"
                    air_iq_url_supplier = "https://omairiq.azurewebsites.net/suppliersearch"
                    d = datetime.datetime.strptime(departure_date, '%d-%m-%Y')
                    rrr = datetime.date.strftime(d, "%Y/%m/%d")
                    payload_air_iq = json.dumps({
                        "origin": origin,
                        "destination": destination,
                        "departure_date": rrr,
                        "adult": adults,
                        "child": child,
                        "infant": infant,
                        # "airline_code": "UK"
                    })
                    headers_air_iq = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'Content-Type': 'application/json'
                    }
                    response_air_iq_supplier = requests.request("POST", air_iq_url_supplier, headers=headers_air_iq,
                                                                data=payload_air_iq)
                    x_air_iq_supplier = response_air_iq_supplier.text
                    json_data_air_iq_supplier = json.loads(x_air_iq_supplier)
                    code_supplier = json_data_air_iq_supplier.get('code', None)
                    air_iq_data_supplier = json_data_air_iq_supplier.get('data', None)
                    if code_supplier and air_iq_data_supplier is not None:
                        if json_data_air_iq_supplier['code'] == '200' and json_data_air_iq_supplier['status']:
                            s = 0
                            for i in json_data_air_iq_supplier['data']:
                                json_return_arr_supplier = {
                                    s: {
                                        "api_type": "air_iq_supplier",
                                        "ticket_id": i['ticket_id'],
                                        "origin": i['origin'],
                                        "destination": i['destination'],
                                        "airline": i['airline'],
                                        "departure_date": i['departure_date'],
                                        "departure_time": i['departure_time'],
                                        "arival_time": i['arival_time'],
                                        "arival_date": i['arival_date'],
                                        "flight_number": i['flight_number'],
                                        "flight_route": i['flight_route'],
                                        "pax": i['pax'],
                                        "price": i['price'],
                                        "infant_price": i['infant_price'],
                                    }
                                }
                                json_return_supplier.update(json_return_arr_supplier)
                                s = s + 1
                    response_air_iq = requests.request("POST", air_iq_url, headers=headers_air_iq, data=payload_air_iq)
                    x_air_iq = response_air_iq.text
                    json_data_air_iq = json.loads(x_air_iq)
                    code = json_data_air_iq.get('code', None)
                    air_iq_data = json_data_air_iq.get('data', None)
                    if code and air_iq_data is not None:
                        if json_data_air_iq['code'] == '200' and json_data_air_iq['status']:
                            k = s
                            for i in json_data_air_iq['data']:
                                json_return_arr = {
                                    k: {
                                        "api_type": "air_iq",
                                        "ticket_id": i['ticket_id'],
                                        "origin": i['origin'],
                                        "destination": i['destination'],
                                        "airline": i['airline'],
                                        "departure_date": i['departure_date'],
                                        "departure_time": i['departure_time'],
                                        "arival_time": i['arival_time'],
                                        "arival_date": i['arival_date'],
                                        "flight_number": i['flight_number'],
                                        "flight_route": i['flight_route'],
                                        "pax": i['pax'],
                                        "price": i['price'],
                                        "infant_price": i['infant_price'],
                                    }
                                }
                                json_return.update(json_return_arr)
                                k = k + 1
                json_return.update(json_return_supplier)
            '''    
            if go_fly_smart_source:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"

                    d = datetime.datetime.strptime(departure_date, '%d-%m-%Y')
                    rrr = datetime.date.strftime(d, "%Y-%m-%d")

                    url = url + "flight/search?origin=" + origin + "&destination=" + destination + "&adults=" \
                          + str(adults) + "&child=" + str(child) + "&infant=" + str(infant) \
                          + "&departure_date=" + str(rrr)
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        '2023-01-01': 'v2'
                    }
                    response = requests.request("GET", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data_x = json.loads(x)
                    if json_data_x['success']:
                        h = k
                        for ik in json_data_x['data']:
                            try:
                                if 'infant' in ik:
                                    infant = ik['infant']
                                else:
                                    infant = 0
                                json_return_xarr = {
                                    h: {
                                        "api_type": "go_fly_smart",
                                        "ticket_id": ik['id'],
                                        "origin": ik['origin_code'],
                                        "destination": ik['destination_code'],
                                        "flight_number": ik['flight_no'],
                                        "flight_route": ik['flight_route'],
                                        "pax": ik['seats_available'],
                                        "price": ik['adult'],
                                        "infant_price": infant,
                                        "departure_date": ik['departure_date'],
                                        "departure_time": ik['departure_time'],
                                        "arival_time": ik['arrival_time'],
                                        "arival_date": ik['arrival_date'],
                                        "airline": ik['airline_code'],
                                    }
                                }
                                json_return_x.update(json_return_xarr)
                                h = h + 1
                            except KeyError:
                                continue
            '''
            if go_fly_smart_source:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"
                    url = url + "api/search?origin=" + origin + "&destination=" + destination + "&adults=" \
                          + str(adults) + "&child=" + str(child) + "&infant=" + str(infant) \
                          + "&departure_date=" + str(departure_date)
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'api-key': TbAgencyApiKeyArray.ClientCode
                    }
                    response = requests.request("GET", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data_x = json.loads(x)
                    if json_data_x['success']:
                        h = 0
                        h = k
                        for ik in json_data_x['data']['data']:
                            try:
                                json_return_xarr = {
                                    h: {
                                        "api_type": "go_fly_smart",
                                        "ticket_id": ik['id'],
                                        "origin": ik['destination']['origin']['code'],
                                        "destination": ik['destination']['destination']['code'],
                                        "airline": ik['airline']['name'],
                                        "departure_date": ik['travel_date'],
                                        "departure_time": ik['departure_time'],
                                        "arival_time": ik['arrival_time'],
                                        "arival_date": ik['arrival_date'],
                                        "flight_number": ik['flight_no'],
                                        "flight_route": None,
                                        "pax": ik['seats_available'],
                                        "price": ik['adult'],
                                        "infant_price": ik['infant']
                                    }
                                }
                                json_return_x.update(json_return_xarr)
                                h = h + 1
                            except KeyError:
                                continue
            if travel_z_gear:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    d = datetime.datetime.strptime(departure_date, '%d-%m-%Y')
                    rrr = datetime.date.strftime(d, "%Y-%m-%d")
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://cheapfixdeparture.com/"
                    else:
                        url = "https://travelportal.pro/"
                    url = url + "rest-api/air-tickets?from_airport_id=" + str(origin) + "&to_airport_id=" + str(
                        destination) + \
                          "&departure_date=" + str(rrr)
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                    }
                    response = requests.request("GET", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data_x = json.loads(x)
                    m = h
                    for ik in json_data_x:
                        try:
                            json_travel_z_gear_return = {}
                            if ik['return_flight_id'] is not None:
                                json_travel_z_gear_return = {
                                    "return_flight": {
                                        "origin": ik['return_flight']['from_airport_id'],
                                        "destination": ik['return_flight']['to_airport_id'],
                                        "airline": ik['return_flight']['airline']['name'],
                                        "departure_date": ik['return_flight']['departure_at'],
                                        "departure_time": '',
                                        "arival_time": ik['return_flight']['arrival_at'],
                                        "arival_date": '',
                                        "flight_number": ik['return_flight']['flight_number'],
                                    }
                                }
                            json_travel_z_gear = {
                                m: {
                                    "api_type": "travel_z_gear",
                                    "ticket_id": ik['id'],
                                    "flight_route": None,
                                    "pax": ik['left_seats'],
                                    "price": ik['price'],
                                    "infant_price": ik['infant_price'],
                                    "origin": ik['flight']['from_airport_id'],
                                    "destination": ik['flight']['to_airport_id'],
                                    "airline": ik['flight']['airline']['name'],
                                    "departure_date": ik['flight']['departure_at'],
                                    "departure_time": '',
                                    "arival_time": ik['flight']['arrival_at'],
                                    "arival_date": '',
                                    "flight_number": ik['flight']['flight_number'],
                                }
                            }
                            json_travel_z_gear[m].update(json_travel_z_gear_return)
                            json_travel_z_gear_x.update(json_travel_z_gear)
                            m = m + 1
                        except KeyError:
                            continue
        ddd.update(json_return)
        ddd.update(json_return_x)
        ddd.update(json_travel_z_gear_x)
        return Response(ddd)


class BaggageInformation(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            ticket_id = request.data.get("ticket_id", None)
            go_fly_smart_source = request.data.get("go_fly_smart_source", False)
            if ticket_id and go_fly_smart_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'api-key': TbAgencyApiKeyArray.ClientCode
                    }
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"
                    url = url + "api/baggage-information?ticket_id=" + str(ticket_id)
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class AvailableDates(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            go_fly_return_json = {}
            air_iq_return_json = {}
            travel_z_gear_json = {}
            air_iq_return_json_supplier = {}
            air_iq_source = request.data.get("air_iq_source", False)
            go_fly_smart_source = request.data.get("go_fly_smart_source", False)
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    origin = request.data.get("origin", None)
                    destination = request.data.get("destination", None)
                    if origin is not None and destination is not None:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://cheapfixdeparture.com/"
                        else:
                            url = "https://travelportal.pro/"
                        url = url + "rest-api/sector-available-dates?from_airport_id=" + str(origin) + "&to_airport_id=" \
                              + str(destination)
                        payload = {}
                        files = {}
                        headers = {
                            'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                        }
                        try:
                            response = requests.request("GET", url, headers=headers, data=payload, files=files)
                            x = response.text
                            json_data_x = json.loads(x)
                            # print(json_data_x)
                            h = 0
                            for ik in json_data_x:
                                try:
                                    json_data_xx = {
                                        h: {"source": 'travel_z_gear', "departure_date": ik['departure_date'],
                                            "lowest_price": ik['lowest_price']}}
                                    h = h + 1
                                except Exception as e:
                                    json_data_xx = {}
                                if json_data_xx:
                                    travel_z_gear_json.update(json_data_xx)
                        except Exception as e:
                            travel_z_gear_json = {}
                else:
                    travel_z_gear_json = {}
            if go_fly_smart_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                    origin = request.data.get("origin", None)
                    destination = request.data.get("destination", None)
                    if origin is not None and destination is not None:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://goflysmartapi.azure-api.net/prod/"
                        else:
                            url = "https://goflysmartapi.azure-api.net/uat/"
                        url = url + "api/get-stock?origin=" + str(origin) + "&destination=" + str(destination)
                        payload = {}
                        files = {}
                        headers = {
                            'api-key': TbAgencyApiKeyArray.ClientCode,
                            'Authorization': TbAgencyApiTokenArray.Token,
                        }
                        try:
                            response = requests.request("GET", url, headers=headers, data=payload, files=files)
                            x = response.text
                            json_data_x = json.loads(x)
                            if json_data_x['success']:
                                h = 0
                                for ik in json_data_x['data']:
                                    try:
                                        json_data_xx = {
                                            h: {"source": 'go_fly_smart', "Dates": ik}}
                                        h = h + 1
                                    except Exception as e:
                                        json_data_xx = {}
                                    if json_data_xx:
                                        go_fly_return_json.update(json_data_xx)
                        except Exception as e:
                            go_fly_return_json = {}
                else:
                    go_fly_return_json = {}
            '''        
            if go_fly_smart_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                    origin = request.data.get("origin", None)
                    destination = request.data.get("destination", None)
                    if origin is not None and destination is not None:
                        if TbAgencyApiKeyArray.api_mode == 1:
                            url = "https://goflysmartapi.azure-api.net/prod/"
                        else:
                            url = "https://goflysmartapi.azure-api.net/uat/"
                        url = url + "flight/sector/dates?origin=" + str(origin) + "&destination=" + str(destination)
                        payload = {}
                        files = {}
                        headers = {
                            'api-key': TbAgencyApiKeyArray.ClientCode,
                            'Authorization': TbAgencyApiTokenArray.Token,
                            '2023-01-01': 'v2'
                        }
                        try:
                            response = requests.request("GET", url, headers=headers, data=payload, files=files)
                            x = response.text
                            json_data_x = json.loads(x)
                            if json_data_x['success']:
                                h = 0
                                for ik in json_data_x['data']:
                                    try:
                                        json_data_xx = {
                                            h: {"source": 'go_fly_smart', "Dates": ik}}
                                        h = h + 1
                                    except Exception as e:
                                        json_data_xx = {}
                                    if json_data_xx:
                                        go_fly_return_json.update(json_data_xx)
                        except Exception as e:
                            go_fly_return_json = {}
                else:
                    go_fly_return_json = {}
            '''
            if air_iq_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                    origin = request.data.get("origin", None)
                    destination = request.data.get("destination", None)
                    if origin is not None and destination is not None:
                        payload_air_iq = json.dumps({
                            "origin": origin,
                            "destination": destination
                        })
                        url_supplier = "https://omairiq.azurewebsites.net/supplieravailability"
                        headers = {
                            'api-key': TbAgencyApiKeyArray.ClientCode,
                            'Authorization': TbAgencyApiTokenArray.Token,
                            'Content-Type': 'application/json'
                        }

                        try:
                            response_supplier = requests.request("POST", url_supplier, headers=headers,
                                                                 data=payload_air_iq)
                            x_supplier = response_supplier.text
                            json_data_x_supplier = json.loads(x_supplier)
                            if json_data_x_supplier['status'] == 'success' and json_data_x_supplier['code'] == '200':
                                hk = 0
                                for ik in json_data_x_supplier['data']:
                                    try:
                                        json_data_xx_supplier = {
                                            hk: {"source": 'air_iq_supplier', "Dates": ik}}
                                        hk = hk + 1
                                    except Exception as e:
                                        json_data_xx_supplier = {}
                                    if json_data_xx_supplier:
                                        air_iq_return_json_supplier.update(json_data_xx_supplier)
                        except Exception as e:
                            air_iq_return_json_supplier = {}

                        url = "https://omairiq.azurewebsites.net/availability"
                        try:
                            response = requests.request("POST", url, headers=headers, data=payload_air_iq)
                            x = response.text
                            json_data_x = json.loads(x)
                            if json_data_x['status'] == 'success' and json_data_x['code'] == '200':
                                h = hk
                                for ik in json_data_x['data']:
                                    try:
                                        json_data_xx = {
                                            h: {"source": 'air_iq', "Dates": ik}}
                                        h = h + 1
                                    except Exception as e:
                                        json_data_xx = {}
                                    if json_data_xx:
                                        air_iq_return_json.update(json_data_xx)

                        except Exception as e:
                            air_iq_return_json = {}
                    else:
                        air_iq_return_json = {}
                else:
                    air_iq_return_json = {}
            air_iq_return_json.update(air_iq_return_json_supplier)
        ddd = [go_fly_return_json, air_iq_return_json, travel_z_gear_json]
        return Response(ddd)


class AvailableSectors(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            go_fly_return_json = {}
            air_iq_return_json = {}
            travel_z_gear_json = {}
            air_iq_source = request.data.get("air_iq_source", False)
            go_fly_smart_source = request.data.get("go_fly_smart_source", False)
            travel_z_gear = request.data.get("travel_z_gear", False)
            if travel_z_gear is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://cheapfixdeparture.com/rest-api/"
                    else:
                        url = "https://travelportal.pro/rest-api/"
                    url = url + "available-sectors"
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data_x = json.loads(x)
                        print(json_data_x)
                        m = 0
                        for ik in json_data_x:
                            try:
                                json_data_xx = {m: {"source": 'travel_z_gear', "Destination": (ik['to_airport_id']),
                                                    "Origin": ik['from_airport_id']}}
                                m = m + 1
                            except Exception as e:
                                json_data_xx = {}
                            if json_data_xx:
                                travel_z_gear_json.update(json_data_xx)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            if go_fly_smart_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiKeyArray is not None and TbAgencyApiTokenArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"
                    url = url + "api/available-destinations"
                    payload = {}
                    files = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Authorization': TbAgencyApiTokenArray.Token,
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data_x = json.loads(x)
                        if json_data_x['success']:
                            h = 0
                            for ik in json_data_x['data']:
                                try:
                                    json_data_xx = {h: {"source": 'go_fly_smart', "Destination": (ik['Destination']),
                                                        "Origin": ik['Origin']}}
                                    h = h + 1
                                except Exception as e:
                                    json_data_xx = {}
                                if json_data_xx:
                                    go_fly_return_json.update(json_data_xx)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)

                    '''
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"
                    url = url + "flight/sectors"
                    payload = {}
                    files = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Authorization': TbAgencyApiTokenArray.Token,
                        '2023-01-01': 'v2'
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data_x = json.loads(x)
                        h = 0
                        for ikk in json_data_x:
                            for ik in ikk['destinations']:
                                try:
                                    json_data_xx = {h: {"source": 'go_fly_smart', "Destination": (ik['cityCode']),
                                                        "Origin": ikk['cityCode']}}
                                    h = h + 1
                                except Exception as e:
                                    json_data_xx = {}
                                if json_data_xx:
                                    go_fly_return_json.update(json_data_xx)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                    '''
            if air_iq_source is True:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                    SecurityKey=Security_Key).first()
                TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                    .first()
                if TbAgencyApiTokenArray is not None:
                    url = "https://omairiq.azurewebsites.net/sectors"
                    payload = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'Content-Type': 'application/json'
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload)
                        x = response.text
                        json_data_air_iq = json.loads(x)
                        code = json_data_air_iq.get('code', None)
                        if code:
                            if json_data_air_iq['code'] == '200' and json_data_air_iq['status'] == 'success':
                                h = 0
                                for ik in json_data_air_iq['data']:
                                    try:
                                        if ik['destination'] is None:
                                            rr = rr + 1
                                        else:
                                            json_data_xxx = {
                                                h: {"source": 'air_iq', "Destination": (ik['destination']),
                                                    "Origin": ik['origin']}}
                                            h = h + 1
                                    except Exception as e:
                                        json_data_xxx = {}
                                    if json_data_xxx:
                                        air_iq_return_json.update(json_data_xxx)
                    except Exception as e:
                        air_iq_return_json = {}
                else:
                    air_iq_return_json = {}
        ddd = [air_iq_return_json, travel_z_gear_json, go_fly_return_json]
        return Response(ddd)


class GoFlySmartBooking(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://goflysmartapi.azure-api.net/prod/"
                else:
                    url = "https://goflysmartapi.azure-api.net/uat/"
                url = url + "api/book-ticket"
                payload = json.dumps(request.data)
                headers = {
                    'Authorization': TbAgencyApiTokenArray.Token,
                    'api-key': TbAgencyApiKeyArray.ClientCode,
                    'Content-Type': 'application/json'
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check api key", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


'''
class GoFlySmartBooking(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://goflysmartapi.azure-api.net/prod/"
                else:
                    url = "https://goflysmartapi.azure-api.net/uat/"
                url = url + "flight/booking"
                payload = json.dumps(request.data)
                headers = {
                    'Authorization': TbAgencyApiTokenArray.Token,
                    'api-key': TbAgencyApiKeyArray.ClientCode,
                    '2023-01-01': 'v2',
                    'Content-Type': 'application/json'
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check api key", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)



class TicketDetails(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                ticket_id = request.data.get("ticket_id", None)
                if ticket_id:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"
                    url = url + "ticket-details/" + str(ticket_id)
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        '2023-01-01': 'v2'
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check request values", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)

'''


class TicketDetails(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=3,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                ticket_id = request.data.get("ticket_id", None)
                if ticket_id:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://goflysmartapi.azure-api.net/prod/"
                    else:
                        url = "https://goflysmartapi.azure-api.net/uat/"
                    url = url + "api/ticket-details/" + str(ticket_id)
                    payload = {}
                    files = {}
                    headers = {
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check request values", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class AirIqTicketDetail(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                ticket_id = request.data.get("ticket_id", None)
                is_supplier_ticket = request.data.get("is_supplier_ticket", False)
                if ticket_id:

                    if is_supplier_ticket:
                        url = "https://omairiq.azurewebsites.net/supplierticket" \
                              "?booking_id=" + str(ticket_id)
                    else:
                        url = "https://omairiq.azurewebsites.net/ticket" \
                              "?booking_id=" + str(ticket_id)
                    payload = {}
                    headers = {
                        'api-key': TbAgencyApiKeyArray.ClientCode,
                        'Authorization': TbAgencyApiTokenArray.Token,
                        'Content-Type': 'application/json'
                    }
                    try:
                        response = requests.request("GET", url, headers=headers, data=payload)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
                else:
                    return Response({'error': "Please check request values", "status": False},
                                    status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class TravelZGearDetail(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                SecurityKey=Security_Key).first()
            ticket_id = request.data.get("ticket_id", None)
            if TbAgencyApiKeyArray is not None and ticket_id is not None:
                url = "https://cheapfixdeparture.com/rest-api/booking-checkout/" + str(ticket_id)
                payload = {}
                headers = {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("GET", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class TravelZGearPayWalletDetail(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                SecurityKey=Security_Key).first()
            ticket_id = request.data.get("ticket_id", None)
            if TbAgencyApiKeyArray is not None and ticket_id is not None:
                url = "https://cheapfixdeparture.com/rest-api/pay-wallet-booking/" + str(ticket_id)
                payload = {}
                headers = {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({'error': "Please check api key", "status": False},
                                status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check header value", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class AirIqBook(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        is_supplier_ticket = request.META.get('HTTP_SUPPLIERTICKET', False)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=4,
                                                                SecurityKey=Security_Key).first()
            TbAgencyApiTokenArray = TbAgencyApiToken.objects.filter(TbAgencyApiKey=TbAgencyApiKeyArray.id) \
                .first()
            if TbAgencyApiTokenArray is not None and TbAgencyApiKeyArray is not None:
                if is_supplier_ticket:
                    url = "https://omairiq.azurewebsites.net/supplierbook"
                else:
                    url = "https://omairiq.azurewebsites.net/book"

                payload = json.dumps(request.data)
                headers = {
                    'api-key': TbAgencyApiKeyArray.ClientCode,
                    'Authorization': TbAgencyApiTokenArray.Token,
                    'Content-Type': 'application/json'
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class TravelZGear(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=5,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                url = "https://cheapfixdeparture.com/rest-api/air-ticket-bookings"
                payload = json.dumps(request.data)
                headers = {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + TbAgencyApiKeyArray.ClientCode,
                }
                try:
                    response = requests.request("POST", url, headers=headers, data=payload)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)
        else:
            return Response({'error': "Please check security key", "status": False},
                            status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueGetSector(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            trip_type = request.data.get("trip_type", 'oneway')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=6,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://api.fareboutique.com/v1/api/sector"
                else:
                    url = "https://devapi.fareboutique.com/v1/api/sector"
                payload = json.dumps({
                    "trip_type": trip_type,
                    "end_user_ip": TbAgencyApiKeyArray.UserName,
                    "token": TbAgencyApiKeyArray.ClientCode
                })
                files = []
                headers = {'Accept': 'application/json',
                           'Content-Type': 'application/json'}
                try:
                    response = requests.request("POST", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data)
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueDestination(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            trip_type = request.data.get("trip_type", 'oneway')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=6,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://api.fareboutique.com/v1/api/departure_city_list"
                else:
                    url = "https://devapi.fareboutique.com/v1/api/departure_city_list"
                payload = json.dumps({
                    "trip_type": trip_type,
                    "end_user_ip": TbAgencyApiKeyArray.UserName,
                    "token": TbAgencyApiKeyArray.ClientCode
                })
                files = []
                headers = {'Accept': 'application/json',
                           'Content-Type': 'application/json'}
                try:
                    response = requests.request("POST", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data['data'])
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueArrival(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            trip_type = request.data.get("trip_type", 'oneway')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=6,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://api.fareboutique.com/v1/api/arrival_city_list"
                else:
                    url = "https://devapi.fareboutique.com/v1/api/arrival_city_list"
                payload = json.dumps({
                    "trip_type": trip_type,
                    "end_user_ip": TbAgencyApiKeyArray.UserName,
                    "departure_city_code": departure_city_code,
                    "token": TbAgencyApiKeyArray.ClientCode
                })
                files = []
                headers = {'Accept': 'application/json',
                           'Content-Type': 'application/json'}
                try:
                    response = requests.request("POST", url, headers=headers, data=payload, files=files)
                    x = response.text
                    json_data = json.loads(x)
                    return Response(json_data['data'])
                except Exception as e:
                    return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueOnwardDates(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            trip_type = request.data.get("trip_type", 'oneway')
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            departure_city_code = request.data.get("departure_city_code", None)
            arrival_city_code = request.data.get("arrival_city_code", None)
            departure_date = request.data.get("departure_date", None)
            if departure_city_code and arrival_city_code:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=6,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.com/v1/api/onward_dates"
                    else:
                        url = "https://devapi.fareboutique.com/v1/api/onward_dates"
                    if trip_type == 'oneway':
                        payload = json.dumps({
                            "trip_type": trip_type,
                            "end_user_ip": TbAgencyApiKeyArray.UserName,
                            "arrival_city_code": arrival_city_code,
                            "departure_city_code": departure_city_code,
                            "token": TbAgencyApiKeyArray.ClientCode
                        })
                    else:
                        payload = json.dumps({
                            "trip_type": trip_type,
                            "end_user_ip": TbAgencyApiKeyArray.UserName,
                            "arrival_city_code": arrival_city_code,
                            "departure_city_code": departure_city_code,
                            "departure_date": departure_date,
                            "token": TbAgencyApiKeyArray.ClientCode
                        })

                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data['data'])
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueSearch(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            departure_city_code = request.data.get("departure_city_code", None)
            arrival_city_code = request.data.get("arrival_city_code", None)
            trip_type = request.data.get("trip_type", 0)
            departure_date = request.data.get("departure_date", None)
            return_date = request.data.get("return_date", None)
            adult = request.data.get("adult", 0)
            children = request.data.get("children", 0)
            infant = request.data.get("infant", 0)
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            if departure_city_code and arrival_city_code:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=6,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.com/v1/api/search"
                    else:
                        url = "https://devapi.fareboutique.com/v1/api/search"
                    if trip_type == 0:
                        payload = json.dumps({
                            "end_user_ip": TbAgencyApiKeyArray.UserName,
                            "departure_city_code": departure_city_code,
                            "arrival_city_code": arrival_city_code,
                            "departure_date": departure_date,
                            "trip_type": trip_type,
                            "adult": adult,
                            "children": children,
                            "infant": infant,
                            "token": TbAgencyApiKeyArray.ClientCode
                        })
                    else:
                        payload = json.dumps({
                            "end_user_ip": TbAgencyApiKeyArray.UserName,
                            "departure_city_code": departure_city_code,
                            "arrival_city_code": arrival_city_code,
                            "departure_date": departure_date,
                            "trip_type": trip_type,
                            "return_date": return_date,
                            "adult": adult,
                            "children": children,
                            "infant": infant,
                            "token": TbAgencyApiKeyArray.ClientCode
                        })
                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueFareQuote(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=6,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://api.fareboutique.com/v1/api/fare_quote"
                else:
                    url = "https://devapi.fareboutique.com/v1/api/fare_quote"
                flight_id = request.data.get("flight_id", None)
                departure_date = request.data.get("departure_date", None)
                adult_children = request.data.get("adult_children", 0)
                infant = request.data.get("infant", 0)
                end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
                if flight_id:
                    payload = json.dumps({
                        "end_user_ip": TbAgencyApiKeyArray.UserName,
                        "token": TbAgencyApiKeyArray.ClientCode,
                        "flight_id": flight_id,
                        "departure_date": departure_date,
                        "adult_children": adult_children,
                        "infant": infant
                    })

                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueBooking(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        flight_data_final = {}
        if Security_Key:
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=6,
                                                                SecurityKey=Security_Key).first()
            if TbAgencyApiKeyArray is not None:
                if TbAgencyApiKeyArray.api_mode == 1:
                    url = "https://api.fareboutique.com/v1/api/book_flight"
                else:
                    url = "https://devapi.fareboutique.com/v1/api/book_flight"
                if request.data:
                    request.data["token"] = TbAgencyApiKeyArray.ClientCode
                    request.data["end_user_ip"] = TbAgencyApiKeyArray.UserName
                    payload = json.dumps(request.data)
                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FareBoutiqueBookingDetail(APIView):
    def post(self, request, format=None):
        Security_Key = request.META.get('HTTP_SECURITYKEY', None)
        if Security_Key:
            reference_id = request.data.get("reference_id", None)
            end_user_ip = request.data.get("end_user_ip", '183.83.43.117')
            if reference_id:
                TbAgencyApiKeyArray = TbAgencyApiKey.objects.filter(api_source_sys_id=6,
                                                                    SecurityKey=Security_Key).first()
                if TbAgencyApiKeyArray is not None:
                    if TbAgencyApiKeyArray.api_mode == 1:
                        url = "https://api.fareboutique.com/v1/api/booking_details"
                    else:
                        url = "https://devapi.fareboutique.com/v1/api/booking_details"
                    payload = json.dumps({
                        "reference_id": reference_id,
                        "end_user_ip": TbAgencyApiKeyArray.UserName,
                        "token": TbAgencyApiKeyArray.ClientCode

                    })
                    files = []
                    headers = {'Accept': 'application/json',
                               'Content-Type': 'application/json'}
                    try:
                        response = requests.request("POST", url, headers=headers, data=payload, files=files)
                        x = response.text
                        json_data = json.loads(x)
                        return Response(json_data)
                    except Exception as e:
                        return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


Youez - 2016 - github.com/yon3zu
LinuXploit