def one_way_trip(enquiry):
    start_date = dt.strptime(enquiry["dates"][0], '%d/%m/%Y')
    start_month = start_date.strftime('%Y-%m')
    adult_pax = int(enquiry['adult'])
    child_pax = len(enquiry['child_age'])
    child_age = enquiry['child_age']
    t.click('//input[@id="fsc-trip-type-selector-one-way"]')
    t.wait(0.5)
    t.type('//input[@id="fsc-origin-search"]', enquiry["city"][0])
    t.wait(0.5)
    t.type('//input[@id="fsc-destination-search"]', enquiry["city"][1])
    t.wait(0.5)
    t.click(
        '//button[@id="depart-fsc-datepicker-button"]//span[starts-with(@class,"DateInput")]'
    )
    t.click(f'//select[@id="depart-calendar__bpk_calendar_nav_select"]')
    t.select('//select[@id="depart-calendar__bpk_calendar_nav_select"]',
             f'{start_month}')
    t.click(
        f'//button[starts-with(@class,"BpkCalendarDate") and contains(@aria-label,"{start_date.strftime("%d %B %Y").lstrip("0")}")]'
    )
    t.click('//button[starts-with(@id,"CabinClassTravellersSelector")]')
    t.click('//select[@id="search-controls-cabin-class-dropdown"]')
    t.select('//select[@id="search-controls-cabin-class-dropdown"]',
             lookup_cabin_class(enquiry["cabin_class"]))

    # t.select('//select[@id="search-controls-cabin-class-dropdown"]',(enquiry["cabin_class"].capitalize()).replace(' ',''))
    number_of_travellers(adult_pax, child_pax, child_age)
    t.click('//button[@type="submit"][@aria-label="Search flights"]')
def multi_city_trip(enquiry):
    t.click('//input[@id="fsc-trip-type-selector-multi-destination"]')
    travel_dates = enquiry["dates"]
    numDep = len(travel_dates)
    cities = enquiry["city"]
    numCity = len(cities)
    form_flightleg = t.count(
        '//*[@id="flights-search-controls-root"]/div/div/form/div[2]/ol/li')
    if numDep < form_flightleg:
        for cnt in range(form_flightleg - numDep):
            t.click(
                f'//*[@id="flights-search-controls-root"]/div/div/form/div[2]/ol/li[{form_flightleg-cnt}]/div[4]/button'
            )
    elif numDep > form_flightleg:
        for cnt in range(numDep - form_flightleg):
            t.click(
                '//div[starts-with(@class,"MulticityControls_MulticityControls__add-leg-wrapper__2arYh")]/button'
            )
            t.wait(0.5)

    for num in range(0, numDep):
        start_date = dt.strptime(travel_dates[num], '%d/%m/%Y')
        start_month = start_date.strftime('%Y-%m')
        orig_city = cities[num]
        if numCity == numDep:
            if num < numDep - 1:
                dest_city = cities[num + 1]
            else:
                dest_city = cities[0]
        else:
            dest_city = cities[num + 1]
        t.type(f'//input[@id="fsc-origin-search-{num}"]', orig_city)
        t.wait(0.5)
        t.type(f'//input[@id="fsc-destination-search-{num}"]', dest_city)
        t.wait(0.5)
        t.click(
            f'//button[@id="fsc-leg-date-{num}-fsc-datepicker-button"]//span[starts-with(@class,"DateInput")]'
        )
        t.click(
            f'//select[@id="fsc-leg-date-{num}-calendar__bpk_calendar_nav_select"]'
        )
        t.select(
            f'//select[@id="fsc-leg-date-{num}-calendar__bpk_calendar_nav_select"]',
            f'{start_month}')
        t.click(
            f'//button[starts-with(@class,"BpkCalendarDate") and contains(@aria-label,"{start_date.strftime("%d %B %Y").lstrip("0")}")]'
        )

    t.click('//button[starts-with(@id,"CabinClassTravellersSelector")]')
    t.click('//select[@id="search-controls-cabin-class-dropdown"]')
    t.select('//select[@id="search-controls-cabin-class-dropdown"]',
             lookup_cabin_class(enquiry["cabin_class"]))
    adult_pax = int(enquiry['adult'])
    child_pax = len(enquiry['child_age'])
    child_age = enquiry['child_age']
    number_of_travellers(adult_pax, child_pax, child_age)

    t.click('//button[@type="submit"][@aria-label="Search flights"]')
