Exemplo n.º 1
0
    def get_credentials(self):

        client_secrets = self.credential_storage + self.user + ".json"

        if not os.path.isfile(client_secrets):
            print "Failed to load client_secret in cache. Going to get new"
            utils.write_string_to_file(client_secrets, self.get_client_secret())

        scope = "https://picasaweb.google.com/data/"
        # get from mongo and dumps to file
        flow = flow_from_clientsecrets(client_secrets, scope=scope, redirect_uri="urn:ietf:wg:oauth:2.0:oob")
        uri = flow.step1_get_authorize_url()

        print "Getting credentials token"
        browser = webdriver.Firefox()
        self._basic_login(browser, uri)

        wait_for_element_visible(browser, By.ID, "submit_approve_access")
        time.sleep(3)
        k = browser.find_element_by_id("submit_approve_access")
        k.click()

        wait_for_element_visible(browser, By.ID, "code")
        code = browser.find_element_by_id("code").get_attribute("value").encode("utf-8")

        credentials = flow.step2_exchange(code)

        browser.quit()
        return credentials
Exemplo n.º 2
0
    def get_multi_story_information(self, keyword, file_path=None):
        """
        :param keyword:  NewestChapter | StoryStatusHashValue | QAHashValue
        :param file_path:
        :return:
        """
        result = dict()

        target_cell = self.find_tagged_cell(keyword)
        flag_cell = self.find_tagged_cell("StoryNameHashValue")
        last_row = self.find_tagged_cell("StoryNameLastRow").value

        target_result = list(self._get_data_range_by_coordinates(target_cell.row, target_cell.col,
                                                                 last_row, target_cell.col))
        flag_result = list(self._get_data_range_by_coordinates(flag_cell.row, flag_cell.col,
                                                               last_row, flag_cell.col))

        for key, element in enumerate(flag_result):
            if element.value:
                result[element.value] = target_result[key].value

        if file_path:
            utils.write_string_to_file(file_path, result)

        return result
Exemplo n.º 3
0
def download_an_image(url, file_path, exclude_url=PARSER_EXCLUDE_URL):
    """
    :param url: image's url
    :param file_path: path to save image
    :return: {"200", "Zero", "Error", "link-anh-ko-hop-le", "Small",  exception_message}
    If url is in 'exclude_url' list : Stop downloading and return
    Get html content and write to file
    Check downloaded file's status and return it
    """
    if re.search("|".join(exclude_url), url) is not None:
        print "{0} : link anh ko hop le".format(url)
        return "link-anh-ko-hop-le"

    if SHOW_DOWNLOAD_STATUS:
        print "[{0}] {1} : Downloading".format(utils.get_current_time(), url)

    html_content = utils.urllib2_get(url=url)
    utils.write_string_to_file(file_path, html_content.read())

    if utils.get_file_size(file_path) == int(html_content.info()['Content-Length']):
        if utils.get_image_resolution(file_path) < 300:
            return "Small"
        else:
            return "200"
    elif utils.get_file_size(file_path) == 0:
        return "Zero"
    else:
        return "Error"
Exemplo n.º 4
0
def get_project_list(export_type='string'):
    gspread_ids = [GSPREAD_SHEET_MAIN, GSPREAD_SHEET_HANTEL]
    print "Updating Project List"
    result = list()

    for gspread_id in gspread_ids:
        worksheet = LiveMangaGspread(sheet_title=gspread_id)
    
        start_cell = worksheet.find_tagged_cell("StoryNameHashValue")
        last_row_cell = worksheet.find_tagged_cell("StoryNameLastRow")
        stop_cell = worksheet.worksheet.acell(worksheet.worksheet.get_addr_int(last_row_cell.value,
                                                                     last_row_cell.col + EXTENDED_COLUMNS))
    
        project_list = worksheet.data_range_to_list(start_cell, stop_cell)
        project_list.pop(0)
        result = result + project_list

    if export_type == 'file':
        utils.write_string_to_file(PROJECT_LIST_PATH + ".txt", "\n".join(" ".join(x) for x in result))

    return result