def data_user(update, context): myResponse = requests.get(config.teleConfig.api+"/data_user") if(myResponse.ok): myResponseOk(myResponse, context, update) else: # If response code is not ok (200), print the resulting http error code with description myResponse.raise_for_status()
def sendRequest(url, type=None, params=None, headers=None, auth=None, files=None, setime=None, post=False): try: if post == True: data = requests.post(url, params=params, headers=headers, auth=auth, files=files) else: data = requests.get(url, params=params, headers=headers, auth=auth, files=files) except Exception as error: pass if data.status_code == 200: return (200, data) else: return (400, data)
def home(): """ Fast estimate Home Page """ wall_resource = 'http://localhost:8090/wall/:WA1' res = requests.get(wall_resource) wall_ = loads(res.text) return render_template( 'index.html', title='FastEstimate', message="Create Professional Construction Estimates in Seconds.", wall=wall_)
def handler(): if (flask.request.method == 'GET') and (flask.request.path == "/start"): params = dict(url = "{}/webhook".format(flask.request.host), max_connections = int(1), allowed_updates = "message") url = "{}{}".format(cfg['TELEGRAM_API'], 'setWebhook') r = requests.get(url,params=params).json() return flask.Response(response=r['description'], status=200) elif (flask.request.method == 'POST') and (flask.request.path == "/webhook"): msg = flask.request.get_json(silent=True, force=True)['message'] if ("language_code" in msg['from']) is True: cfg['LN'] = msg['from']['language_code'][:2] if ('text' in msg) and ("entities" in msg) is True: if ("bot_command" in msg['entities'][0]['type']) is True: cmd = msg['text'].replace('/','').lower().split() cmd = replace_(cmd[0]) return msg_receive_(msg, cmd, cfg['LN']) else: return flask.Response(status=200)
def Function(msg, cmd): return requests.get( 'https://mipsum.herokuapp.com/frases/random').json()['frase']
def Function(msg, cmd): nsfw = requests.get('http://api.o{}.ru/noise/1'.format(cmd[0])).json()[0]["preview"] api.sendPhoto(msg['chat']['id'],"http://media.o{}.ru/{}".format(cmd[0],nsfw), settings.BOT_USERNAME, reply_to_message_id=msg["message_id"]) return False
def testEventbriteCreds(self): # Ensure API authentication is working. If no error, pass. authHeader = AUTH_HEADER_EB r = requests.get("https://www.eventbriteapi.com/v3/users/me", headers=AUTH_HEADER_EB) self.assertEqual(r.status_code, 200)