示例#1
0
def get_content():
    res = get('https://api.apiopen.top/getJoke', {'type': 'gif', 'count': 20})
    html = ''
    if res is not None and res.get('code') == 200:
        content_list = res.get('result')
        for index, item in enumerate(content_list):
            # html += '<b>{}</b><p>{}</p>'.format(
            #     index + 1,
            #     str_unicode_html(item.get('text'))
            # )
            src = item.get('images')
            if get(src, format=False).status_code != 200:
                continue
            print(index)
            html += '<p><strong>{}</strong></p>'.format(
                str_unicode_html(item.get('text')))
            if item.get('top_comments_content') is not None:
                html += '<p>神评论:{}</p>'.format(
                    str_unicode_html(item.get('top_comments_content')))
            html += '<p><img src={}></p><p> </p><p> </p><br><br>'.format(src)

        if html != '':
            html += '<blockquote><p>图片来自网络,侵删</p></blockquote>'

        return html
    else:
        return None
示例#2
0
def api():
    method = requestUtils.get(request, 'method', str)
    version = requestUtils.get(request, 'version', str)
    callback = requestUtils.get(request, 'callback', str)
    format_type = requestUtils.get(request, 'format', str)

    if method == 'api.status.getStatus':
        if callback == 'updateServerStatus(data)' and version == '1' and format_type == 'json':
            javascript = serverApi.api_getStatus_javascript(callback)
            return Response(javascript, mimetype='application/javascript')

    print " "
    print "http://" + request.host + "/api"
    print request.args
    print " "

    return ""
示例#3
0
def surveyApi():
    method = requestUtils.get(request, 'method', str)

    if method == "api.survey.getSurveyList":
        return responseUtils.xmlResponseWithObject(
            serverApi.surveyApi_getSurveyList_object())

    return responseUtils.xmlResponseWithObject({})
示例#4
0
def dlsApi():
    method = requestUtils.get(request, 'method', str)

    if method == 'api.launcher.setTheme':
        theme = requestUtils.get(request, 'theme', str)
        server.setActiveTheme(theme)
        return responseUtils.jsonResponseWithObject({'stat': 'ok'})

    if method == 'api.launcher.listThemes':
        selectedTheme = server.getActiveTheme()
        themesList = server.availableThemes()
        return responseUtils.jsonResponseWithObject({
            'stat':
            'ok',
            'themes':
            themesList,
            'selectedTheme':
            selectedTheme
        })

    return Response(status=500)
示例#5
0
def gameApi():
    version = requestUtils.get(request, 'version', str)
    build = requestUtils.get(request, 'build', str)
    method = requestUtils.get(request, 'method', str)

    # Different players must be using the same version of the game, otherwise
    # there may be issue during a match.
    validVersion = server.setGameVersion(build)
    if serverConfig.versionLockEnabled() and validVersion == False:
        return responseUtils.xmlResponseWithObject(
            serverApi.bootstrapApi_error_object())

    if method == 'api.status.getStatus':
        include_broadcasts = requestUtils.get(request, 'include_broadcasts',
                                              str)
        return responseUtils.xmlResponseWithObject(
            serverApi.gameApi_getStatus_object(include_broadcasts))

    print " "
    print "http://" + request.host + "/api"
    print request.args
    print " "

    return responseUtils.xmlResponseWithObject({})
示例#6
0
def bootstrapLauncher():
    version = requestUtils.get(request, 'version', str)

    if serverConfig.skipLauncher():
        launcherNotesHtml = launcherUtils.directToGameHtml()
        return Response(launcherNotesHtml, mimetype='text/html')

    launcherPath = serverConfig.darksporeLauncherThemesPath()
    launcherPath = pathUtils.join(
        pathUtils.join(launcherPath, server.getActiveTheme()), "index.html")

    file = open(
        pathUtils.join(pathUtils.join(serverConfig.storagePath(), 'www'),
                       launcherPath), "r")
    launcherHtml = file.read()

    dlsClientScript = launcherUtils.dlsClientScript(server.config.host())
    launcherHtml = launcherHtml.replace('</head>', dlsClientScript + '</head>')

    return Response(launcherHtml, mimetype='text/html')
