|
| 1 | +import os |
| 2 | +import telebot |
| 3 | +import requests |
| 4 | +import pandas as pd |
| 5 | + |
| 6 | +API_Key = "6453714074:AAEJFCtoIRzxkBtoKF1H2ExlGz-IvgaSUoc" |
| 7 | +bot = telebot.TeleBot(API_Key ) |
| 8 | + |
| 9 | +# print("going") |
| 10 | + |
| 11 | +# @bot.message_handler(commands=['checkroom']) |
| 12 | + |
| 13 | +# def greet(message): |
| 14 | +# # range 1 - 3 |
| 15 | +number_of_people = 1 |
| 16 | + |
| 17 | +def get_room_inventory(arrangement_id): |
| 18 | + # Define the API URL |
| 19 | + url = f"https://rwcruises.partner.flickket.com/v1/usrcsrv/arrangements/{arrangement_id}/units?translation=false&preview=0" |
| 20 | + |
| 21 | + # Make the HTTP request |
| 22 | + headers = { |
| 23 | + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" |
| 24 | + } |
| 25 | + |
| 26 | + response = requests.get(url, headers=headers) |
| 27 | + |
| 28 | + # Check if the request was successful |
| 29 | + if response.status_code == 200: |
| 30 | + data = response.json() |
| 31 | + inventories = data["result"]["inventories"] |
| 32 | + |
| 33 | + # Initialize inventory values |
| 34 | + balcony_stateroom_inventory = 0 |
| 35 | + balcony_deluxe_stateroom_inventory = 0 |
| 36 | + |
| 37 | + # Find the inventory for "Balcony Stateroom" and "Balcony Deluxe Stateroom" |
| 38 | + for price in data["result"]["prices"]: |
| 39 | + # print(price) |
| 40 | + if price["name"] == "Balcony Stateroom": |
| 41 | + inventory_id = str(price["inventory_id"]) |
| 42 | + if inventory_id in inventories: |
| 43 | + balcony_stateroom_inventory = inventories[inventory_id] |
| 44 | + elif price["name"] == "Balcony Deluxe Stateroom": |
| 45 | + inventory_id = str(price["inventory_id"]) |
| 46 | + if inventory_id in inventories: |
| 47 | + balcony_deluxe_stateroom_inventory = inventories[inventory_id] |
| 48 | + # print(inventories[inventory_id]) |
| 49 | + |
| 50 | + # Create a dictionary with the inventory values |
| 51 | + # room_inventory = { |
| 52 | + # "Balcony Stateroom": balcony_stateroom_inventory, |
| 53 | + # "Balcony Deluxe Stateroom": balcony_deluxe_stateroom_inventory |
| 54 | + # } |
| 55 | + # print(room_inventory) |
| 56 | + return f'Bal : {balcony_stateroom_inventory} | Bal Del {balcony_deluxe_stateroom_inventory}' |
| 57 | + |
| 58 | + else: |
| 59 | + print(f"Failed to retrieve data for Arrangement ID {arrangement_id}. Status code: {response.status_code}") |
| 60 | + return None |
| 61 | + |
| 62 | +phucket_dict = { |
| 63 | + 1 : 319833, |
| 64 | + 2 : 319837, |
| 65 | + 3 : 319840 |
| 66 | +} |
| 67 | +penang_dict = { |
| 68 | + 1: 319797, |
| 69 | + 2: 319801, |
| 70 | + 3: 319821, |
| 71 | +} |
| 72 | + |
| 73 | +friday_dict={ |
| 74 | + 1:319760 |
| 75 | +} |
| 76 | + |
| 77 | +wednesday_dict={ |
| 78 | + 1:319744 |
| 79 | +} |
| 80 | + |
| 81 | +loc_dict = { |
| 82 | + "Penang" : penang_dict, |
| 83 | + "Phucket": phucket_dict, |
| 84 | + "Wednesday": wednesday_dict, |
| 85 | + "Friday" : friday_dict |
| 86 | +} |
| 87 | +res = "" |
| 88 | +for i in ["Penang","Phucket","Wednesday","Friday"]: |
| 89 | + package_id = loc_dict[i][number_of_people] |
| 90 | + |
| 91 | + url = f'https://rwcruises.partner.flickket.com/v1/experiencesrv/packages/schedule_service/get_schedules_and_units?translation=false&package_id={package_id}&preview=0' |
| 92 | + |
| 93 | + headers = { |
| 94 | + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" |
| 95 | + } |
| 96 | + |
| 97 | + response = requests.get(url, headers=headers) |
| 98 | + res += f'{i}\n' |
| 99 | + |
| 100 | + # Check if the request was successful |
| 101 | + if response.status_code == 200: |
| 102 | + data = response.json() |
| 103 | + # print(data["result"]["schedules"]) |
| 104 | + for item in data["result"]["schedules"]: |
| 105 | + res += f'{item["date"]} : {get_room_inventory(item["time_slots"][0]["arrangement_id"])}\n' |
| 106 | + |
| 107 | + |
| 108 | +send_url = 'https://api.telegram.org/bot6453714074:AAEJFCtoIRzxkBtoKF1H2ExlGz-IvgaSUoc/sendmessage?chat_id=-4067239998&text="{}"'.format(res) |
| 109 | +# print(send_url) |
| 110 | +requests.get(send_url) |
| 111 | +print("sent") |
0 commit comments