コード例 #1
0
    def __init__(self, name, draw_graph=False):
        self.__info = Request.country_info(name)
        self.__historical = Request.country_historical(self.__info.name)

        super(CountryMessage, self).__init__(Draw.country_historical,
                                             self.__historical,
                                             draw_graph=draw_graph)
コード例 #2
0
def apod():
    url = current_app.config['APOD_URL']
    params = {'api_key': get_jwt(), **get_json(PayloadSchema())}

    apod_request = Request(url, params=params)

    response = apod_request.get().json()

    if 'thumbnail_url' in response:
        image_url = response['thumbnail_url']
    else:
        image_url = (response['hdurl']
                     if bool(params['hd']) else response['url'])

    content = requests.get(image_url).content

    path = get_media_path()
    file_name = get_file_name(params['date'])

    save_image(content, path, file_name)

    return jsonify({
        'status': 'Success! Image saved.',
        'path': os.path.join(path, file_name),
    })
コード例 #3
0
def cme():
    url = current_app.config['CME_URL']

    params = {'api_key': get_jwt(),
              **get_params(CMEPayloadSchema())}

    cme_request = Request(url, params=params)

    response = cme_request.get().json()

    cme_info = form_cme_data(response)

    return jsonify(cme_info)
コード例 #4
0
    def __init__(self,
                 first_countries=None,
                 draw_graph=True,
                 sort=CountryInfo.Fields.cases):
        self.__info = Request.world_info()
        self.__historical = Request.world_historical()
        self.__countries = Request.countries(sort=sort)

        self.sort = sort.name
        self.first_countries = first_countries

        super(WorldMessage, self).__init__(Draw.world_historical,
                                           self.__historical,
                                           draw_graph=draw_graph)
コード例 #5
0
def api_lcm():
    return jsonify(
        Request(
            request.args,
            methods.lcm,
            required_args={
                'numbers': utils.string_to_int_list
            },
        ).process(str))
コード例 #6
0
def api_next_prime():
    return jsonify(
        Request(
            request.args,
            methods.next_prime,
            required_args={
                'number': int
            },
        ).process(str))
コード例 #7
0
    def initialize_request(self, request, *args, **kwargs):
        """
        Returns the initial request object.
        """
        parser_context = self.get_parser_context(request)

        return Request(request,
                       parsers=self.get_parsers(),
                       authenticators=self.get_authenticators(),
                       negotiator=self.get_content_negotiator(),
                       parser_context=parser_context)
コード例 #8
0
def api_four_squares():
    return jsonify(
        Request(
            request.args,
            methods.four_squares,
            required_args={
                'number': int
            },
            restrictions={
                'number': {
                    'upper_bound': 10**30
                }
            },
        ).process())
コード例 #9
0
def api_random_prime():
    return jsonify(
        Request(
            request.args,
            methods.random_prime,
            required_args={
                'digits': int
            },
            restrictions={
                'digits': {
                    'upper_bound': 100
                }
            },
        ).process(str))
コード例 #10
0
def api_bezout():
    return jsonify(
        Request(
            request.args,
            methods.bezout,
            required_args={
                'numbers': utils.string_to_int_list
            },
            restrictions={
                'numbers': {
                    'count': 2
                }
            },
        ).process(lambda x: list(map(str, x))))
コード例 #11
0
def top_countries(chat: ChatHandler, _):
    countries_cnt = 3

    req = Request.countries()
    for i in range(countries_cnt - 1):
        send_country_class(chat, country_class=req.list[i])
コード例 #12
0
ファイル: __init__.py プロジェクト: bbelchak/py-alexa
import os

ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID")
SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")
SERVICE_HOST = "awis.amazonaws.com"


if __name__ == "__main__":
    from api.request import Request

    request = Request()
    total = 1000
    query = {
        "ResponseGroup": "Listings",
        "Action": "CategoryListings",
        "Path": "Top/Business",
        "SortBy": "Popularity",
        "Recursive": "True",
    }
    for count in range(1, total, 20):
        query["Start"] = count
        for s in request.sites(query):
            print s
コード例 #13
0
ファイル: api_tests.py プロジェクト: tsepanx/covid-stats.bot
 def test_countries_request(self):
     req = Request.countries()
     for country_info in req.list:
         self.assert_country_info(country_info)
コード例 #14
0
ファイル: api_tests.py プロジェクト: tsepanx/covid-stats.bot
 def test_country_info_request(self):
     for country_name in self.TEST_COUNTRIES:
         req = Request.country_info(country_name)
         self.assert_country_info(req)
コード例 #15
0
ファイル: api_tests.py プロジェクト: tsepanx/covid-stats.bot
 def test_world_info_request(self):
     req = Request.world_info()
     self.assertGreater(req.cases + req.recovered, 2 * 10**6)
コード例 #16
0
ファイル: api_tests.py プロジェクト: tsepanx/covid-stats.bot
 def test_country_historical_request(self):
     for country_name in self.TEST_COUNTRIES:
         request = Request.country_historical(country_name)
         self.assert_country_historical(request)
コード例 #17
0
ファイル: api_tests.py プロジェクト: tsepanx/covid-stats.bot
 def test_world_historical(self):
     req = Request.world_historical()
     self.assert_historical_dicts(req)