#!/usr/bin/env python from amazon_price_checker import AmazonPriceChecker from notification_manager import NotificationManager from item_info import ItemInfo notification = NotificationManager() apc = AmazonPriceChecker() apc.add_item( ItemInfo( item_id="B078MGXLVS", threshold_price=70.00, # normal price = 69.99 description="Blue Radius III Custom Shockmount", )) apc.add_item( ItemInfo( item_id="B078MLBGRM", threshold_price=140.00, # normal price = 139.00 description="Blue Compass Premium Tube-Style Broadcast Boom Arm", )) apc.get_all_item_price() cheap_items = apc.get_cheap_items() for item in cheap_items: message = (f"{item.description} is priced at ${item.actual_price:.2f}, " f"which is below our threshold of ${item.threshold_price:.2f}\n" f"URL: {item.url}") notification.send_email(message=message)
new_price = search_results["price"] fly_from = search_results["route"][0]["cityFrom"] fly_to = search_results["route"][0]["cityTo"] departure_iata = search_results["route"][0]["flyFrom"] arrival_iata = search_results["route"][0]["flyTo"] departure_date = search_results["route"][0]["local_departure"].split( "T")[0] arrival_date = search_results["route"][0]["local_arrival"].split( "T")[0] except TypeError: # If the data returned is None continue else: # Update the lowest price column and send an email if new_price < current_price: data_manager.update_sheet( row_id=row_id, params={"price": { "lowestPrice (inRupees)": new_price }}) for user_row in data_manager.users: email = user_row["email"] notification_manager.send_email(price=new_price, fly_from=fly_from, fly_to=fly_to, departure_iata=departure_iata, arrival_iata=arrival_iata, departure_date=departure_date, arrival_date=arrival_date, to_addrs=email)
from notification_manager import NotificationManager import os from web_scraper import WebScraper keyvault_url = os.environ.get('KEYVAULT_URL') credential = DefaultAzureCredential() kv_client = SecretClient(keyvault_url, credential) MY_EMAIL = kv_client.get_secret('fake-email').value PASSWORD = kv_client.get_secret('fake-email-password').value TARGET_EMAIL = kv_client.get_secret('target-email').value target_product = input("Please enter the full url of the product you wish to search: ") preferred_price = float(input("Please enter your target price: ").strip('$')) scraper = WebScraper() product_dict = scraper.retrieve_price_from_site(target_product, preferred_price) data_manager = DataManager(product_dict) data_manager.check_if_item_in_data_file() products_to_buy = data_manager.check_if_price_below_target() notification_manager = NotificationManager(MY_EMAIL, PASSWORD) notification_manager.send_email(products_to_buy, TARGET_EMAIL)
data["iataCode"]: { "id": data["id"], "city": data["city"], "price": data["lowestPrice"] } for data in sheet_data } tomorrow = datetime.now() + timedelta(days=1) six_month_from_today = datetime.now() + timedelta(days=(6 * 30)) for destination_code in destinations: flight = flight_search.check_flights(ORIGIN_CITY_IATA, destination_code, from_time=tomorrow, to_time=six_month_from_today) if flight is None: continue if flight.price < destinations[destination_code]["price"]: message=f"Low price alert! Only CDN${flight.price} to fly from {flight.origin_city}-{flight.origin_airport} to " \ f"{flight.destination_city}-{flight.destination_airport}, from {flight.out_date} to {flight.return_date}." \ f"{GOOGLE_FLIGHT_ENDPOINT}?hl=en#flt={flight.origin_airport}.{flight.destination_airport}.{flight.out_date}*{flight.destination_airport}.{flight.origin_airport}.{flight.return_date}" if flight.stop_overs > 0: message += f"\nFlight has {flight.stop_overs} stop over, via {flight.via_city}." print(message) notification_manager.send_sms(message) notification_manager.send_email(message)
sheety_data = DataManager() user_data = sheety_data.get_user_email() for city in sheety_data.data: # get IATA code iata_code = flight.search_city(city["city"]) lowest_price = city["lowestPrice"] # put IATA code to sheety if city["iataCode"] == "": sheety_data.put_data(iata_code, city["id"]) # search lowest price for user in user_data: email_content = flight.search_flight(iata_code, lowest_price) if email_content: send_message.send_email(email_content[0], email_content[1], user["email"]) # for testing # print(flight.search_city("Paris")) # flight.search_flight("KUL", 414) # input user info # print("Welcome to Blaze's Flight Club.\nWe find the best flight deals and email you.") # first = input("What is your first name?\n") # last = input("What is your last name?\n") # email = input("What is your email?\n") # email_check = input("Type your email again.\n") # if email == email_check: # sheety_user_data.post_user(first, last, email) # print("You're in the club!") # else:
# data_manager.update_sheet(data['id'], flight_search.city) notification = NotificationManager() for data in sheet_data: try: price = flight_data.api_call(data['iataCode']) for lowest in price: # print(lowest['cityTo']) if data['lowestPrice'] > lowest['price']: for email in data_email: notification.send_email(email['email'], f"Low price alert! Only ${lowest['price']} to fly from " f"{lowest['cityFrom']}-{lowest['flyFrom']}" f" to {lowest['cityTo']}-{lowest['flyTo']}" f" from {datetime.now().date()} to " f"{lowest['utc_departure'].split('T')[0]}" ) break except KeyError: continue # notification.send_message( # f"Low price alert! Only ${lowest['price']} to fly from " # f"{lowest['cityFrom']}-{lowest['flyFrom']}" # f" to {lowest['cityTo']}-{lowest['flyTo']}" # f" from {datetime.now().date()} to " # f"{lowest['utc_departure'].split('T')[0]}" # )
data_manager.put_data() # Getting todays date and price for next 6 month using timedelta function tomorrow = datetime.now() + timedelta(days=1) next_6_month = datetime.now() + timedelta(days=(6 * 30)) # This will pass each city iata and time to search flight_fuction for city in return_data: flight = flight_search.search_flight( ORIGIN_CITY_IATA, city["iataCode"], from_time=tomorrow, to_time=next_6_month ) # if flight_search return none then this will just pass if flight is None: pass # else this will go ahead and compare current price of ticket and all time low price which # we stored in google sheet else: # its matches then it will send an email to all the emails in our user_data google sheet if flight.price < city["lowestPrice"]: send_notification.send_email(city["city"])
from data_manager import DataManager from flight_search import FlightSearch from notification_manager import NotificationManager ORIGIN = "NBO" # Populate Google sheet copy flight_sheet = DataManager() sheet_data = flight_sheet.get_sheet_data() # Get IATA code flight_search = FlightSearch() for row in sheet_data: if row['iataCode'] == "": row['iataCode'] = flight_search.get_iata_code(row['city']) # Update IATA code on google sheet flight_sheet.update_sheet_data() # Get cheap flights for row in sheet_data: flights = flight_search.get_flight_details(ORIGIN, row['iataCode']) if flights and flights.price <= row['lowestPrice']: notification = NotificationManager(flights.price, ORIGIN, flights.source_airport, flights.dest_city, flights.dest_airport) notification.send_email() else: continue
emails = data_manager.get_emails() ORIGIN_CITY_IATA = "LON" if sheet_data[0]["iataCode"] == "": for row in sheet_data: row["iataCode"] = flight_search.get_destination_code(row["city"]) data_manager.destination_data = sheet_data data_manager.update_destination_codes() tomorrow = datetime.now() + timedelta(days=1) six_month_from_today = datetime.now() + timedelta(days=(6 * 30)) for destination in sheet_data: flight = flight_search.check_flights(ORIGIN_CITY_IATA, destination["iataCode"], from_time=tomorrow, to_time=six_month_from_today) if flight and flight.price < destination["lowestPrice"]: message = f"Low price alert!" \ f" Only £{flight.price} to fly from {flight.origin_city}-{flight.origin_airport}" \ f" to {flight.destination_city}-{flight.destination_airport}, from {flight.out_date}" \ f" to {flight.return_date}: https://www.google.co.uk/flights?hl=en#flt={ORIGIN_CITY_IATA}.{destination['iataCode']}.{flight.out_date}*{destination['iataCode']}.{ORIGIN_CITY_IATA}.{flight.return_date}\n" if flight.stop_overs > 0: message += f"Flight has {flight.stop_overs} stop over, via {flight.via_city}" notification_manager.send_sms(message=message) notification_manager.send_email(message=message, emails=emails)
cities = [each['iataCode'] for each in data['prices']] for city in cities: print(city) try: flights = flight.search(fly_from='SYD', fly_to=city, date_from='05/01/2021', date_to='05/01/2021') curr_price = [ item for item in data['prices'] if item['iataCode'] == city ] loc_id = curr_price[0]['id'] loc_min = curr_price[0]['lowestPrice'] prices = [] for each in flights: prices.append(each['price']) min_price = min(prices) if min_price < loc_min: e_message = f"Low Price Alert!\nOnly ${min_price} from SYD to {city}" notify.send_email(e_message, emails) except ValueError as e: continue except KeyError as e: continue # message = f"Low Price Alert!\nOnly ${min_price} from SYD to {city}" # notify.send_sms(message) # print("Sent SMS") sheety.update_data(loc_id, min_price)
data = flight_data.data(city_codes) min_prices = data["prices"] out_date = data["out date"] return_date = data["return date"] # find original price of flights orig_prices = flight_data.orig_prices() # if min price < orig price send alert alert_city_num = [ num for num in range(len(min_prices)) if min_prices[num] < orig_prices[num] ] email_data = sheety_data.email_data()["users"] emails = [da["email"] for da in email_data] for num in alert_city_num: flight_city = cities[num] flight_code = city_codes[num] cost = min_prices[num] out = out_date[num] ret = return_date[num] # notif.send_alert(cost, flight_city, flight_code, out, ret) for email in emails: notif.send_email(city=flight_city, code=flight_code, out=out, ret=ret, to_email=email, price=cost)