当前位置: 首页>>代码示例>>Python>>正文


Python MozillaCookieJar.extract_cookies方法代码示例

本文整理汇总了Python中cookielib.MozillaCookieJar.extract_cookies方法的典型用法代码示例。如果您正苦于以下问题:Python MozillaCookieJar.extract_cookies方法的具体用法?Python MozillaCookieJar.extract_cookies怎么用?Python MozillaCookieJar.extract_cookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cookielib.MozillaCookieJar的用法示例。


在下文中一共展示了MozillaCookieJar.extract_cookies方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FlotrackConnection

# 需要导入模块: from cookielib import MozillaCookieJar [as 别名]
# 或者: from cookielib.MozillaCookieJar import extract_cookies [as 别名]

#.........这里部分代码省略.........
                    ("workout", ""),
                    ("workout", ""),
                    ("title", route),
                    ("show_on_menu", 0),
                    ("date", date_string),
                    ("warmup_mins", ""),
                    ("warmup_secs", ""),
                    ("warmup_distance", ""),
                    ("warmup_dist_unit", "miles"),
                    ("warmup_shoe_id", ""),
                    ("add_log", ""),
                    ("interval[0][reps]", ""),
                    ("interval[0][distance]", ""),
                    ("interval[0][dist_unit]", "miles"),
                    ("interval[0][rest]", ""),
                    ("interval[0][rest_unit]", "secs"),
                    ("interval[0][calculate_pace]", 1),
                    ("interval[0][shoe_id]", ""),
                    ("cooldown_mins", ""),
                    ("cooldown_secs", ""),
                    ("cooldown_distance", ""),
                    ("cooldown_dist_unit", "miles"),
                    ("cooldown_shoe_id", ""),
                    ("mins", int(minutes_component)),
                    ("secs", int(seconds_component)),
                    ("distance", distance_miles),
                    ("dist_unit", "miles"),
                    ("calculate_pace", 0),
                    ("calculate_pace", 1),
                    ("feel", ""),
                    ("field1", ""),
                    ("field2", ""),
                    ("shoe_id", ""),
                    ("notes", notes),
                    ("add_log", ""),]
        for i in range(len(run_info)):
            key = run_info[i][0]
            value = run_info[i][1]
            if key != "add_log" and "interval[0]" not in key:
                key = "RunningLogResource[%s]" % key
                run_info[i] = (key, value)
        return url_encode(run_info)

    def get_running_log_url(self, date):
        date_string = format(date, "%Y/%m/%d")
        return self.running_log_url % date_string

    def login(self, username, password):
        connection = HttpConnection(self.flotrack_domain)
        connection.set_debuglevel(self.debug_level)
        connection.connect()
        # Configure login parameters (this is the content of the HTTP request)
        params = { "LoginForm[username]": username,
                   "LoginForm[password]": password,
                   "LoginForm[rememberMe]": 1, }
        encoded_params = url_encode(params)
        # Get the HTTP headers to use
        headers = self.get_default_headers(encoded_params)
        del headers["Cookie"]
        # Configure the cookie jar to store the login information
        cookie_request = HttpRequestAdapter(self.flotrack_domain, self.login_url,
                                            headers)
        self.cookie_jar.add_cookie_header(cookie_request)
        # Issue the HTTP request
        request = connection.request("POST", self.login_url, encoded_params, headers)
        response = connection.getresponse()
        if response.status == OK:
            return False
        if response.status == FOUND:
            response.read()
            response.info = lambda: response.msg
            # Extract the login cookies
            self.cookie_jar.extract_cookies(response, cookie_request)
            self.connection = connection
            return True
        raise Exception("Flotrack connection failed during login.")

    def logout(self):
        request = self.connection.request("GET", self.logout_url)
        response = self.connection.getresponse()
        if response.status == OK:
            return False
        if response.status == FOUND:
            return True
        raise Exception("Flotrack connection failed during logout.")

    def record_run(self, date, route, distance_miles, time_minutes, notes=""):
        # Create parameters to pass to the log
        encoded_params = self.get_running_log_params(date, route, distance_miles, time_minutes, notes)
        # Post the data to the server
        headers = self.get_default_headers(encoded_params)
        running_log_url = self.get_running_log_url(date)
        request = self.connection.request("POST", running_log_url, encoded_params, headers)
        response = self.connection.getresponse()
        if response.status == OK:
            return False
        if response.status == FOUND:
            response.read()
            return True
        raise Exception("Flotrack connection failed while recording run.")
开发者ID:karldickman,项目名称:bike-log,代码行数:104,代码来源:flotrack_upload.py


注:本文中的cookielib.MozillaCookieJar.extract_cookies方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。