Ejemplo n.º 1
0
def predict(image_path):
    image = open(image_path, "rb").read()
    image = base64.b64encode(image).decode("utf-8")
    data = {"image": image, 'postId': 11111, 'userId': 22222, 'imageUrl': image_path}
    data = json.dumps(data)
    req = request.Request(HOST, headers={"Content-Type": "application/json"})
    res = request.urlopen(req, data=bytes(data, encoding="utf-8"))
    result = json.loads(res.read())
    return result
Ejemplo n.º 2
0
def _get(urlString):
    """
    Internal method to convert a URL into it's response (a *str*).

    :param str urlString: the url to request a response from
    :returns: the *str* response
    """
    if PYTHON_3:
        req = request.Request(urlString, headers=HEADER)
        response = request.urlopen(req)
        return response.read().decode('utf-8')
    else:
        req = urllib2.Request(urlString, headers=HEADER)
        response = urllib2.urlopen(req)
        return response.read()
Ejemplo n.º 3
0
def send_message_to_slack(text):
    from urllib import request
    import json

    post = {"text": "{0}".format(text)}

    try:
        json_data = json.dumps(post)
        req = request.Request(
            "https://hooks.slack.com/services/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",
            data=json_data.encode('ascii'),
            headers={'Content-Type': 'application/json'})
        resp = request.urlopen(req)
    except Exception as em:
        print("EXCEPTION: " + str(em))
Ejemplo n.º 4
0
def send_message_to_slack(text):
    from urllib import request, parse
    import json

    post = {"text": "{0}".format(text)}

    try:
        json_data = json.dumps(post)
        req = request.Request(
            "https://hooks.slack.com/services/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",
            data=json_data.encode('ascii'),
            headers={'Content-Type': 'application/json'})
        resp = request.urlopen(req)
    except Exception as em:
        print("EXCEPTION: " + str(em))
Ejemplo n.º 5
0
def send_message_to_slack(text: str):

    post = {"text": "{0}".format(text)}

    try:
        json_data = json.dumps(post)
        req = request.Request(
            "https://hooks.slack.com/services/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",
            data=json_data.encode('ascii'),
            headers={'Content-Type': 'application/json'})
        resp = request.urlopen(req)
    except Exception as em:
        print("EXCEPTION: " + str(em))
    output = {"input": text, "output": "sent message"}
    return json.dumps(output)
    send_message_to_slack("<text>")
Ejemplo n.º 6
0
def tuling(text):
    userInfo = {
        'apiKey': '6d7cfb30e6d5463cbd5336cba25bbb6f',
        'userId': '382554'
    }
    inputText = {'text': text}
    selfInfo = {'location': {'city': '上海'}}
    perception = {'inputText': inputText, 'selfInfo': selfInfo}
    dic = {'reqType': 0, 'perception': perception, 'userInfo': userInfo}
    req = request.Request('http://openapi.tuling123.com/openapi/api/v2')
    f = request.urlopen(req, json.dumps(dic).encode('utf-8'))
    dic = json.loads(f.read().decode('utf-8'))
    results = dic['results']
    if len(results) > 0:
        res = results[0]
        text = res['values']['text']
        return text
    return ''
Ejemplo n.º 7
0
def alert(text):
    from urllib import request, parse
    x = "{"
    y = "}"
    a = "True"
    b = "False"
    post = {"text": "{0}".format(text)}
    try:
        json_data = json.dumps(post)
        req = request.Request(
            "https://hooks.slack.com/services/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",
            data=json_data.encode('ascii'),
            headers={'Content-Type': 'application/json'})
        resp = request.urlopen(req)
        return f"{x}\n\"input\": {text},\n\"output\": {a}\n{y}"
    except Exception as em:
        print("EXCEPTION: " + str(em))
        return f"{x}\n\"input\": {text},\n\"output\": {b}\n{y}"
    alert(f'{text}')
Ejemplo n.º 8
0
def index():
    client = Client(app.config['API_KEY'], app.config['API_SECRET'])
    prices = client.get_all_tickers()

    url = 'http://data.fixer.io/api/latest?access_key=87fdd450a053ec762d421382f62b7ad7&symbols=USD,CNY'
    req = request.Request(url)
    res = request.urlopen(req)
    res = res.read()
    resjson = json.loads(res)
    usdrate = resjson["rates"]["USD"]
    cnyrate = resjson["rates"]["CNY"]
    fex = float(cnyrate / usdrate)

    mybtc = mydb.session.query(
        Btc.symbol,
        func.sum(Btc.amount).label('amount'),
        func.sum(Btc.cnycost).label('cnycost')).group_by(Btc.symbol).all()
    mybase = mydb.session.query(func.sum(Base.invest).label('invest')).first()
    mybaseinvest = mybase.invest

    portfolio = {}

    mybtclist = {}
    for symbol in prices:
        mybtclist[symbol['symbol']] = symbol['price']

    cnysum = float(0)
    for coin in mybtc:
        if coin.symbol + "USDT" in mybtclist:
            cnyprice = float(
                mybtclist[coin.symbol + "USDT"]) * fex  #*float(coin.amount)
            portfolio[coin.symbol] = [
                coin.amount, coin.cnycost,
                round(float(coin.cnycost) / float(coin.amount), 2), cnyprice,
                round(cnyprice, 2),
                round((cnyprice * float(coin.amount) - float(coin.cnycost)) /
                      (float(coin.cnycost)) * 100, 2)
            ]
        elif coin.symbol + "ETH" in mybtclist:
            cnyprice = float(mybtclist[coin.symbol + "ETH"]) * float(
                mybtclist['ETHUSDT']) * fex  #*float(coin.amount)
            portfolio[coin.symbol] = [
                coin.amount, coin.cnycost,
                round(float(coin.cnycost) / float(coin.amount), 2), cnyprice,
                round(cnyprice, 2),
                round((cnyprice * float(coin.amount) - float(coin.cnycost)) /
                      (float(coin.cnycost)) * 100, 2)
            ]
        else:
            cnyprice = float(mybtclist[coin.symbol + "BTC"]) * float(
                mybtclist['BTCUSDT']) * fex  #*float(coin.amount)
            portfolio[coin.symbol] = [
                coin.amount, coin.cnycost,
                round(float(coin.cnycost) / float(coin.amount), 2), cnyprice,
                round(cnyprice, 2),
                round((cnyprice * float(coin.amount) - float(coin.cnycost)) /
                      (float(coin.cnycost)) * 100, 2)
            ]
        cnysum = cnysum + float(portfolio[coin.symbol][3] * float(coin.amount))

    gain = round((cnysum / float(mybaseinvest) - 1) * 100, 2)

    cnysumround = float('%.2f' % cnysum)
    mybaseinvestround = float('%.2f' % mybaseinvest)

    return render_template('index.html',
                           prices=prices,
                           fex=fex,
                           mybtc=mybtc,
                           portfolio=portfolio,
                           cnysumround=cnysumround,
                           mybaseinvestround=mybaseinvestround,
                           gain=gain)