Beispiel #1
0
class CurrentLiveStream(QWebEngineView):
    config: ConfigFunctions = None
    url: QUrl = None

    def __init__(self, parent: QWidget = None, resort: str = None):
        super(CurrentLiveStream, self).__init__(parent)
        self.config = ConfigFunctions()
        self.url = QUrl(self.config.get_stream_path(resort_name=resort))
        self.initUI(parent=parent)

    def initUI(self, parent: QWidget):
        self.setFixedWidth(self.config.get_width() * 0.7)
        self.setFixedHeight(parent.height())
        self.load(self.url)
        self.triggerPageAction(QWebEnginePage.ReloadAndBypassCache)
Beispiel #2
0
class ResortMasterList(object):
    conf: ConfigFunctions = None
    resorts: list = None
    cur_index: int = 0
    num_resorts: int = 0

    def __init__(self):
        self.conf = ConfigFunctions()
        self.resorts = self.conf.get_list_of_resorts()
        self.num_resorts = len(self.resorts)

    def get_next_resort(self):
        self.cur_index = (self.cur_index + 1) % self.num_resorts
        return self.resorts[self.cur_index]

    def get_previous_resort(self):
        self.cur_index = (self.cur_index - 1) % self.num_resorts
        return self.resorts[self.cur_index]

    def get_resort_at_index(self, index: int):
        self.cur_index = index
        return self.resorts[index]

    def get_current_index(self):
        return self.cur_index

    def get_resort_amount(self):
        return self.num_resorts
Beispiel #3
0
class BaseMainWindow(QMainWindow):
    layout: QVBoxLayout = None
    config: ConfigFunctions = None

    def __init__(self, parent=None):
        super(BaseMainWindow, self).__init__(parent)
        self.config = ConfigFunctions()
        self.set_base_ui()

    def set_base_ui(self):
        self.layout = QVBoxLayout()
        self.setFixedHeight(self.config.get_height())
        self.setFixedWidth(self.config.get_width())
        self.layout.setContentsMargins(0, 0, 0, 0)

    def keyPressEvent(self, e):
        if e.key() == Qt.Key_Escape:
            self.close()
class CurrentTemp(QLabel):
    config: ConfigFunctions = None

    def __init__(self, parent=None, cur_temp=''):
        super(CurrentTemp, self).__init__(parent)
        self.config = ConfigFunctions()
        self.initUI(cur_temp=cur_temp)

    def initUI(self, cur_temp):
        self.setText(cur_temp)
        self.setObjectName('curWeatherTemp')
        self.setFixedHeight(int(self.config.get_height() * 0.22))
        self.setStyleSheet(load_stylesheet('weather_table.qss'))
Beispiel #5
0
 def __init__(self):
     self.conf = ConfigFunctions()
     self.resorts = self.conf.get_list_of_resorts()
     self.num_resorts = len(self.resorts)
 def __init__(self, parent=None, cur_temp=''):
     super(CurrentTemp, self).__init__(parent)
     self.config = ConfigFunctions()
     self.initUI(cur_temp=cur_temp)
Beispiel #7
0
from time import sleep
from src.backend.config import ConfigFunctions
from datetime import datetime, timezone
from requests import get
from shutil import copyfileobj
from pathlib import Path
from os.path import sep
from os import getcwd
from re import sub
import dateutil.parser

config = ConfigFunctions()
BASE_WEATHER_URL = config.get_weather_url()


def get_weather_info_from_api(resort_name, num_days=5):
    latitude, longitude = config.get_resort_coordinates(resort_name)
    resort_gps_url = "".join([BASE_WEATHER_URL, latitude, ",", longitude])
    while True:
        response = get(resort_gps_url)
        if response.status_code == 200:
            break
        sleep(5)  # wait for api to come back online
    res_dict = get(resort_gps_url).json()
    forecast_url = res_dict.get('properties', {}).get('forecast', None)
    if forecast_url:
        forecast = get(forecast_url).json()
        return _format_weather(forecast.get('properties', {}), num_days)
    return "error"  # TODO raise exception

Beispiel #8
0
from PyQt5.QtWidgets import QApplication
from sys import argv
from src.backend.config import ConfigFunctions
from src.backend.threading_functions import cntdown_timer
from src.resources.main_app import MainWindow
from src.db.db_daemon import db_weather_daemon, db_travel_daemon
from threading import Thread

if __name__ == '__main__':
    config = ConfigFunctions()
    db_travel_watcher = Thread(target=db_travel_daemon,
                               args=(config.get_db_path(), ),
                               daemon=True)
    db_travel_watcher.start()
    db_weather_watcher = Thread(target=db_weather_daemon,
                                args=(config.get_db_path(), ),
                                daemon=True)
    db_weather_watcher.start()
    argv.append("--disable-web-security")
    app = QApplication(argv)
    window = MainWindow()
    window.setWindowTitle('Vacation Planning Assistant')
    window.show()
    timer = Thread(target=cntdown_timer, args=(window, ), daemon=True)
    timer.start()
    app.exec_()
Beispiel #9
0
 def __init__(self, source=None):
     self.config = ConfigFunctions()
     self.source = source
     self.helpers = DbHelpers()
     self.set_up_connection()
Beispiel #10
0
 def __init__(self, parent: QWidget = None, resort: str = None):
     super(CurrentLiveStream, self).__init__(parent)
     self.config = ConfigFunctions()
     self.url = QUrl(self.config.get_stream_path(resort_name=resort))
     self.initUI(parent=parent)