示例#7
0
def gameServicePng():
    account_id = requestUtils.get(request, 'account_id', int)
    if account_id != None:
        print("Should return user account PNG")
        return ""

    creature_id = requestUtils.get(request, 'creature_id', int)
    if creature_id != None:
        print("Should return creature PNG")
        return ""

    template_id = requestUtils.get(request, 'template_id', int)
    if template_id != None:
        size = requestUtils.get(request, 'size', int)
        print("Should return creature template PNG")
        return ""

    ability_id = requestUtils.get(request, 'ability_id', int)
    if ability_id != None:
        print("Should return ability PNG")
        return ""

    rigblock_id = requestUtils.get(request, 'rigblock_id', int)
    if rigblock_id != None:
        # Rig blocks are:
        # Eyes, noses, mouths, hands, feet, tails, wings, armor,
        # weapons, jewelry and all types of assets used in character creation.
        print("Should return creature part PNG")
        return ""

    print " "
    print "http://" + request.host + "/game/service/png"
    print request.args
    print " "

    return ""
示例#8
0
def bootstrapApi():
    version = requestUtils.get(request, 'version', str)
    build = requestUtils.get(request, 'build', str)
    method = requestUtils.get(request, 'method', str)

    # Different players must be using the same version of the game, otherwise
    # there may be issue during a match.
    validVersion = server.setGameVersion(build)
    if serverConfig.versionLockEnabled() and validVersion == False:
        return responseUtils.xmlResponseWithObject(
            serverApi.bootstrapApi_error_object())

    if method.startswith('api.account.'):
        if method == 'api.account.getAccount':
            include_feed = requestUtils.get(request, 'include_feed', bool)
            include_decks = requestUtils.get(request, 'include_decks', bool)
            include_creatures = requestUtils.get(request, 'include_creatures',
                                                 bool)
            player_id = requestUtils.get(request, 'id', int)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_getAccount_object(
                    player_id, include_feed, include_decks, include_creatures))

        if method == 'api.account.searchAccounts':
            count = requestUtils.get(request, 'count', int)
            terms = requestUtils.get(request, 'terms', str)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_searchAccounts_object(count, terms))

    if method.startswith('api.config.'):
        if method == 'api.config.getConfigs':
            include_settings = requestUtils.get(request, 'include_settings',
                                                bool)
            include_patches = requestUtils.get(request, 'include_patches',
                                               bool)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_getConfigs_object(
                    build, include_settings, include_patches))

    if method.startswith('api.creature.'):
        if method == 'api.creature.getCreature':
            creature_id = requestUtils.get(request, 'id', int)
            include_parts = requestUtils.get(request, 'include_parts', bool)
            include_abilities = requestUtils.get(request, 'include_abilities',
                                                 bool)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_getCreature_object(
                    creature_id, include_parts, include_abilities))

        if method == 'api.creature.getTemplate':
            creature_id = requestUtils.get(request, 'id', int)
            include_abilities = requestUtils.get(request, 'include_abilities',
                                                 bool)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_getCreatureTemplate_object(
                    creature_id, include_abilities))

    if method.startswith('api.friend.'):
        if method == 'api.friend.getList':
            start = requestUtils.get(request, 'start', int)
            sort = requestUtils.get(request, 'sort', str)  # eg. 'name'
            list_type = requestUtils.get(request, 'list',
                                         str)  # eg. 'following'
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_getFriendsList_object(
                    start, sort, list))

        if method == 'api.friend.follow':
            name = requestUtils.get(request, 'name', str)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_followFriend_object(name))

        if method == 'api.friend.unfollow':
            name = requestUtils.get(request, 'name', str)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_unfollowFriend_object(name))

        if method == 'api.friend.block':
            name = requestUtils.get(request, 'name', str)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_blockFriend_object(name))

        if method == 'api.friend.unblock':
            name = requestUtils.get(request, 'name', str)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_unblockFriend_object(name))

    if method.startswith('api.leaderboard.'):
        if method == 'api.leaderboard.getLeaderboard':
            name = requestUtils.get(request, 'name',
                                    str)  # eg. 'xp' / 'pvp_wins' / 'team'
            varient = requestUtils.get(request, 'varient',
                                       str)  # eg. 'friends'
            count = requestUtils.get(request, 'count', int)
            start = requestUtils.get(request, 'start', int)
            return responseUtils.xmlResponseWithObject(
                serverApi.bootstrapApi_getLeaderboard_object(
                    name, varient, count, start))

    print " "
    print "http://" + request.host + "/bootstrap/api"
    print request.args
    print " "

    return responseUtils.xmlResponseWithObject(
        serverApi.bootstrapApi_error_object())