def remove_image(mid): logging.info('REMOVING IMAGE ' + str(mid)) resp = requests.delete( DIALOGS_API_SKILL_URL + str(mid).strip('/'), headers={'Authorization': 'OAuth {}'.format(OAuth)}) log_request(resp) resp = resp.json() return 'result' in resp and resp['result'] == 'ok'
def route(src, trg): resp = requests.get(RASP_API_URL.format('search'), params={ 'from': str(src), 'to': str(trg) }) try: resp.raise_for_status() except Exception: log_request(resp) raise return resp.json()
def upload_image_source(source): logging.info('UPLOADING IMAGE') resp = requests.post(DIALOGS_API_SKILL_URL, files={'file': source}, headers={ 'Authorization': 'OAuth {}'.format(OAuth), }) log_request(resp) resp = resp.json() if 'image' in resp: return resp['image']['id'] return False
def nearest_stations(pos, dist=1): resp = requests.get(RASP_API_URL.format('nearest_stations'), params=Str.string_query({ 'lat': pos[0], 'lng': pos[1], 'distance': dist })) try: resp.raise_for_status() except Exception: log_request(resp) raise return resp.json()
def get(self, surface=False, **kwargs): resp = requests.get(self.get_url(static=True, **kwargs)) try: resp.raise_for_status() except Exception: log_request(resp) raise mf = BytesIO(resp.content) if surface: import pygame return pygame.image.load(mf, '_.png') else: return mf
def upload_image_url(url): logging.info('UPLOADING IMAGE FROM ' + url) resp = requests.post(DIALOGS_API_SKILL_URL, json={'url': url}, headers={ 'Authorization': 'OAuth {}'.format(OAuth), }) logging.info('request finished, got ' + resp.content.decode('utf-8')) log_request(resp) resp = resp.json() if 'image' in resp: return resp['image']['id'] return False
def __init__(self, geocode, **kwargs): kwargs['geocode'] = geocode for k, v in kwargs.items(): if v is None: pass elif isinstance(v, str) or hasattr(v, '__int__'): pass elif hasattr(v, 'str_parameter'): kwargs[k] = str(v) else: kwargs[k] = Str.pos(v) resp = requests.get(GEOCODE_API_URL, params=kwargs) try: resp.raise_for_status() except Exception: log_request(resp) raise res = resp.json() self.data = res['response']['GeoObjectCollection']
def __init__(self, text, **kwargs): kwargs['text'] = text for k, v in kwargs.items(): if v is None: pass elif isinstance(v, str) or hasattr(v, '__int__'): pass elif hasattr(v, 'str_parameter'): kwargs[k] = v.str_parameter() else: kwargs[k] = Str.pos(v) resp = requests.get(SEARCH_API_URL, params=kwargs) try: resp.raise_for_status() except Exception: log_request(resp) raise res = resp.json() if res.get('status', None) == 'error': raise ValueError(res) self.data = res