Beispiel #11
0
 def __init__(self, parent=None):
     super(BaseVContainer, self).__init__(parent)
     self.config = ConfigFunctions()
     self.layout = QVBoxLayout()
     self.layout.setContentsMargins(0, 0, 0, 0)
     self.setLayout(self.layout)
Beispiel #12
0
 def __init__(self, parent=None):
     super(BaseMainWindow, self).__init__(parent)
     self.config = ConfigFunctions()
     self.set_base_ui()
 def setUp(self) -> None:
     self.config_obj = ConfigFunctions(test_environ=True)
     self.cwd = getcwd()
class TestConfigReturnValues(unittest.TestCase):
    config_obj: ConfigFunctions = None
    cwd: str = None

    def setUp(self) -> None:
        self.config_obj = ConfigFunctions(test_environ=True)
        self.cwd = getcwd()

    def test_config_field_values(self):
        self.assertEqual(
            self.config_obj.conf_file_path,
            self.cwd + sep + 'test' + sep + 'conf' + sep + 'tst_config.yaml')
        self.assertEqual(
            self.config_obj.secrets_file_path,
            self.cwd + sep + 'test' + sep + 'conf' + sep + 'tst_secrets.yaml')

    def test_maps_key(self):
        self.assertEqual(self.config_obj.get_maps_key(), 'test_google_maps')

    def test_amadeus_keys(self):
        keys = self.config_obj.get_amadeus_keys()
        self.assertEqual(len(keys), 2)
        self.assertEqual(keys[0], 'test_amadeus_key')
        self.assertEqual(keys[1], 'test_amadeus_secret')

    def test_weather_url(self):
        self.assertEqual(self.config_obj.get_weather_url(),
                         'https://api.weather.gov/points/')

    def test_origin_coordinates(self):
        coordinates = self.config_obj.get_origin_coordinates()
        self.assertEqual(len(coordinates), 2)
        self.assertEqual(coordinates[0], '100.100')
        self.assertEqual(coordinates[1], '-200.200')

    def test_get_resort_driving(self):
        self.assertFalse(
            self.config_obj.get_resort_driving(resort_name='steamboat'))
        self.assertTrue(
            self.config_obj.get_resort_driving(resort_name='killington'))

    def test_resort_info_gets(self):
        res_coords = self.config_obj.get_resort_coordinates(
            resort_name='steamboat')
        prefs_steamboat = self.config_obj.get_resort_airport_prefs(
            resort_name='steamboat')
        resort_list = self.config_obj.get_list_of_resorts()
        self.assertEqual(len(prefs_steamboat), 2)
        self.assertEqual(prefs_steamboat[0], 'HDN')
        self.assertFalse(prefs_steamboat[1])
        self.assertEqual(len(res_coords), 2)
        self.assertEqual(res_coords[0], '667')
        self.assertEqual(res_coords[1], '-667')
        self.assertIn('steamboat', resort_list)
        self.assertIn('killington', resort_list)
        self.assertEqual(
            self.config_obj.get_resort_proper_name(resort_name='steamboat'),
            'Steamboat Springs')

    def test_get_airline_prefs(self):
        self.assertEqual(self.config_obj.get_airlines_pref(), 'WN')
        self.assertEqual(self.config_obj.get_origin_airport(), 'NYC')

    def test_get_height_width(self):
        self.assertEqual(self.config_obj.get_width(), 1600)
        self.assertEqual(self.config_obj.get_height(), 960)

    def test_get_db(self):
        self.assertEqual(self.config_obj.get_db_path(), 'test_db.db')

    def test_get_stream_path(self):
        self.assertEqual(
            self.config_obj.get_stream_path(resort_name='killington'),
            'test_url2')

    def test_hidden_config_functions(self):
        config = self.config_obj._get_config()
        secrets = self.config_obj._get_secrets()
        resorts = self.config_obj._get_resorts()
        resort = self.config_obj._get_individual_resort(
            resort_name='killington')
        self.assertEqual(type(config), dict)
        self.assertNotEqual(len(config), 0)
        self.assertEqual(type(secrets), dict)
        self.assertNotEqual(len(secrets), 0)
        self.assertEqual(type(resort), dict)
        self.assertNotEqual(len(resort), 0)
        self.assertEqual(type(resorts), dict)
        self.assertGreater(len(resorts), 1)
from amadeus import Client as amadeus_Client
from src.backend.config import ConfigFunctions
from googlemaps import Client as gmaps_Client
from datetime import timedelta, date
from pprint import pprint

config = ConfigFunctions()


def get_driving_to_resort_data_from_api(resort):
    cli = _get_gmaps_client()
    resort_lat, resort_lon = config.get_resort_coordinates(resort)
    origin_lat, origin_lon = config.get_origin_coordinates()
    res = cli.directions(origin=''.join([origin_lat, ',', origin_lon]),
                         destination=''.join([resort_lat, ',', resort_lon]),
                         units='imperial')
    return {'distance': _get_drive_distance(res), 'time': _get_drive_time(res)}


def get_flying_to_resort_data_from_api(resort):
    prefs = _get_flight_prefs(resort)
    flights_list = _in_two_weekends_flights(prefs)
    print(flights_list)  # TODO - change to logging
    return flights_list


def _get_common_flight_info(segments):
    massaged_segments = []
    for seg in segments:
        flight_info = seg.get('flightSegment')
        flight_departs = flight_info.get('departure').get('at')