def multi_city_trip(enquiry):
    t.click('//input[@id="flight-type-multi-dest-hp-flight"]')
    travel_dates = enquiry["dates"]
    numDep = len(travel_dates)
    cities = enquiry["city"]
    numCity = len(cities)

    form_flightleg = (t.count(
        '//div[@class="cols-nested gcw-multidest-flights-container"]/div/fieldset'
    ))
    print(form_flightleg)
    if numDep < form_flightleg:
        for cnt in range(form_flightleg - numDep):
            t.click(
                f'//*[@id="flightlegs-list-fieldset-{form_flightleg-cnt}-hp-flight"]/div/a'
            )
    elif numDep > form_flightleg:
        for cnt in range(numDep - form_flightleg):
            t.click('//a[@id="add-flight-leg-hp-flight"]')
            t.wait(0.5)

    t.type('//input[@id="flight-origin-hp-flight"]', cities[0])
    t.type('//input[@id="flight-destination-hp-flight"]', cities[1])
    t.type('//input[@id="flight-departing-single-hp-flight"]', '[clear]')
    t.type('//input[@id="flight-departing-single-hp-flight"]',
           (dt.strptime(travel_dates[0], '%d/%m/%Y')).strftime("%d/%m/%Y"))

    for num in range(1, numDep):
        print(f"num:{num} and form_flightleg:{form_flightleg}")

        start_date = dt.strptime(travel_dates[num], '%d/%m/%Y')
        orig_city = cities[num]
        if numCity == numDep:
            if num < numDep - 1:
                dest_city = cities[num + 1]
            else:
                dest_city = cities[0]
        else:
            dest_city = cities[num + 1]

        t.type(f'//input[@id="flight-{num+1}-origin-hp-flight"]', orig_city)
        t.wait(0.5)
        t.type(f'//input[@id="flight-{num+1}-destination-hp-flight"]',
               dest_city)
        t.wait(0.5)
        t.type(f'//input[@id="flight-{num+1}-departing-hp-flight"]', '[clear]')
        t.type(f'//input[@id="flight-{num+1}-departing-hp-flight"]',
               start_date.strftime("%d/%m/%Y"))

    t.click('//a[@id="flight-advanced-options-hp-flight"]')
    t.select('//select[@id="flight-advanced-preferred-class-hp-flight"]',
             lookup_cabin_class(enquiry["cabin_class"]))
    t.click('//*[@id="gcw-flights-form-hp-flight"]/div[8]/label/button')
def one_way_trip(enquiry):
    start_date = dt.strptime(enquiry["dates"][0], '%d/%m/%Y')

    t.click('//input[@id="flight-type-one-way-hp-flight"]')
    t.type('//input[@id="flight-origin-hp-flight"]', enquiry["city"][0])
    t.type('//input[@id="flight-destination-hp-flight"]', enquiry["city"][1])
    t.type('//input[@id="flight-departing-single-hp-flight"]', '[clear]')
    t.type('//input[@id="flight-departing-single-hp-flight"]',
           start_date.strftime("%d/%m/%Y"))
    t.click('//*[@id="traveler-selector-hp-flight"]/div/ul/li/button')
    t.click('//a[@id="flight-advanced-options-hp-flight"]')
    t.select('//select[@id="flight-advanced-preferred-class-hp-flight"]',
             lookup_cabin_class(enquiry["cabin_class"]))
    t.click('//*[@id="gcw-flights-form-hp-flight"]/div[8]/label/button')
