def get_each_imginfo_list(images_info, f_num):
    std_shortcode = ''

    # initialize info list
    f_gps = f_gps_detail = ''

    
    for info in images_info:

        try:

            # parsed 'info'
            f_filename, f_shortcode, f_category, f_extension = file_util.parse_filename(info)

            # only need a txt file
            if (f_extension != '.txt') or ('old' in f_category): 

                # move to 'after' folder
                file_util.move_file(f_filename, parameters.images_info_before_path, parameters.images_info_after_path)
                continue

            ## [File Type1] {date}!{shortcode}.txt
            if f_category == '':
                # if this is the 1st iteration
                if std_shortcode == '': 
                    std_shortcode = f_shortcode
                    f_date, f_like, f_comment, f_hashtag = get_txt_info(info, f_filename)

                elif (std_shortcode != '') and (std_shortcode == f_shortcode):
                    f_date, f_like, f_comment, f_hashtag = get_txt_info(info, f_filename)
                        
            ##


            ## [File Type2] {date}!{shortcode}_location.txt
            if f_category == '_location':
                # if this is the 1st iteration
                if std_shortcode == '':
                    std_shortcode = f_shortcode
                    f_gps, f_gps_detail = get_gps_info(info, f_filename)

                elif (std_shortcode != '') and (std_shortcode == f_shortcode):
                    f_gps, f_gps_detail = get_gps_info(info, f_filename)

            ##

            

        except:
            print('ERROR:', info)

    # combine a whole extracted information with 'imginfo_list'
    # imginfo_list = [filenumber, shortcode, date, like, comment, hashtag, gps, gps detail]
    imginfo_list = [f_num, std_shortcode, f_date, f_like, f_comment, f_hashtag, f_gps, f_gps_detail]

    return imginfo_list
def get_gps_info(info, filename):
    # read a file
    with open(info, 'r') as f:
        data = f.readlines()
        f_gps = data[0].split('\n')[0]
        f_gps_detail = data[1]

    # move to 'after' folder
    file_util.move_file(filename, parameters.images_info_before_path, parameters.images_info_after_path)

    return f_gps, f_gps_detail
Exemplo n.º 3
0
def check_data(img_dir, unqualified_dir):
    """
    检查图片
    :param img_dir:
    :param unqualified_dir:
    :return:
    """
    if not os.path.exists(unqualified_dir):
        os.makedirs(unqualified_dir)
    total = 0
    unqualified = 0
    for root, dirs, files in os.walk(img_dir):
        for img in files:
            total += 1
            print(img)
            if not img_util.is_img(img):
                file_util.move_file(os.path.join(root, img), unqualified_dir)
                unqualified += 1
    print("total={0}, unqualified={1}".format(total, unqualified))
def get_txt_info(info, filename):

    # read a file
    with open(info, 'r') as f:
        data = f.read()

        # data format : date_utc:{date_utc}\ncaption:{caption}\nlikes:{likes}\ncomments:{comments}
        parsed_data = data.split('\\n')

        f_date = parsed_data[0].split('date_utc')[1][1:]
        f_like = parsed_data[2].split('likes')[1][1:]
        f_comment = parsed_data[3].split('comments')[1][1:].split('\n')[0]
            
        # count the number of '#' in caption
        f_hashtag = parsed_data[1].count('#')

    # move to 'after' folder
    file_util.move_file(filename, parameters.images_info_before_path, parameters.images_info_after_path)

    return f_date, f_like, f_comment, f_hashtag
def separate_img_imginfo(images_before):

    for f in images_before:

        try:
        
            f_filename, _, f_category, f_extension = file_util.parse_filename(f)

            if f_extension != '.jpg': continue

            # if file is a image
            if f_category == '':
                file_util.move_file(f_filename, parameters.images_info_before_path, parameters.images_before_path) 
                continue

            if f_category.split('_')[1].isdigit():
                file_util.move_file(f_filename, parameters.images_info_before_path, parameters.images_before_path) 

        except:
            print('ERROR:', f)
Exemplo n.º 6
0
                    img_animal = 1

                # check: person?
                if ('person' in t) or ('people' in t):
                    img_person = 1
            ##


            # combine all info
            img_analysislist = [f_num, f_filename, f_shortcode, img_food, img_animal, img_person, img_color, img_tag]

            ###


            # move this img to after-analysis folder
            file_util.move_file(f_filename, parameters.images_before_path, parameters.images_after_path)

            # write in a csv file
            colname_names = ''
            if f_num == 1:
                colname_names = ['num', 'file name', 'shortcode', 'food[1] / non-food[0]', 'animal[1] / non-animal[0]', 
                                'person[1] / non-person[0]', 'dominant color', 'all tags'] 
                
            row_list = [img_analysislist]
            file_util.write_list_to_csv(colname_names, row_list, parameters.f2_path, 1) 

            # increase filenumber
            f_num += 1

        except:
            print('ERROR:', img)
Exemplo n.º 7
0
                         patch['name'])
                    failed_patches[patch['name']] = failed_lines
                    continue

                if options.restore:
                    # Restore from backup if a backup exists.
                    for patch_path in patch_paths:
                        patch_path_abs = os.path.abspath(os.path.join(patch_root_abs, \
                                                                      patch_path))
                        backup_path_abs = patch_path_abs + backup_ext
                        if os.path.exists(backup_path_abs):
                            if read_file(patch_path_abs) == read_file(
                                    backup_path_abs):
                                msg('Restoring backup of %s' % patch_path_abs)
                                remove_file(patch_path_abs)
                                move_file(backup_path_abs, patch_path_abs)
                            else:
                                msg('Discarding backup of %s' % patch_path_abs)
                                remove_file(backup_path_abs)
                                has_backup_changes = True
                        else:
                            msg('No backup of %s' % patch_path_abs)

        if (not options.revert and not options.reapply) or has_backup_changes:
            if len(options.add) > 0:
                # Add additional requested files to the patch.
                for patch_path in options.add:
                    patch_path_abs = os.path.abspath(os.path.join(patch_root_abs, \
                                                                  patch_path))
                    if os.path.exists(patch_path_abs):
                        msg('Adding file %s' % patch_path_abs)
Exemplo n.º 8
0
          warn('Failed to apply %s, fix manually and run with --resave' % \
               patch['name'])
          failed_patches[patch['name']] = failed_lines
          continue

        if options.restore:
          # Restore from backup if a backup exists.
          for patch_path in patch_paths:
            patch_path_abs = os.path.abspath(os.path.join(patch_root_abs, \
                                                          patch_path))
            backup_path_abs = patch_path_abs + backup_ext
            if os.path.exists(backup_path_abs):
              if read_file(patch_path_abs) == read_file(backup_path_abs):
                msg('Restoring backup of %s' % patch_path_abs)
                remove_file(patch_path_abs)
                move_file(backup_path_abs, patch_path_abs)
              else:
                msg('Discarding backup of %s' % patch_path_abs)
                remove_file(backup_path_abs)
                has_backup_changes = True
            else:
              msg('No backup of %s' % patch_path_abs)

    if (not options.revert and not options.reapply) or has_backup_changes:
      if len(options.add) > 0:
        # Add additional requested files to the patch.
        for patch_path in options.add:
          patch_path_abs = os.path.abspath(os.path.join(patch_root_abs, \
                                                        patch_path))
          if os.path.exists(patch_path_abs):
            msg('Adding file %s' % patch_path_abs)