Exemplo n.º 1
0
def log_dl_event(dl_event_lbl_frm, day_cbox, schedule_event_cbtn_sel,
                 time_txt_box, am_pm_cbox, subreddit_cbox):

    log_d = {
        "event_name":
        event_name(dl_event_lbl_frm
                   ),  # remove the space at the start and the ': ' at the end
        "day": day_cbox.get(),
        "schedule_event": schedule_event_cbtn_sel.get(),
        "time": time_txt_box.get(),
        "am_pm": am_pm_cbox.get(),
        "subreddit_l": subreddit_cbox['values']
    }

    # print('in gui_commands, log_d: ', log_d)#```````````````````````````````````````````````````````````````````````

    dl_event_dl = get_dl_event_data_dl()

    # add to data if event already exists
    found = False
    for d_num, dl_event_d in enumerate(dl_event_dl):
        if dl_event_d['event_name'] == log_d['event_name']:
            found = True
            dl_event_dl[d_num] = log_d
            break

    # add new if event does not exist yet
    if found == False:
        dl_event_dl.append(log_d)

    json_logger.write(dl_event_dl, DL_SCHEDULE_JSON_PATH)
Exemplo n.º 2
0
def main():

    code_req_dl = [{
        'store_name': 'jimmy_johns',
        'value_quantity_tl': [(25, 2), (500, 1)]
    }, {
        'store_name': 'jets_pizza',
        'value_quantity_tl': [(25, 1)]
    }]

    confirmed_code_type_d, is_complete = get_confirmed_code_type_d__and_is_complete(
        code_req_dl)
    print(
        'confirmed_code_type_d: ', confirmed_code_type_d
    )  ###########``````````````````````````````````````````````````````````````````````````

    import json_logger
    json_logger.write(confirmed_code_type_d, 'test_output.json')

    print(
        'is_complete: ', is_complete
    )  #```````````````````````````````````````````````````````````````````````````````````````````````````
Exemplo n.º 3
0
    def _log_small_historical_data():
        file_system_utils.make_dir_if_not_exist(HISTORICAL_DATA_DIR_PATH)

        # make new log dir path
        now = datetime.datetime.now()
        date_time_str = now.strftime("%Y-%m-%d__%H_%M")
        new_log_dir_path = HISTORICAL_DATA_DIR_PATH + '/log__' + date_time_str

        # add new dir, delete old if exists
        file_system_utils.delete_if_exists(new_log_dir_path)
        os.mkdir(new_log_dir_path)

        # copy data from current_data to new dir in historical_data
        copy_path_l = [
            CURRENT_DATA_DIR_PATH + '/download_log.csv',
            CURRENT_DATA_DIR_PATH + '/pool_clips_data.csv',
            CURRENT_DATA_DIR_PATH + '/LOG_FILES'
        ]
        file_system_utils.copy_objects_to_dest(copy_path_l, new_log_dir_path)

        # get list of evaluated postIds
        pool_evaluated_post_id_l = []
        pool_clips_data_row_dl = logger.readCSV(CURRENT_DATA_DIR_PATH +
                                                '/pool_clips_data.csv')
        for row_d in pool_clips_data_row_dl:
            if row_d['status'] != '':
                pool_evaluated_post_id_l.append(row_d['postId'])


#         print(pool_evaluated_post_id_l)#``````````````````````````````````````````````````````````````````````````

# add pool_evaluated_post_id_l to existing list of evaluated post ids
        evaluated_post_id_l = get_evaluated_post_id_l()
        #         print(evaluated_post_id_l)#`````````````````````````````````````````````````````````````````````````
        json_logger.write(pool_evaluated_post_id_l + evaluated_post_id_l,
                          EVALUATED_POST_IDS_JSON_PATH)
Exemplo n.º 4
0
def del_dl_event(dl_event_lbl_frm):
    dl_event_dl = get_dl_event_data_dl()
    for d in dl_event_dl:
        if d['event_name'] == event_name(dl_event_lbl_frm):
            dl_event_dl.remove(d)
    json_logger.write(dl_event_dl, DL_SCHEDULE_JSON_PATH)
Exemplo n.º 5
0
def make_code_card(kwargs, test_mode):
    template_type = kwargs['template_type']
    store_name = kwargs['store_name']

    img_paths_to_delete_l = [
        get__test_mode_blank_store_template_img_path(store_name),
        get__test_mode_blank_template_img_path(template_type)
    ]
    if test_mode:
        # remove the needed box coords from the json file if it exists
        if fsu.is_file(TEMPLATE_BOX_COORDS_JSON_PATH):
            dim_template_box_coords_ddd = json_logger.read(
                TEMPLATE_BOX_COORDS_JSON_PATH)

            if TEMPLATE_DIMS_STR in dim_template_box_coords_ddd:
                dim_template_box_coords_ddd.pop(TEMPLATE_DIMS_STR)

                json_logger.write(dim_template_box_coords_ddd,
                                  TEMPLATE_BOX_COORDS_JSON_PATH)

        # remove imgs so they get re-made
