Exemple #1
0
def run_server():
    kyk = Kyoukai("example_app")

    @kyk.route("/")
    async def index(ctx: HTTPRequestContext):
        with open("index.html") as f:
            return as_html(f.read())

    @kyk.route("/data")
    async def data(ctx: HTTPRequestContext):
        with open('db.json', 'r') as db:
            R = json.load(db)
            output = {
                "data":
                list(
                    map(
                        lambda r: [
                            "<a href='%s' target='_blank'># %s</a>" %
                            ("https://steemit.com/@%s/%s" % (r['author'], r[
                                'permlink']), r['title']), r['timestamp'],
                            "<a href='https://steemit.com/@%s' target='_blank'>%s</a>"
                            % (r['voter'], r['voter']),
                            "<a href='https://steemit.com/@%s' target='_blank'>%s</a>"
                            % (r['author'], r['author']),
                            int(r['weight']) / 100
                        ], R['_default'].values()))
            }
            return json.dumps(output), 200, {
                "Content-Type": "application/json"
            }

    kyk.run()
Exemple #2
0
def run_server():
    kyk = Kyoukai("PyTicker2 API Server")

    @kyk.route("/")
    async def index(ctx: HTTPRequestContext):
        return "HELLO", 200

    @kyk.route("/data")
    async def data(ctx: HTTPRequestContext):
        with open('dump.json', 'r') as pyticker_json:
            return json.dumps(json.load(pyticker_json)), 200, {
                "Content-Type": "application/json"
            }

    kyk.run()
Exemple #3
0
def run_server():
    kyk = Kyoukai("example_app")

    @kyk.route("/")
    async def index(ctx: HTTPRequestContext):
        return "HELLO", 200

    @kyk.route("/data")
    async def data(ctx: HTTPRequestContext):
        with open('upbit.json', 'r') as upbit_json:
            return json.dumps(json.load(upbit_json)), 200, {
                "Content-Type": "application/json"
            }

    kyk.run()
Exemple #4
0
import json
from kyoukai import Kyoukai, HTTPRequestContext

kyk = Kyoukai("example_app")

@kyk.route("/", methods=["GET", "POST"])
async def index(ctx: HTTPRequestContext):
    return json.dumps(list(ctx.request.headers.items())), 200, {"Content-Type": "application/json"}

kyk.run()
Exemple #5
0
import json
from kyoukai import Kyoukai, HTTPRequestContext

kyk = Kyoukai("example_app")


@kyk.route("/", methods=["GET", "POST"])
async def index(ctx: HTTPRequestContext):
    return json.dumps(list(ctx.request.headers.items())), 200, {
        "Content-Type": "application/json"
    }


kyk.run()
Exemple #6
0
    try:
        file_directory = 'templates/' + settings['pages']['servererror']
    except:
        file_directory = 'templates/index.html'

    with open(file_directory) as file:
        content = file.read()

        content = content.replace('{{AMOUNT}}', str(len(files)))
        content = content.replace('{{NAME}}', settings['meta']['name'])
        content = content.replace('{{DESCRIPTION}}',
                                  settings['meta']['description'])
        content = content.replace('{{TYPE}}', settings['meta']['type'])
        content = content.replace('{{TYPE-PLURAL}}',
                                  settings['meta']['plural'])
        content = content.replace('{{SITEURL}}', settings['meta']['siteurl'])
        content = content.replace('{{ENDPOINT-MAIN}}',
                                  settings['endpoints']['main']['name'])
        content = content.replace('{{ENDPOINT-JSON}}',
                                  settings['endpoints']['json']['name'])
        content = content.replace('{{ENDPOINT-RANDOM}}',
                                  settings['endpoints']['random']['name'])

        return util.as_html(content)


# ############################

# Run our App.
app.run(IP, PORT)
Exemple #7
0
        statisticTable = r.table(tbname).get(ourid).run(conn)

        try:
            newcount = statisticTable['count'] + 1
        except:
            newcount = 1

        r.table(tbname).get(ourid).update({"count": newcount}).run(conn)

        if response is None:
            return util.Response(status=404)

        if settings['monetise']['enabled']:
            with open(settings['templates']['monetise']) as file:
                stream = file.read()

            stream = stream.replace("{ LINK }", statisticTable['redirect_url'])

            header = {
                'Content-Type': "text/html"
            }

            return util.Response(stream, status=200, headers=header)
        else:
            return util.Response("<meta http-equiv=\"refresh\" content=\"0; url=" + statisticTable['redirect_url'] + "/\" />", status=200)

# ############################

# Run our App.
app.run(ip=ip, port=port)
Exemple #8
0
@app.route('/search', methods=['POST'])
async def search_handler(ctx):
    """ Returns json respresentiaton of a google reverse image search query """
    img_url = ''
    for url in ctx.request.form:
        img_url = url

    # Check whether the image exists and is actually a proper image
    image_resp = await get_resp_obj(img_url)
    if image_resp is None:
        return as_json({'error': 'Image does not exist'})
    if not is_image(image_resp):
        return as_json({'error': 'URL does not contain a proper image'})

    # Search for the image via reverse google image search
    google_html = await get_resp_html(SEARCH_URI.format(img_url))
    if google_html is None:
        return as_json({'error': 'Google has blocked this IP\nRe-captcha may be required'})

    # Try to decode HTML into JSON response
    try:
        return as_json(rp.parse_results(google_html))
    except Exception as e:
        return as_json({'error': f'Soup parsing error: {e}'})

    return as_json(resp_json)


if __name__ == '__main__':
    app.run(ip='localhost', port=8000)