def check_availability(reservation_date,reservation_time,party_size,restaurant_name):
    try:
        #Convert User Defined Values to System Usable Values
        reservation_day=reservation_date.split('/')[0]
        reservation_month =reservation_date.split('/')[1]
        reservation_month=int(reservation_month)-1
        reservation_year =reservation_date.split('/')[2]
        reservation_time_int=int(reservation_time)
        start_time_hr= reservation_time[:2]
        if reservation_time_int>1159:
            if start_time_hr!="12":
                start_time_hr=int(start_time_hr)-12
            start_time_option = str(start_time_hr)+":"+reservation_time[2:4]+" pm"
        else:
            start_time_option = str(start_time_hr)+":"+reservation_time[2:4]+" am"
             
        #Booking Parameters
        chope_url ='https://www.chope.co/singapore-restaurants/category/restaurant/'
        t.init()
        t.url(chope_url) 
        t.wait(10)
        #Date Field
        t.click(f"(//span[contains(@class,'input-group-addon icon-calendar')])[1]")
        t.wait(7)
        boolean_flag=1
        while boolean_flag:
            if t.present(f"//td[@data-handler='selectDay'and @data-year='{reservation_year}' and @data-month='{reservation_month}']/a[text()='{reservation_day}']"):
                t.click(f"//td[@data-handler='selectDay'and @data-year='{reservation_year}' and @data-month='{reservation_month}']/a[text()='{reservation_day}']")
                boolean_flag=0
            else:
                t.click('//a[@title="Next"]')
        t.click(f"//td[@data-handler='selectDay'and @data-month='{reservation_month}']/a[text()='{reservation_day}']")
        #Time Field
        t.select(f"//select[contains(@id,'time-field')]",start_time_option)
        #Number of Diners Field
        t.click(f"(//span[contains(@class,'input-group-addon icon-person')])[1]")
        t.select(f"//select[contains(@id,'adults')]",party_size)
        #Restaurant Field
        t.type(f"//select[contains(@id,'sb-sel-restaurant')]",restaurant_name)
        t.click('//button[@id="btn-search"]')
        t.wait(5)
        if t.present(f"//div[@class='alert alert-danger']"):
            print('Not Available')
            return 0
        else:
            print ('Available')
            return 1
    except:
        print('Error')
        return 'Reservation Unsuccessful. Unforunately, the restaurant was not able to accomodate your reservation.'
def number_of_travellers(adult_pax, children_pax, children_age):
    print(f"Adults: {adult_pax} and Children: {children_pax}")
    form_adult_pax = int(
        t.read('//input[@id="search-controls-adults-nudger"]'))
    form_children_pax = int(
        t.read('//input[@id="search-controls-children-nudger"]'))
    print(
        f"Form Current Adults: {form_adult_pax} and Children: {form_children_pax}"
    )
    # set the number of adult travellers
    if adult_pax > form_adult_pax:
        for n in range(form_adult_pax, adult_pax):
            t.click('//button[@title="Increase number of adults"]')
            t.wait(1)
    elif adult_pax < form_adult_pax:
        for x in range(0, form_adult_pax - adult_pax):
            t.click('//button[@title="Decrease number of adults"]')
            t.wait(1)
    else:
        for n in range(form_adult_pax, adult_pax):
            t.click('//button[@title="Increase number of adults"]')
            t.wait(1)

    # set the number of child travellers
    if children_pax > form_children_pax:
        for n in range(form_children_pax, children_pax):
            t.click('//button[@title="Increase number of children"]')
            t.wait(1)
    elif children_pax < form_children_pax:
        for x in range(0, form_children_pax - children_pax):
            t.click('//button[@title="Decrease number of children"]')
            t.wait(1)
    else:
        for n in range(form_children_pax, children_pax):
            t.click('//button[@title="Increase number of children"]')
            t.wait(1)

    # Set the age for each child traveller
    if len(children_age) > 0:
        for m in range(0, len(children_age)):
            t.click(f'//select[@id="children-age-dropdown-{m}"]')
            t.select(f'//select[@id="children-age-dropdown-{m}"]',
                     str(children_age[m]))

    t.click(
        '//section[@id="cabin-class-travellers-popover"]//button[.="Done"]')