#         img_paths_to_delete_l = [get__normalized_color_template_img_path(template_type),
#                                  get__blank_template_img_path(template_type),
#                                  get__blank_store_template_img_path(store_name)]
        img_paths_to_delete_l.append(
            get__normalized_color_template_img_path(template_type))
        img_paths_to_delete_l.append(
            get__blank_template_img_path(template_type))
        img_paths_to_delete_l.append(
            get__blank_store_template_img_path(store_name))

    img_paths_to_delete_l.append(
        get__test_mode_blank_store_template_img_path(store_name))
    img_paths_to_delete_l.append(
        get__test_mode_blank_template_img_path(template_type))

    for img_path in img_paths_to_delete_l:
        fsu.delete_if_exists(img_path)

    # get template_type_box_coords from json file
    # if the json file does not exist, it will be created
    # if the box_coords are not in the json file, they will be loaded from the normalized_color_template_img
    # if the normalized_color_template_img does not exist, it will be created from the user-made color_template_img
    print('  Getting template_type_box_coords...')
    template_type_box_coords = get_template_type_box_coords(template_type)

    for box_title, box_coords in template_type_box_coords.items():
        print(box_title + ' : ' + str(box_coords))

    # get blank_store_template_img from path
    # if blank_store_template image does not exist, make it
    # if blank_template_img does not already exist, it will be created in the process
    print('  Getting blank_store_template_img...')
    if test_mode:
        blank_store_template_img_path = get__test_mode_blank_store_template_img_path(
            store_name)
    else:
        blank_store_template_img_path = get__blank_store_template_img_path(
            store_name)

    print('blank_store_template_img_path: ', blank_store_template_img_path
          )  #```````````````````````````````````````````````````````````

    if not fsu.is_file(blank_store_template_img_path):
        print(
            '    Blank_store_template_img does not exist, creating it now...')
        make_new_blank_store_template(kwargs, template_type_box_coords,
                                      test_mode)


#     else:
    blank_store_template_img = pu.open_img(blank_store_template_img_path)
    #     blank_store_template_img.show()

    print('  Making new code_card_img...')
    return make_new_code_card(kwargs, template_type_box_coords,
                              blank_store_template_img)
Exemplo n.º 6
0
def get_template_type_box_coords(template_type):
    color_template_img_path = get__color_template_img_path(template_type)
    normalized_color_template_img_path = get__normalized_color_template_img_path(
        template_type)
    # read in data from json file if it exists
    if fsu.is_file(TEMPLATE_BOX_COORDS_JSON_PATH):
        dim_template_box_coords_ddd = json_logger.read(
            TEMPLATE_BOX_COORDS_JSON_PATH)
    else:
        dim_template_box_coords_ddd = {}

    # add template dims to ddd if not already exist
    if TEMPLATE_DIMS_STR not in dim_template_box_coords_ddd:
        dim_template_box_coords_ddd[TEMPLATE_DIMS_STR] = {}


#         template_box_coords_dd = dim_template_box_coords_ddd[TEMPLATE_DIMS_STR]

# add template_type if needed
    if template_type not in dim_template_box_coords_ddd[TEMPLATE_DIMS_STR]:
        dim_template_box_coords_ddd[TEMPLATE_DIMS_STR][template_type] = {}

    # if box coords don't already exist for template type, get them from image, also log in json file
    if dim_template_box_coords_ddd[TEMPLATE_DIMS_STR][template_type] == {}:
        #             color_template_img_path = TEMPLATE_DIMS_DIR_PATH + '\\color_template__' + template_type + '.JPG'

        # raise exception if color template img does not exist
        if not fsu.is_file(color_template_img_path):
            raise Exception(
                'ERROR:  color_template_img_path does not exist: ',
                color_template_img_path,
                '/ncannot get box_coords, maybe add a good way of adding new color templates here'
            )

        # normalize the colors of the original color_template_img if not already done
        if not fsu.is_file(normalized_color_template_img_path):
            print(
                '  Normalized_color_template_img does not exist, creating it now...'
            )
            img = pu.open_img(color_template_img_path)
            # power point likes to add new colors to images so first, need to normalize all colors by dominant -
            # meaning that if you have 100 (255, 255, 255) pixels and 50 (255, 255, 254) pixels, replace all with (255, 255, 255)
            print(
                '    Normalizing colors of original color_template_img by dominant...'
            )
            img = pu.normalize_colors__by_dominant(img,
                                                   COLOR_NORMILIZATION_FACTOR)

            # sometimes the new colors added by power point out-number the original colors, so use same method to normalize
            # all colors in img to the list of box colors
            box_color_l = TEMPLATE_COLORS_DD[template_type].values()
            print('    Normalizing those colors by list...')
            img = pu.normalize_colors__by_l(img, box_color_l,
                                            COLOR_NORMILIZATION_FACTOR)

            print('    Saving new normalized_color_template_img at ',
                  normalized_color_template_img_path, '...')
            img.save(normalized_color_template_img_path)

        # get box coords from normalized_color_template_img
        normalized_color_template_img = pu.open_img(
            normalized_color_template_img_path)
        print('  Getting box coords from normalized_color_template_img...')
        box_coords = pu.get_box_coords_d(normalized_color_template_img,
                                         TEMPLATE_COLORS_DD[template_type])
        #         print(box_coords)#```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````

        dim_template_box_coords_ddd[TEMPLATE_DIMS_STR][
            template_type] = box_coords
        json_logger.write(dim_template_box_coords_ddd,
                          TEMPLATE_BOX_COORDS_JSON_PATH)

    return dim_template_box_coords_ddd[TEMPLATE_DIMS_STR][template_type]