Пример #1
0
def add_user():
    username = input("Enter username: "******"Enter password: "******"Enter email address: ").strip()

    # Validate username.
    validated = validate_username(username, password, email)
    if validated == 1:
        ui_.message_out(username, g_.s, 'No Duplicate entries exist.')
        proceed = create_user_in_table(username, password, email)
        ui_.message_out(username, g_.s, 'User created confirmed.')
        if proceed != 1:
            return 0
    elif validated == -1:
        ui_.message_out('', g_.e, 'Username or Password or email is blank.')
        return 0
    elif validated == -2:
        ui_.message_out('', g_.e, 'Email address already registered.')
        return 0
    else:
        ui_.message_out('', g_.e, 'Username exists.')
        add_user()

    creat_user_log_file(username)
    create_user_config_file(username)
    main_3.main(username, 'activate_service_1')
    main_3.main(username, 'add_folder')
    main_3.main(username, 'run')
    return username
Пример #2
0
def create_user_in_table(username, password, email):
    try:
        file_path = g_.root + g_.folder_db + 'users.csv'
        user_details = open(file_path, 'a', encoding='utf-8')
        user_details.write('\n' + username + ',' + password + ',' + email)
        user_details.close()
        ui_.message_out(username, g_.s, 'User added.')
    except:
        return 0
    return 1
Пример #3
0
def find_next_photo(username):
    file_path = g_.root + g_.folder_db + username + '_sequence.csv'
    data = pd.read_csv(file_path)
    rows = data.loc[data['uploaded'] == 'not-done']
    if rows.empty:
        ui_.message_out(username, g_.e, "No more photographs to share.")
        time.sleep(15)
        return ''
    else:
        folder_no = rows.iloc[0]['folder_no']
        photo_path = rows.iloc[0]['file_path']
        return [folder_no, photo_path]
Пример #4
0
def check_signin(username, password):
    file_path = g_.root + g_.folder_db + 'users.csv'
    # user_details = open(file_path, 'r', encoding='utf-8')
    user_list = pd.read_csv(file_path)
    # user_details.close()

    # So user_list is a table with all usernames and passwords.
    row = user_list.loc[(user_list['username'] == username)]
    if row.empty:
        return 0
    else:
        try:
            if str(row.iloc[0]['password']).strip() != password:
                ui_.message_out('', g_.e, 'Password did not match')
                return 0
        except:
            return 0

    # username and password match.
    ui_.message_out(username, g_.s, 'User signed in.')
    return 1
Пример #5
0
def fb_page_post_image(username, file, graph, description, count):
    with open(file, "rb") as image:
        graph.put_photo(image=image, message=description)
    notification.notify("Uploaded:", str(file))
    ui_.message_out(username, g_.s, 'Uploaded ' + str(file))

    # Update the log
    log = g_.root + g_.folder_db + 'db.csv'
    log_content = open(log, 'a', encoding='utf-8')
    log_content.write(
        str(dt.datetime.now()) + ',' + "Uploaded" + ',' + str(file) + '\n')
    log_content.close()

    # Update count number.
    count = count + 1
    counter = g_.root + g_.folder_db + 'count.txt'
    counter_content = open(counter, 'w', encoding='utf-8')
    counter_content.write(str(count))
    counter_content.close()

    time.sleep(60)
    return count
Пример #6
0
def main(user, text):
    if text.strip() == 'add_folder':
        proceed = func_sequence.add_folder(user)
        if proceed == 1:
            ui_.message_out(user, g_.s, 'Folder is added successfully.')
        confirm = input("Add another folder?").strip()
        if confirm in g_.yes:
            main(user, 'add_folder')
    elif text == 'sign_up':
        proceed = func_sequence.add_user()
        if proceed != 0:
            ui_.message_out(proceed, g_.s, 'User created.')
    elif text == 'run':
        main_bg.run_service_1(user)
    elif text == 'activate_service_1':
        func_sequence.activate_service(user, 1)
        ui_.message_out(user, g_.s, user)
    else:
        ui_.message_out('', g_.e, text + ' is not a recognised command.')
