Beispiel #1
0
 def short_link(self, link):
     params = {}
     for key, value in self.params.items():
         params[key] = value.format(url = link)
     url = self.url.format(url = quote(link))
     res = upload(url, params)
     return re.search(self.regexp, res).group('name')
Beispiel #2
0
 def upload_file(self, filename, part = 2):
     self.check_file(filename)
     params = {}
     for key, value in self.params.items():
         params[key] = value.format(file = filename)
     res = upload(self.url, params, part = part)
     return re.search(self.regexp, res).group('name')
Beispiel #3
0
 def paste_text(self, text, language, comment, filename, part = 2):
     if not language in self.languages:
         raise LanguageNotFound(', '.join(self.languages))
     params = {}
     for key, value in self.params.items():
         params[key] = value.format(code = text, lang = language, comment = comment, name = filename)
     res = upload(self.url, params, part = part)
     return re.search(self.regexp, res).group('name')
Beispiel #4
0
def run_model(parameter):
    # Parameter here is the model's acronym sent in the link
    if request.method == "GET":
        return render_template("models/{}.html".format(parameter),
                               display=parameter)

    else:
        user = current_user.username
        form_files = request.files
        form_data = request.form

        inputParam = user_input(form_data, form_files)

        errors = []

        # IF metrics not checked
        if "metrics" not in form_data:
            errors.append("Please check at least one or more metrics")
        # IF files are not uploaded
        if len(form_files) == 0:
            errors.append("Please ensure the dataset file is uploaded")
        # IF file extension error
        elif not upload(form_files):
            errors.append("Upload was unsuccessful")
            errors.append("Accepted file types: .txt, .csv")

        if len(errors) > 0:
            return jsonify({"errors": errors})

        user_folder = "uploads/" + user
        current_run = check_folder(user_folder)

        results_path = user_folder + "/user_results.pkl"
        result_dict = {current_run: "model training in queue..."}

        if os.stat(results_path).st_size > 0:  # Old user
            f = open(results_path, "rb")
            user_results = pickle.load(f)
            user_results.update(result_dict)
            f.close()

            f = open(results_path, "wb")
            pickle.dump(user_results, f)
            f.close()
        else:  # New user
            f = open(results_path, "wb")
            pickle.dump(result_dict, f)
            f.close()

        # Adding Cornac task into Redis Queue
        task_input = (inputParam, user, current_run)
        job = q.enqueue(run_task, task_input)

        return jsonify({"result": "Task has been submitted to our server..."})
Beispiel #5
0
def binding_method(*widgets):
    """
    Function is responsible for binding methods on to the widgets.
    @param widgets: Objects of different widgets
    """
    try:
        file_upload_button, folder_upload_button, foldername_entry, upload_to_gdrive, textarea, container = widgets

        # File upload button binding
        file_upload_button.bind('<Button-1>', lambda event, textarea=textarea: functions.select_file(textarea))
        # Folder upload button binding
        folder_upload_button.bind('<Button-1>', lambda event, textarea=textarea: functions.select_folder(textarea))
        # Upload to Google Drive Button Binding
        upload_to_gdrive.bind('<Button-1>',
                              lambda event, foldername_entry=foldername_entry, textarea=textarea,
                                     root=container: functions.upload(
                                  foldername_entry, textarea, root))
    except Exception as e:
        raise Exception(e)
Beispiel #6
0
def start_menu():
    menu = {}
    menu_items = [
        "Exit", "Create Build", "Restore Build", "List Builds",
        "Download Build", "Upload Build", "Delete Builds", "Settings"
    ]

    for i in range(len(menu_items)):
        menu[f"{i}"] = menu_items[i]

    # while True:
    print("Build Manager\n")
    for entry in menu:
        print(f"[{entry}]:", menu[entry])

    selection = input("\nPlease Select: ")

    functions.clear()
    if selection.isdigit():
        if 1 <= int(selection) <= 7:
            switcher = {
                1: lambda: functions.create_build(),
                2: lambda: functions.restore_build(),
                3: lambda: functions.list_builds(service_menu("local")),
                4: lambda: functions.download(service_menu("online")),
                5: lambda: functions.upload(service_menu("online")),
                6: lambda: functions.delete(service_menu("local")),
                7: lambda: settings_menu()
            }
            func = switcher.get(int(selection),
                                lambda: "Unknown option selected\n")
            return func()
        elif selection == "0":
            functions.clear()
            sys.exit()

    print("Unknown option selected\n")
Beispiel #7
0
 def upload(self, file):
     url = self.upload_file(file, part = 1)
     res = upload(url)
     return re.search(r'\"(http:\/\/ipicture\.ru\/uploads\/\d*\/[a-zA-Z0-9]*\.\w*)\"', res).group(1)
Beispiel #8
0
 def upload(self, file):
     self.regexp = self.regexp % strftime(r'%Y\/%m%d')
     url = self.upload_file(file, part = 1)
     res = upload(url)
     return re.search(r'http:\/\/i\d*\.fastpic\.ru\/big\/[a-zA-Z0-9\.\/\-_]*', res).group()
Beispiel #9
0
 def upload(self, file):
     self.url = re.search(r'id=\"upload\" action=\"(http://m.pikucha.ru/[a-zA-Z0-9]*)\"', upload(self.url)).group(1)
     id = self.upload_file(file, part = 1)
     return 'http://pikucha.ru/%s/%s' % (id, os.path.basename(file))