def return_trip(enquiry):
    start_date = dt.strptime(enquiry["dates"][0], '%d/%m/%Y')
    end_date = dt.strptime(enquiry["dates"][1], '%d/%m/%Y')

    t.click('//input[@id="flight-type-roundtrip-hp-flight"]')
    t.type('//input[@id="flight-origin-hp-flight"]', enquiry["city"][0])
    t.type('//input[@id="flight-destination-hp-flight"]', enquiry["city"][1])
    t.type('//input[@id="flight-departing-hp-flight"]', '[clear]')
    t.type('//input[@id="flight-departing-hp-flight"]',
           start_date.strftime("%d/%m/%Y"))
    t.click('//*[@id="traveler-selector-hp-flight"]/div/ul/li/button')
    t.click('//a[@id="flight-advanced-options-hp-flight"]')
    t.select('//select[@id="flight-advanced-preferred-class-hp-flight"]',
             lookup_cabin_class(enquiry["cabin_class"]))
    t.click('//*[@id="gcw-flights-form-hp-flight"]/div[8]/label/button')
    tu.wait_for_pageload('//button[@id="flights-advanced-options-toggle"]')
    curr_enddate = t.read('//input[@id="return-date-1"]')
    if curr_enddate != end_date.strftime("%d/%m/%Y"):
        t.type('//input[@id="return-date-1"]', '[clear]')
        t.type('//input[@id="return-date-1"]', end_date.strftime("%d/%m/%Y"))
    t.click('//*[@id="flight-wizard-search-button"]')
def number_of_travellers(adult_pax, children_pax, children_age):
    print(f"Adults: {adult_pax} and Children: {children_pax}")
    t.click(f'//select[@id="adult-count"]')
    t.select('//select[@id="adult-count"]', f'{adult_pax}')

    # set the number of child travellers
    t.click(f'//select[@id="child-count"]')
    t.select('//select[@id="child-count"]', f'{children_pax}')

    # Set the age for each child traveller
    if children_pax > 0:
        for m in range(0, children_pax):
            print(f'Child {m+1} age {str(children_age[m])}')
            t.click(f'//select[@id="child-age-{m+1}"]')
            t.wait(1)
            t.select(f'//select[@id="child-age-{m+1}"]', str(children_age[m]))
            t.wait(1)
Ejemplo n.º 9
0
logpath.mkdir(exist_ok=True)

log_name = datetime.datetime.now().strftime('resume_%H_%M_%d_%m_%Y.log')
logging.basicConfig(filename=logpath / log_name, level=logging.INFO)

# start chrome
t.init()

while PROCEED == True:

    batch_count += 1
    t.url(url)
    print(f'\n-----start batch {batch_count}-----\n')

    # start date
    t.select('//select[@id="searchForm_selectedFromPeriodProjectName"]',
             START_DATE)

    # end date
    t.select('//select[@id="searchForm_selectedToPeriodProjectName"]',
             END_DATE)

    # type of sale
    t.click('//label[@for="checkbox1"]')
    t.click('//label[@for="checkbox2"]')
    t.click('//label[@for="checkbox3"]')

    project_total = t.count('//div[@id="projectContainerBox"]/a')

    # select projects
    for _ in range(SELECTION_LIMIT):
        if project_count > project_total - 1:
Ejemplo n.º 10
0
t.keyboard('[esc]')     
t.wait(1)
t.keyboard('[tab]')
t.wait(1)
t.keyboard('[esc]')
t.wait(4)
t.click('//*[@id="nav"]/li[1]/a')
t.wait(2)
path=r'C:\Users\garv2\Desktop\INDIAN OVERSEAS BANK\balance.jpeg'#PATH
balance="balance"+str(filename)
path=path.replace("balance",balance)
t.snap('page',path)
t.wait(2)
t.click('//*[@id="nav"]/li[3]/a')
t.wait(2)
t.select('//*[@id="accountNo"]','010002000011105')
t.wait(2)
t.click('//*[@id="tcalico_0"]')
t.wait(3)
tr2=tr
td2=a-1
if a==1:
    td2=7
    tr2=tr-1
    if tr==2:
        tr2=6
        t.click('//*[@id="tcal"]/table[1]/tbody/tr/td[2]/img')
        t.wait(2)
