Skip to main content

Object-Oriented HTTP Request

Project description

Winney 面向对象的 HTTP 请求

Tutorial

wy = Winney(host="www.baidu.com")
wy.add_url(method="get", uri="/", function_name="download")
wy.download()
t = wy.get_bytes()
print(t)

The Best Practice

from winney import Winney

from config import ZEUS_HOST, ZEUS_PORT, APP_TYPE, ZEUS_TOKEN_HEADER, ZEUS_TOKEN_VALUE


class Zeus(object):
    def __init__(self, host, port):
        self.winney = Winney(host=host, port=port, headers={ZEUS_TOKEN_HEADER: ZEUS_TOKEN_VALUE})
        self.init_functions()
    
    def init_functions(self):
        self.winney.add_url(method="get", uri="/zeus/app_types/",           function_name="get_types")
        self.winney.add_url(method="get", uri="/zeus/app_types/{type_id}",  function_name="get_type")
        self.winney.add_url(method="get", uri="/zeus/accounts/{user_id}",   function_name="get_user_info")
        self.winney.add_url(method="get", uri="/zeus/application/{app_id}", function_name="get_app_info")
        self.winney.add_url(method="get", uri="/zeus/applications/",        function_name="get_apps")
    
    def get_data(self, r):
        if not r.ok():
            return None
        data = r.get_json()
        if data["code"] != 0:
            print("Failed to get zeus data, response = ", data)
            return None
        return data["data"]
    
    def get_apps(self, user_id):
        r = self.winney.get_apps(headers={"Authorization": "Token {}".format(user_id)}, user_id=user_id)
        return self.get_data(r)

    def get_types(self):
        r = self.winney.get_types()
        return self.get_data(r)
    
    def get_type_by_id(self, type_id):
        r = self.winney.get_type(type_id=type_id)
        return self.get_data(r)
    
    def get_user_info(self, user_id):
        r = self.winney.get_user_info(user_id=user_id)
        return self.get_data(r)
    
    def get_app_info(self, app_id):
        r = self.winney.get_app_info(app_id=app_id)
        return self.get_data(r)


zeus = Zeus(host=ZEUS_HOST, port=ZEUS_PORT)
zeus.get_app_info("123456)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

winney-redis-0.1.3.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file winney-redis-0.1.3.tar.gz.

File metadata

  • Download URL: winney-redis-0.1.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.5

File hashes

Hashes for winney-redis-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b899c53b6874d1e1a85c146ce67c9851f861078c547a46aa7b8ed42061af8590
MD5 d3da0dac98e2482f535c6d5ba5680aac
BLAKE2b-256 1e8ecf7c06349b26a0eb1cf7a8d66d53213bccc24e9d4d0cb426fd91a99f9f85

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page