Пример #7
0
def add_folder(username):
    # Authorise Dropbox. [Out of Scope of this program. We work with predefined user; Me.]
    folder_name = input("Enter folder name: ").strip()

    if folder_name != '':
        # Check if the folder exists.
        folder_exists = check_folder_exists(folder_name)

        # Finds the most relevant link for the folder.
        link = f_.create_link(folder_name)  # Finding the link.
        # Shortens the link using Bit.ly.
        short_link = f_.shorten_link(link)  # Shortened link.

        # Creates the folder number:
        try:
            num = get_latest_folder_no(username)
            num = num + 1
        except:
            num = 1

        # Enters the folder, link, shortened link to the database.
        to_folder_rec(username, num, folder_name, link, short_link)

        # Randomises the files.
        proceed = sequence_files(username, num, folder_name)

        if proceed == 1:
            ui_.message_out(username, g_.s, 'Randomised List made.')
            return 1
        if proceed == 0:
            ui_.message_out(username, g_.e, 'Randomised List failed.')
            return 0

    else:
        ui_.message_out(username, g_.e, 'No folder name entered.')
        return 0
Пример #8
0
def run_service_1(username):
    # Service 1: Fetch photographs from the schedule and upload on Facebook.

    # Check if service 1 is active for the username.
    is_active = is_service_active('service_1', username)
    if is_active != 'active':
        ui_.message_out(username, g_.e, 'Service is not active.')
        return 0
    elif is_active == 'failed':
        ui_.message_out(username, g_.e,
                        'Could not connect to user_services database.')
        return 0
    else:
        ui_.message_out(
            username, g_.s,
            'Started the service "Upload to Facebook at regular interval."')
        print(g_.selected_fb_time)
        while is_active == 'active':

            curr_time = str(dt.datetime.now().hour) + ":" + str(
                dt.datetime.now().minute)
            if curr_time in g_.selected_fb_time:
                is_active = is_service_active('service_1', username)
                if is_active == 'active':
                    print("shob active ache.")
                    # Read from the scheduled csv file: Get folder no. and file path.
                    folder_und_path = find_next_photo(username)
                    print(folder_und_path)
                    if not folder_und_path:
                        print("No photographs to share")
                    if folder_und_path != '':
                        folder_no = folder_und_path[0]
                        photo_path = folder_und_path[1]
                        photo_available = is_photo_available(
                            username, photo_path)
                        if not photo_available:
                            ui_.message_out(username, g_.e,
                                            'No more photographs to share.')
                            folder_no = ''
                            photo_path = ''
                        elif photo_available[0] != 'works':
                            # If the photo is not available, choose the next available one.
                            folder_no = photo_available[0]
                            photo_path = photo_available[1]

                        if folder_no != '':
                            # Find the long link, short link.
                            long_link_und_short_link = find_links(
                                username, folder_no)
                            print(long_link_und_short_link)
                            long_link = long_link_und_short_link[0]
                            short_link = long_link_und_short_link[1]

                            # Fetch a description using the long link.
                            description = summarise.get_summary_description(
                                long_link, 'fb')

                            # Check if the shortened link exist.
                            if short_link != '':
                                description = description + " Check out more at " + short_link

                            # Upload the image with the description.
                            page_graph = f_.fb_page_graph_build(
                                g_.page_id, g_.client_token)
                            try:
                                with open(g_.root + 'temp_', "rb") as image:
                                    page_graph.put_photo(image=image,
                                                         message=description)
                                ui_.message_out(username, g_.s,
                                                'Uploaded: ' + str(photo_path))
                            except:
                                ui_.message_out(
                                    username, g_.e,
                                    'Upload failed: ' + str(photo_path))

                            # Delete the temporary file.
                            os.remove(g_.root + 'temp_')

                            # Mark the file as done.
                            mark_the_file_done(username, photo_path)

                            # Put to sleep for 59 seconds.
                            time.sleep(59)
        return 1
Пример #9
0
        proceed = func_sequence.add_user()
        if proceed != 0:
            ui_.message_out(proceed, g_.s, 'User created.')
    elif text == 'run':
        main_bg.run_service_1(user)
    elif text == 'activate_service_1':
        func_sequence.activate_service(user, 1)
        ui_.message_out(user, g_.s, user)
    else:
        ui_.message_out('', g_.e, text + ' is not a recognised command.')


if __name__ == '__main__':
    username = func_sequence.signin()
    if username != 'error':
        ok_continue = 1
        while ok_continue == 1:
            selection = input("Input the following options:\n"
                              "'add_folder' to add folder\n")
            main(username, selection)
            ok_continue = input("Would you want to continue? ")
            if ok_continue in g_.yes:
                ok_continue = 1
    else:
        ui_.message_out('', g_.e, 'Signing in failed.')
        ok_continue = input("Would you like to sign up?")
        if ok_continue in g_.yes:
            main('', 'sign_up')
        else:
            ui_.message_out('', g_.i, 'Bye.')