element1='//*[@id="tcal"]/table[2]/tbody/'+'/tr['+str(tr)+']/td['+str(td2)+']'
element2='//*[@id="tcal"]/table[2]/tbody/'+'/tr['+str(tr2)+']/td['+str(a)+']'
#print(element1)
def make_reservation(reservation_date,reservation_time,party_size,restaurant_name,first_name,last_name,email_address,phone_number):
    try:
        #Convert User Defined Values to System Usable Values
        reservation_day=reservation_date.split('/')[0]
        reservation_month =reservation_date.split('/')[1]
        reservation_month=int(reservation_month)-1
        reservation_year =reservation_date.split('/')[2]
        reservation_time_int=int(reservation_time)
        start_time_hr= reservation_time[:2]
        if reservation_time_int>1159:
            if start_time_hr!="12":
                start_time_hr=int(start_time_hr)-12
            start_time_option = str(start_time_hr)+":"+reservation_time[2:4]+" pm"
        else:
            start_time_option = str(start_time_hr)+":"+reservation_time[2:4]+" am"
            
        #Booking Parameters
        chope_url ='https://www.chope.co/singapore-restaurants/category/restaurant/'
        t.init()
        t.url(chope_url)
        t.wait(10)
        #Date Field
        t.click(f"(//span[contains(@class,'input-group-addon icon-calendar')])[1]")
        t.wait(7)
        boolean_flag=1
        while boolean_flag:
            if t.present(f"//td[@data-handler='selectDay'and @data-year='{reservation_year}' and @data-month='{reservation_month}']/a[text()='{reservation_day}']"):
                t.click(f"//td[@data-handler='selectDay'and @data-year='{reservation_year}' and @data-month='{reservation_month}']/a[text()='{reservation_day}']")
                boolean_flag=0
            else:
                t.click('//a[@title="Next"]')
        t.click(f"//td[@data-handler='selectDay'and @data-month='{reservation_month}']/a[text()='{reservation_day}']")
        #Time Field
        t.select(f"//select[contains(@id,'time-field')]",start_time_option)
        #Number of Diners Field
        t.click(f"(//span[contains(@class,'input-group-addon icon-person')])[1]")
        t.select(f"//select[contains(@id,'adults')]",party_size)
        #Restaurant Field
        t.type(f"//select[contains(@id,'sb-sel-restaurant')]",restaurant_name)
        t.click('//button[@id="btn-search"]')
        t.wait(5)
        
        #Secondary Page to Confirm Timing
        t.click(f"//a[contains(@rname,'{restaurant_name}') and text()='{start_time_option}']")
        t.wait(5)
        t.click(f"//input[@id='btn_sub' and @value='Book Now']")
        t.wait(5)
        
        #Booking Confirmation
        t.popup('https://book.chope.co/')
        #First Name
        t.type('//input[@id="forename"]',first_name)
        #Last Name
        t.type('//input[@id="surname"]',last_name)
        #Email
        t.type('//input[@id="email"]',email_address)
        #Phone Number
        t.type('//input[@id="telephone"]',phone_number)
        #Agree Terms & Conditions
        if t.present(f"//input[@name='agree_term_conditions']"):
            t.click(f"//input[@name='agree_term_conditions']")
        #Confirm Booking
        t.click(f"//button[@id='check_book_now']")
        t.wait(5)
        t.close()
        print('Success')
        schedule_reservation(reservation_date,reservation_time,party_size,restaurant_name,first_name,sample_restaurant_address)
        return 'Reservation Successful'
    except:
        print('Error')
        return 'Reservation Unsuccessful. Unforunately, the restaurant was not able to accomodate your reservation.'