Ejemplo n.º 1
0
    def __init__(self):
        self.app = gui("Youtube to mp3 converter", "550x230")
        self.app.setResizable(canResize=True)
        self.app.setOnTop(stay=True)
        self.app.startFrame("LEFT", row=0, column=0)
        self.app.setBg("#4EC5C1")
        self.app.setFont(15)

        self.app.addLabel("url_label", "Insert Youtube url:", 0, 0)
        self.app.addValidationEntry("url_value", 0, 1)
        self.app.setFocus("url_value")
        self.app.setEntryMaxLength("url_value", 80)
        self.app.setEntryFg("url_value", "#000000")
        self.app.setEntryDefault("url_value", "https://www.youtube.com/...")

        self.app.addButtons(["Download", "Cancel"], self.press, 2, 0, 2)
        self.app.setButtonState("Download", "normal")
        self.app.setButtonState("Cancel", "normal")
        self.app.setButtonRelief("Download", "groove")
        self.app.setButtonRelief("Cancel", "groove")

        # Return default user's download path for Linux, macOS or Windows
        self.app.save_dir = get_download_path()

        self.dl = self.create_downloader()

        # add status bar on the bottom of the window
        self.app.addStatusbar(fields=1)
        self.app.setStatusbarBg("#000000", 0)
        # every second check the status of Download and update the status bar
        self.app.registerEvent(self.update_status)

        self.app.go()
Ejemplo n.º 2
0
 def __init__(self, serfile_list: List[SerfFile]):
     self.serfile_list = serfile_list
     self.file_order = [
         'state', 'market', 'carrier', 'company', 'effective_date',
         'status', 'file_type', 'file_number'
     ]
     self.wd = get_download_path()
Ejemplo n.º 3
0
def download_file_from_drive():
    extension_type = get_extension_types()
    mime_type_of_folder = 'application/vnd.google-apps.folder'

    creds = get_credential()
    service = get_drive_service(creds)
    items = get_drive_file_names(creds)
    for item in items:
        print('\nInitiating download of file: %s\n' % item['name'])
        file_name = item['name']
        file_id = item['id']
        file_mime_type = item['mimeType']

        if file_mime_type != mime_type_of_folder:
            if file_mime_type not in extension_type:
                request = call_get_media_api(service, file_id)
            else:
                request = call_export_api(service, file_id, extension_type,
                                          file_mime_type)

            download_path = get_download_path()
            fh = io.FileIO(join(download_path, file_name), 'wb')
            downloader = MediaIoBaseDownload(fh, request)
            done = False
            while done is False:
                try:
                    status, done = downloader.next_chunk()
                    print("==========Download %d%%.==========" %
                          int(status.progress() * 100))
                except errors.HttpError as error:
                    print("An error occurred: %s" % error)
    return True, "Success"
Ejemplo n.º 4
0
    def __get_paths():
        download_path = get_download_path()
        paths = sorted(Path(download_path).iterdir(), key=os.path.getmtime)

        # exclude the folders
        paths = [p for p in paths if '.' in str(p)]
        # print(len(paths), len(self.serfiles))
        return paths
Ejemplo n.º 5
0
    def __init__(self):
        url = 'https://interactive.web.insurance.ca.gov/apex_extprd/f?p=102:InteractiveReport:0::NO:4,RIR::'
        super().__init__(url)
        self.__initial_setup()

        self.filing_urls = []

        self.file_tracker = FileTracker()
        # self.file_tracker.wipe_download_records()

        self.num_downloads = len(os.listdir(get_download_path()))
Ejemplo n.º 6
0
    def __init__(self):
        url = 'https://myportal.dfs.ny.gov/web/prior-approval/rate-applications-by-company'
        super().__init__(url)
        self.__set_submission_date()

        self.row_urls = []
        self.filing_urls = []

        self.file_tracker = FileTracker()
        self.file_tracker.wipe_download_records()

        self.num_downloads = len(os.listdir(get_download_path()))
Ejemplo n.º 7
0
 def rename_serfiles_filenames(self):
     download_path = get_download_path()
     paths = [
         os.path.join(download_path, p) for p in os.listdir(download_path)
         if '.' in str(p)
     ]
     print(len(paths), len(self.serfiles))
     if len(paths) > 0:
         for i, x in enumerate(paths):
             path = str(paths[i])
             file_name = path[path.rfind('/') + 1:]
             self.serfiles[i].data_dict['file_name'] = file_name
