ó
UX[c           @   sp   d  d l  Td  d l Z d  d l m Z d  d l m Z d  d l Z e ƒ  Z d „  Z d „  Z	 e
 d d „ Z d S(	   iÿÿÿÿ(   t   *N(   t   pprint(   t   etreec         C   sß   d } xÒ t  t |  ƒ ƒ D]¾ } |  | } | | } | | }	 | | }
 | | } d | j ƒ  k rl d } n! d | j ƒ  k r‡ d } n d } | } | d t | d ƒ d	 | d
 |	 d |
 d | d | d 7} q W| S(   Nt    t   ECONOMYt   Yt   BUSINESSt   Jt   Fs$   <OriginDestinationInformation RPH ='i   s*   '>
                    <DepartureDateTime>s\   </DepartureDateTime>
                    
                    <OriginLocation LocationCode='s=   ' />
                    <DestinationLocation LocationCode ='s\   ' />
                    <TPA_Extensions>
                        <AlternateTime PlusMinus='sF   '/>
                        <CabinPref PreferLevel='Preferred' Cabin='sc   '/>
                    </TPA_Extensions>
                </OriginDestinationInformation >
        (   t   ranget   lent   uppert   str(   t   datesofdeparturet   timewindowst
   departurest   arrivalst	   cabinListt   bodyt   indext   departuredatetimet   departurewindowt	   departuret   arrivalt   cabint   rd(    (    s6   /mnt/c/Users/Mahat/Documents/tripnomics-1.2/py/test.pyt   requestBody   s"    




		9c         C   sí   yÈ t  j j d d d d d d d d ƒ } | j ƒ  } t | _ d	 d
 d d d } t |  | | d | | | | | | |	 |
 | | | | g ƒ } | j | | ƒ | j ƒ  | j	 GH| j
 ƒ  | j
 ƒ  Wn t k
 rè } | GHd GHt SXt S(   Nt   usert   rt_bott   passwords   mp.work.t   hosts   tripnomicsdb.cloudapp.nett   databaset   Alternatefares¯  INSERT INTO Fare_Details(
            `TktNumber`,
            `PNR`,
            `Timestamp`,
            `GDS_Source`,
            `Origin`,
            `Destination`,
            `DateOfJourney`,
            `Airline`,
            `FlightNo`,
            `DepartureTime`,
            `ArrivalTime`,
            `Fare`,
            `FareBasis`,
            `FareClass`,
            `FareID`,
            `Dep_Date`
            ) s   VALUES(s   %s,i   s   %s)t   1Ss4   ERROR !!!!!! Can't commit alternate fare to database(   t   mysqlt	   connectort   connectt   cursort   Truet
   autocommitt   tuplet   executet   committ	   statementt   closet	   Exceptiont   False(   t	   tktnumbert   pnrt	   timestampt   origint   destinationt   dep_datet   marketing_airline_codet   flight_numbert   dep_timet   arr_timet   faret
   fare_basist   rbdt   orgt   destt   fidt   ddtt   orderbyt   cnxR%   t   add_gen_rowt   gen_info_insertt   e(    (    s6   /mnt/c/Users/Mahat/Documents/tripnomics-1.2/py/test.pyt   commit_alt_fare*   sD    		

i   c	   )      C   sm  t  ƒ  }	 d |	 d t | | | | | ƒ d t | ƒ d }
 t j t d |
 d t ƒ} | j GHt |	 ƒ d d  l	 } | j
 j j | j ƒ } | j ƒ  } | GHt j | j ƒ } | d d } | j } | j d  ƒ d | d	 <| j d
 d | ƒ} t j j ƒ  j d ƒ } d } d } xL| d  D]@} | j d ƒ } | j d d | ƒ} d t | ƒ } x| D]û} t j j ƒ  j d ƒ } | j d d | ƒd j d ƒ } | j d d | ƒd j d ƒ } | j d d | ƒd j d ƒ } | j d d | ƒd j d ƒ } | j d d | ƒd j d ƒ } | j d ƒ }  | j d ƒ }! | j d ƒ }" t j j |" d ƒ }# |# j d  ƒ }" |# j d! ƒ }$ | j d" ƒ }% t j j |% d ƒ }& |& j d! ƒ }% | j d# d | ƒd j d$ ƒ }' |" d% |$ }( t j j |( d& ƒ }( |( j d ƒ }( | r$|( } n  t | |  | | | |" | |  |$ |% | |' |! | | | | | ƒ qfWq%Wd  S('   Nsƒ   <SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:eb='http://www.ebxml.org/namespaces/messageHeader' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xsd='http://www.w3.org/1999/XMLSchema'>
            <SOAP-ENV:Header>
                <eb:MessageHeader SOAP-ENV:mustUnderstand='1' eb:version='2.0'>
                    <eb:From>
                    <eb:PartyId type='urn:x12.org:IO5:01'>1212</eb:PartyId>
                    </eb:From>
                    <eb:To>
                    <eb:PartyId type='urn:x12.org:IO5:01'>2323</eb:PartyId>
                    </eb:To>
                    <eb:CPAId>6B3D</eb:CPAId>
                    <eb:ConversationId>TEST-6B3D</eb:ConversationId>
                    <eb:Service eb:type='OTA'>BargainFinderMaxRQ</eb:Service>
                    <eb:Action>BargainFinderMaxRQ</eb:Action>
                    <eb:MessageData>
                    <eb:MessageId>1001</eb:MessageId>
                    <eb:Timestamp>2012-06-07T10:00:01</eb:Timestamp>
                    <eb:TimeToLive>2013-06-06T23:59:59</eb:TimeToLive>
                    </eb:MessageData>
                </eb:MessageHeader>
                <wsse:Security xmlns:wsse='http://schemas.xmlsoap.org/ws/2002/12/secext' xmlns:wsu='http://schemas.xmlsoap.org/ws/2002/12/utility'>
                    <wsse:BinarySecurityToken valueType='String' EncodingType='wsse:Base64Binary'>sV  </wsse:BinarySecurityToken>
                </wsse:Security>
            </SOAP-ENV:Header><SOAP-ENV:Body>
            
    <OTA_AirLowFareSearchRQ
            xmlns='http://www.opentravel.org/OTA/2003/05'
            ResponseType='OTA'
            ResponseVersion='4.1.0'
            Version='4.1.0'
            AvailableFlightsOnly='true'>
            <POS>
                <Source PseudoCityCode='6B3D'>
                    <RequestorID ID='1' Type='1'>
                        <CompanyName Code='TN'/>
                    </RequestorID>
                </Source>
            </POS>
            sÓ  
            
            <TravelPreferences
                ETicketDesired='true'
                ValidInterlineTicket='true'
                MaxStopsQuantity='2'
                Hybrid='true'
                LookForAlternatives='true'>            
            </TravelPreferences>
            <TravelerInfoSummary>
                <SeatsRequested>1</SeatsRequested>
                <AirTravelerAvail>
                    <PassengerTypeQuantity Code='ADT' Quantity='sž  '/>
                </AirTravelerAvail>
            </TravelerInfoSummary>
            <TPA_Extensions>
                <IntelliSellTransaction>
                    <RequestType Name='100ITINS'/>
                    <ResponseSorting SortFaresInsideItin='true'/>
                </IntelliSellTransaction>
            </TPA_Extensions>
        </OTA_AirLowFareSearchRQ>

        </SOAP-ENV:Body></SOAP-ENV:Envelope> t   datat   headersiÿÿÿÿs%   http://www.opentravel.org/OTA/2003/05t   ddds   .//ddd:PricedItineraryt
   namespacess   %Y-%m-%d %H:%M:%SR   i
   t   SequenceNumbers   .//ddd:FlightSegments   Fare s   .//ddd:MarketingAirlinei    t   Codes   .//ddd:DepartureAirportt   LocationCodes   .//ddd:ArrivalAirports"   .//ddd:ItinTotalFare//ddd:BaseFaret   CurrencyCodes#   .//ddd:ItinTotalFare//ddd:TotalFaret   Amountt   FlightNumbert   ResBookDesigCodet   DepartureDateTimes   %Y-%m-%dT%H:%M:%Ss   %Y-%m-%ds   %H%Mt   ArrivalDateTimes   .//ddd:FareCalcLinet   Infot    s   %Y-%m-%d %H%M(   t   start_sessionR   R   t   requestst   postt   urlRG   t   contentt   stop_sessiont   xml.dom.minidomt   domt   minidomt   parseStringt   toprettyxmlR   t   XMLt   nsmapt   popt   Nonet   xpatht   datetimet   nowt   strftimet   gett   strptimeRE   ()   R0   R/   R   R   R   R   R   t   faredropt	   paxNumbert   tR   t   responset   xmlt   pretty_xml_as_stringt   roott   yt   nst   PricedItinerariesR?   R<   R=   t   priceditineraryR@   t   flightsegmentsR>   t   flightsegmentR1   R5   R2   R3   t   currencyR9   R6   R;   R4   t   depdateR7   R8   t   arrdateR:   t   depdatetime(    (    s6   /mnt/c/Users/Mahat/Documents/tripnomics-1.2/py/test.pyt	   file_Farei   sz    	3/
	
		(   t   defst   jsonR   t   lxmlR   RV   t   dictt   dR   RE   R.   R{   (    (    (    s6   /mnt/c/Users/Mahat/Documents/tripnomics-1.2/py/test.pyt   <module>   s   
			?