def load_vars_and_apply_replacements():
    project_vars_d = json_logger.read(VARS_JSON_PATH)
    for key, val in project_vars_d.items():
        for str_to_replace, replacement_str in STR_REPLACE_D.items():
            if str_to_replace in val:
                # print('FOUND STR TO REPLACE, val: ', val)#`````````````````````````````````````````````````
                project_vars_d[key] = val.replace(str_to_replace,
                                                  replacement_str)
                # print('val after replace: ', val, val.replace(str_to_replace, replacement_str))#``````````````````````````````````````````````````
    return project_vars_d
Пример #2
0
def main():
    os.chdir('C:\\Users\\Brandon\\Documents\\Personal_Projects\\vid_m_comp'
             )  # not sure if this is needed for startup folder method

    dl_schedule_dl = json_logger.read(DL_SCHEDULE_JSON_PATH)
    dl_event_l = build_dl_event_l(dl_schedule_dl)
    #     for dl_event in dl_event_l:
    #         print(dl_event.event_name, dl_event.dl_date, dl_event.dl_datetime)

    scheduled_dl_event_l = get_scheduled_dl_event_l(dl_event_l)

    if len(scheduled_dl_event_l) == 0:
        print('no dl events scheduled')
    else:
        soonest_dl_event = get_soonest_dl_event(scheduled_dl_event_l)

        print('The next download event is: ', soonest_dl_event.descrip_str())
        wait_sec = soonest_dl_event.sec_until_dl()
        print('sleeping for', wait_sec, 'seconds...')
        time.sleep(wait_sec)
        import download_vids
        download_vids.download_vids(300, soonest_dl_event.subreddit_l,
                                    'overwrite')
        main()
Пример #3
0
def get_dl_event_data_dl():
    if os.path.isfile(DL_SCHEDULE_JSON_PATH):
        dl_event_dl = json_logger.read(DL_SCHEDULE_JSON_PATH)
    else:
        dl_event_dl = []
    return dl_event_dl
Пример #4
0
def get_gui_vars():
    return json_logger.read(GUI_VARS_JSON_FILE_PATH)
Пример #5
0
def get_evaluated_post_id_l():
    try:
        evaluated_post_id_l = json_logger.read(EVALUATED_POST_IDS_JSON_PATH)
    except FileNotFoundError:
        evaluated_post_id_l = []
    return evaluated_post_id_l
Пример #6
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)
Пример #7
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]