Ejemplo n.º 8
0
    def __init__(self):
        url = 'http://wpso.dmhc.ca.gov/premiumratereview/FilingList.aspx'
        super().__init__(url)
        self.__initial_setup()

        self.filing_urls = []

        # self.carrier_matcher = CarrierMatcher()
        self.file_tracker = FileTracker()

        # remove for deployment
        # self.file_tracker.wipe_download_records()

        self.num_downloads = len(os.listdir(get_download_path()))
Ejemplo n.º 9
0
    def __wait_for_download(self):
        files_downloaded = False

        for i in range(8):
            curr_num_downloads = len(os.listdir(get_download_path()))
            if curr_num_downloads > self.num_downloads:
                self.num_downloads = curr_num_downloads
                files_downloaded = True
                break
            else:
                time.sleep(5)

        if files_downloaded == False: raise Exception("File not downloading!")
        else: pass
Ejemplo n.º 10
0
    def __init__(self, url):
        super().__init__(url)
        print("running for url: ", url)
        self.__initial_setup()

        self.num_pages = None
        self.no_more_rows = False

        self.carrier_matcher = CarrierMatcher()
        self.file_tracker = FileTracker()

        # self.file_tracker.wipe_download_records()

        self.num_downloads = len(os.listdir(get_download_path()))
Ejemplo n.º 11
0
    def move_old_dl_files(self):
        download_path = get_download_path()
        dl_files = os.listdir(download_path)

        if dl_files == ['Moved_Downloads_Content']:
            pass
        elif len(dl_files) > 0:
            dl_storage = os.path.join(download_path, 'Moved_Downloads_Content')
            if 'Moved_Downloads_Content' not in dl_files:
                create_folder(dl_storage)
            move_files_to_folder(download_path, dl_storage)
            print("Moved old files into folder: 'Moved_Downloads_Content'")

        else:
            print("Thank you for emptying the downloads folder.")
Ejemplo n.º 12
0
    def __gather_base_data(self) -> dict:

        filing_nbr_select = '#filingNo'
        plan_name_select = '#healthPlanName'
        filing_type_select = '#filingType'
        market_select = '#marketType'
        status_select = '#filingStatus'
        effective_date_select = '#dtEffective'

        filing_number = self.wait_for_and_find(filing_nbr_select).text
        plan_name_str = self.wait_for_and_find(plan_name_select).text
        file_type = self.wait_for_and_find(filing_type_select).text
        market = self.wait_for_and_find(market_select).text
        status = self.wait_for_and_find(status_select).text
        effective_date = self.wait_for_and_find(effective_date_select).text
        effective_date = standard_date_str(effective_date)

        state = 'CA_dmhc'
        carrier = self.__get_carrier(plan_name_str)
        company = self.__get_company(plan_name_str)
        current_path = get_download_path()

        base_data_dict = {
            'state': state,
            'carrier': carrier,
            'company': company,
            'market': market,
            'status': status,
            'effective_date': effective_date,
            'file_type': file_type,
            'current_path': current_path,
            'file_number': filing_number,
            'file_name': ''
        }

        return base_data_dict
Ejemplo n.º 13
0
    def loadSettings(self):
        # set window pos and size
        self._window_size = self._settings.value('gmMainWindowSize', defaultValue=self.size())
        self._window_pos = self._settings.value('gmMainWindowPos', defaultValue=None)
        self._maximize_window = self._settings.value('gmMainWindowMaximized', defaultValue=False)

        # set theme
        theme_value = self._settings.value('gmTheme', defaultValue='light')

        if theme_value.lower() == 'dark':
            self.ui.actionDarkTheme.setChecked(True)

        # set initial dir and file explore paths
        self._explore_path = self._settings.value('gmExplorePath', defaultValue=get_download_path())

        # set tool sizes
        self.ui.pageViewer.setPenSize(self._settings.value('gmPenSize', defaultValue=5))
        self.ui.pageViewer.setEraserSize(self._settings.value('gmEraserSize', defaultValue=100))

        # conditionally show welcome tab
        self._show_welcome_tab = self._settings.value('gmShowWelcomeTab', defaultValue=True)

        if self._show_welcome_tab:
            self.showWelcomeTab()
