Ejemplo n.º 1
0
def _transform_request(request):
    request = request.decode('utf-8')
    request = unquote(request)

    # Direct http example
    if request.startswith('http'):
        request = download_image(request)
    else:
        # Slack Label Example
        request_array = request.split('&')
        print(request_array)

        result = [
            value for value in request_array if value.startswith('text=')
        ]
        if len(result) > 0:
            request = download_image(result[0][5:])
            print(request)

    predict_img = image.load_img(request, target_size=(224, 224))
    predict_img_array = image.img_to_array(predict_img)
    predict_img_array = np.expand_dims(predict_img_array, axis=0)
    predict_preprocess_img = preprocess_input(predict_img_array)

    return predict_preprocess_img
Ejemplo n.º 2
0
def findBugInfo(bugId, location, *args):
    if location and location[-1] != '/':
        location += '/'
    request = "%sissues/%s" % (location, bugId)
    try:
        if request.startswith("https") and getattr(sys, 'frozen', False):
            certs = os.path.join(os.path.dirname(sys.executable), "etc",
                                 "cacert.pem")
            reply = urllib.request.urlopen(
                request, context=ssl.create_default_context(cafile=certs))
        else:
            reply = urllib.request.urlopen(request)
        content = reply.read().decode(reply.headers.get_content_charset())
        info = json.loads(content)
    except Exception as e:
        message = (
            "Failed to open URL '" + request + "': " + str(e) +
            ".\n\nPlease make sure that bug " + bugId + " exists\n" +
            "and that the configuration entry 'bug_system_location' " +
            "points to the correct GitHub repository.\nThe current value is '"
            + location +
            "', it often looks like: 'https://api.github.com/repos/<user>/<repo>/'."
        )
        return "NONEXISTENT", message, False, bugId
    if len(info) <= 1:
        message = "Could not parse reply from GitHub, maybe incompatible interface."
        return "BAD SCRIPT", message, False, bugId
    bugText = "******************************************************\n" + \
        "Ticket #%s (%s)\n" % (bugId, info['state']) + \
        "%s\n%sticket/%s\n" % (info['title'], location, bugId) + \
        "Reported By: %s Owned by: %s\n" % (info['user']['login'], info['assignee']) + \
        "Updated: %s Milestone: %s\n" % (info['updated_at'], info['milestone']) + \
        "Description:\n" + info['body'] + "\n" + \
        "******************************************************"
    return info['state'], bugText, info['state'] == "closed", bugId
Ejemplo n.º 3
0
 def __getUrls(self):
     urls = []
     html = self.html
     while True:
         pos = html.find('href="')
         if pos == -1:
             break
         html = html[pos + 6:]
         url = html[:html.find('"')]
         if url.startswith("/"):
             url = self.dominio + url
         urls.append(url)
     return urls
Ejemplo n.º 4
0
def process(update):
    request = str(update['message']['text']) if 'text' in update['message'] else "$$"
    global chat_id
    chat_id = update['message']['chat']['id']
    global message_id
    message_id = update['message']['message_id']
    user_id = update['message']['from']['id']
    username = update['message']['from']['username'] if 'username' in update['message']['from'] else False
    first_name = update['message']['from']['first_name'] if 'first_name' in update['message']['from'] else False
    last_name = update['message']['from']['last_name'] if 'last_name' in update['message']['from'] else False
    name = (first_name + " ") if first_name else ""
    name += last_name if last_name else ""
    global requester
    requester = username if username else name

    message_timestamp = update['message']['date']

    # update stats
    for chat_var in [Chats, SessionChats]:
        if chat_id in chat_var:
            if user_id in chat_var[chat_id]:
                chat_var[chat_id][user_id].new_message(message_timestamp)
            else:
                chat_var[chat_id][user_id] = UserStat([username, first_name, last_name], timestamp=message_timestamp)
        else:
            chat_var[chat_id] = {user_id: UserStat([username, first_name, last_name], timestamp=message_timestamp)}

    # process received commands
    if request.startswith(botprefix):

        request = request.split(botprefix, 1)[1]
        if request:
            if "@" in request:
                target = request.split("@", 1)[1].split(" ")
                if target[0] != bot_username:
                    return
                else:
                    request = request.replace("@" + bot_username, "")
        else:
            return

        try:
            request = shlex.split(request)
        except ValueError:
            return

        switcher = {
            "": dummy,
            "help": build_help,
            "quote": build_quote,
            "stats_alltime": build_alltime_stats,
            "stats_daily": build_daily_stats,
            "about": build_about,
            "uptime": build_uptime,
            "list_users": list_users,
            "save_stats": save_stats,
            "reset_daily": reset_daily_stats,
            "remember": build_remember_link,
            "forget": build_forget_link,
            "recall": build_recall_link,
            "search": build_search_link,
            "getpic": build_imgur_pic,
            "memegen": build_meme_gen,
            "search_meme": build_search_memes,
            "login_imgur": login_imgur,
            "logout_imgur": logout_imgur,
            "imgur_status": login_status_imgur
        }
        log("Request - " + str(request))
        response = switcher[request[0]](request) if request[0] in switcher else False
        log("Response - " + str(response))
        if response:
            send_message(response)