Ejemplo n.º 14
0
    def __gather_base_data(self):

        company_name_select = '#R34739679176854560_heading'
        filing_nbr_select = '#generalfilingdetails > table > tbody > tr:nth-child(2) > td'
        market_select = '#generalfilingdetails > table > tbody > tr:nth-child(1) > td'
        effective_date_select = '#generalfilingdetails > table > tbody > tr:nth-child(6) > td'
        status_select = '#container > table > tbody > tr > td'

        company_name_str = self.wait_for_and_find(company_name_select).text
        filing_number = self.wait_for_and_find(filing_nbr_select).text
        file_type = 'Rate Filing'
        market = self.wait_for_and_find(market_select).text
        effective_date = self.wait_for_and_find(effective_date_select).text
        effective_date = standard_date_str(effective_date)
        status_str = self.wait_for_and_find(status_select).text

        state = 'CA_cdi'
        carrier = self.__get_carrier(company_name_str)
        company = company_name_str
        current_path = get_download_path()
        status = status_str

        base_data_dict = {
            'state': state,
            'carrier': carrier,
            'company': company,
            'market': market,
            'status': status,
            'effective_date': effective_date,
            'file_type': file_type,
            'current_path': current_path,
            'file_number': filing_number,
            'file_name': ''
        }

        return base_data_dict
Ejemplo n.º 15
0
 def test_with_default_path(self):
     path = get_download_path()
     assert path == '/google_drive_api/src/downloads'
Ejemplo n.º 16
0
    def __gather_row_info(self, i) -> (bool, dict):
        """
        

        Parameters
        ----------
        i : TYPE
            DESCRIPTION.

        Returns
        -------
        bool, dict
            DESCRIPTION.

        """

        company_path = f'//*[@id="j_idt25:filingTable_data"]/tr[{i}]/td[1]'
        prod_name_path = f'//*[@id="j_idt25:filingTable_data"]/tr[{i}]/td[3]'
        sub_type_path = f'//*[@id="j_idt25:filingTable_data"]/tr[{i}]/td[4]'
        filing_type_path = f'//*[@id="j_idt25:filingTable_data"]/tr[{i}]/td[5]'
        filing_status_path = f'//*[@id="j_idt25:filingTable_data"]/tr[{i}]/td[6]'
        tracking_number_path = f'//*[@id="j_idt25:filingTable_data"]/tr[{i}]/td[7]'

        company = self.wait_for_and_find(company_path,
                                         tag_type='xpath',
                                         wait_time=60).text
        carrier = self.carrier_matcher.match_to_carrier(company)

        product_name_str = self.wait_for_and_find(prod_name_path,
                                                  tag_type='xpath').text
        sub_type_str = self.wait_for_and_find(sub_type_path,
                                              tag_type='xpath').text
        is_valid_product, market = self.__valid_product(
            product_name_str, sub_type_str)

        status_str = self.wait_for_and_find(filing_status_path,
                                            tag_type='xpath').text
        is_valid_status = self.__valid_status(status_str)
        status = status_str

        file_type = self.wait_for_and_find(filing_type_path,
                                           tag_type='xpath').text
        file_name = self.wait_for_and_find(tracking_number_path,
                                           tag_type='xpath').text

        current_path = get_download_path()

        effective_date = self.get_effective_date(
            self.wait_for_and_find(prod_name_path, tag_type='xpath').text)
        # effective_date = self.__effective_date

        data_dict = {
            'state': self.state,
            'carrier': carrier,
            'company': company,
            'market': market,
            'status': status,
            'effective_date': effective_date,
            'file_type': file_type,
            'current_path': current_path,
            'file_number': file_name,
            'file_name': file_name + '.zip',
        }

        if is_valid_product and is_valid_status:
            print("valid row")
            return True, data_dict,
        else:
            return False, {}
Ejemplo n.º 17
0
 def test_with_valid_environ_path(self, monkeypatch):
     valid_path = os.getcwd()
     envs = {'download_path': valid_path}
     monkeypatch.setattr(os, 'environ', envs)
     path = get_download_path()
     assert path == valid_path
Ejemplo n.º 18
0
 def test_with_invalid_environ_path(self, monkeypatch):
     invalid_path = ''
     envs = {'download_path': invalid_path}
     monkeypatch.setattr(os, 'environ', envs)
     path = get_download_path()
     assert path == '/google_drive_api/src/downloads'
Ejemplo n.º 19
0
 def test_oserror_while_path_creation(self,
                                      mocked_create_download_path):
     mocked_create_download_path.side_effect = OSError
     with pytest.raises(OSError):
         get_download_path()
Ejemplo n.º 20
0
 def test_create_download_path_is_called(self,
                                         mocked_create_download_path):
     mocked_create_download_path.return_value = '/google_drive_api/src/downloads'
     get_download_path()
     mocked_create_download_path.assert_called_once_with(
         '/google_drive_api/src/downloads')