def main():
    """Main"""
    # Connect to database
    cursor = database.get_dbcursor()
    
    # Decide how many days back to scan
    if (sys.version_info >= (3, 0)):
        num_days = int(input("How many days back would you like to scan? [7]") or 7)
    else:
        num_days = int(raw_input("How many days back would you like to scan? [7]") or 7)
    
    start_date = datetime.datetime.utcnow() - datetime.timedelta(num_days)
    
    # Get list of Youtube ids to check
    ids = get_youtubeids(cursor, start_date)
    
    print("Scanning %d matched video entries..." % len(ids));
       
    # Find videos that no longer exist on YouTube
    # Check videos several times to make sure it isn't just
    # a network problem.
    to_remove = find_missing_videos(cursor, ids)
    print("Scan 1 - Found %d candidate missing videos" % len(to_remove))
    for i in range(10):
        to_remove = find_missing_videos(cursor, to_remove)
        print("Scan %d - Found %d candidate missing videos" % (i + 2, len(to_remove)))
    # Stop if no matches found
    if len(to_remove) is 0:
        print("No missing videos found. Exiting script.")
        sys.exit()
            
    # Confirm with user before removing
    print("Videos to be removed: ")
    for x in to_remove:
        print (x)
    print("Total: %d" % len(to_remove))
    
    if (sys.version_info >= (3, 0)):
        choice = input("Are you sure you want to remove these videos from the database? ")
    else:
        choice = raw_input("Are you sure you want to remove these videos from the database? ")
        
    while choice.lower() not in ["yes", "y", "no", "n"]:
        if (sys.version_info >= (3, 0)):
            choice = input("Please enter yes or no ")
        else:
            choice = raw_input("Please enter yes or no ")
        
    if choice in ["n", "no"]:
        sys.exit("Exiting without making any changes.")
        
    # Once confirmed, remove all videos found to be missing
    # Default param style (MySQLdb.paramstyle) is 'format' so %s is used 
    sql = "DELETE FROM youtube WHERE youtubeId IN (%s)" % ','.join(['%s'] * len(to_remove))
    cursor.execute(sql, to_remove)
        
    print("===========")
    print(" Summary")
    print("===========")
    print("Number of movies removed: %d / %d" % (len(to_remove), len(ids)))
Example #2
0
def main():
    """Main"""
    # Connect to database
    cursor = database.get_dbcursor()

    # Decide how many days back to scan
    num_days = int(
        raw_input("How many days back would you like to scan? [7]") or 7)
    start_date = datetime.datetime.utcnow() - datetime.timedelta(num_days)

    # Get list of Youtube ids to check
    ids = get_youtubeids(cursor, start_date)

    print("Scanning %d matched video entries..." % len(ids))

    # Find videos that no longer exist on YouTube
    # Check videos several times to make sure it isn't just
    # a network problem.
    to_remove = find_missing_videos(cursor, ids)
    print("Scan 1 - Found %d candidate missing videos" % len(to_remove))
    for i in range(10):
        to_remove = find_missing_videos(cursor, to_remove)
        print("Scan %d - Found %d candidate missing videos" %
              (i + 2, len(to_remove)))
    # Stop if no matches found
    if len(to_remove) is 0:
        print("No missing videos found. Exiting script.")
        sys.exit()

    # Confirm with user before removing
    print("Videos to be removed: ")
    for x in to_remove:
        print x
    print("Total: %d" % len(to_remove))

    choice = raw_input(
        "Are you sure you want to remove these videos from the database? ")
    while choice.lower() not in ["yes", "y", "no", "n"]:
        choice = raw_input("Please enter yes or no ")

    if choice in ["n", "no"]:
        sys.exit("Exiting without making any changes.")

    # Once confirmed, remove all videos found to be missing
    # Default param style (MySQLdb.paramstyle) is 'format' so %s is used
    sql = "DELETE FROM youtube WHERE youtubeId IN (%s)" % ','.join(
        ['%s'] * len(to_remove))
    cursor.execute(sql, to_remove)

    print("===========")
    print(" Summary")
    print("===========")
    print("Number of movies removed: %d / %d" % (len(to_remove), len(ids)))
def main(argv):
    rootdir = "/var/www/jp2"
    moveto  = "/var/www/jp2/Corrupted"
    
    # Make sure at least one file was specified
    if len(argv) < 2:
        print "Incorrect number of arguments. Please specify the names of the files you wish to remove."
        sys.exit()
        
    # Connect to database
    cursor = database.get_dbcursor()
        
    for filename in argv[1:]:
        filepath = remove_from_db(cursor, rootdir, filename)
        remove_from_archive(filepath, moveto)    
    
    print "Done!"
Example #4
0
def main():
    # Connect to database
    cursor = database.get_dbcursor()
    
    # Get search path
    input_ = raw_input("Enter a directory or path to a list of files to check: ")
    corrupt_dir = "/var/www/jp2/Corrupted"
    
    # Get search criterion (e.g. CDELT < 0.01 or IMG_TYPE = DARK)
    filter_key = raw_input("Header key: ")
    filter_op = raw_input("Operator [=, ~=, <, <=, >, >=, or CONTAINS]: ").lower()
    
    while filter_op not in ["=", "<", ">", "<=", ">=", "contains"]:
        print ("Invalid operator specified. Please try again.")
        filter_op = raw_input("Operator [=, ~=, <, <=, >, >=, or CONTAINS]: ")

    filter_val = raw_input("Value: ")

    # Get a list of files to search
    if os.path.isdir(input_):
        images = find_images(input_)
    else:
        images = [i.rstrip() for i in open(input_)]
    
    print("Scanning %d images..." % len(images))
    
    # Filter image list based on criterion
    quarantine = filter_images(images, filter_key, filter_op, filter_val)
    
    if len(quarantine) is 0:
        print("No matches found!")
    
    # Remove quarantined images
    print ("Found %d images matching the criterion. " % len(quarantine))
    
    choice = raw_input("Are you sure you want to remove them? [y/n] ")
    
    while choice not in ["y", "n"]:
        print ("Invalid choice. Please choice y or n")
        choice = raw_input("\nAre you sure you want to remove them? [y/n] ")
    
    for file_ in quarantine:
        filepath = remove.remove_from_db(cursor, root_dir, os.path.basename(file_))
        remove.remove_from_archive(filepath, corrupt_dir)
    
    print("Finished!")
Example #5
0
def main(argv):
    rootdir = "/var/www/jp2"
    moveto = "/var/www/jp2/Corrupted"

    # Make sure at least one file was specified
    if len(argv) < 2:
        print "Incorrect number of arguments. Please specify the names of the files you wish to remove."
        sys.exit()

    # Connect to database
    cursor = database.get_dbcursor()

    for filename in argv[1:]:
        filepath = remove_from_db(cursor, rootdir, filename)
        remove_from_archive(filepath, moveto)

    print "Done!"
Example #6
0
def main():
    # Connect to database
    cursor = database.get_dbcursor()

    # Get search path
    input_ = raw_input("Enter a directory or path to a list of files to check: ")
    corrupt_dir = "/var/www/jp2/Corrupted"

    # Get search criterion (e.g. CDELT < 0.01 or IMG_TYPE = DARK)
    filter_key = raw_input("Header key: ")
    filter_op = raw_input("Operator [=, ~=, <, <=, >, >=, or CONTAINS]: ").lower()

    while filter_op not in ["=", "<", ">", "<=", ">=", "contains"]:
        print("Invalid operator specified. Please try again.")
        filter_op = raw_input("Operator [=, ~=, <, <=, >, >=, or CONTAINS]: ")

    filter_val = raw_input("Value: ")

    # Get a list of files to search
    if os.path.isdir(input_):
        images = find_images(input_)
    else:
        images = [i.rstrip() for i in open(input_)]

    print("Scanning %d images..." % len(images))

    # Filter image list based on criterion
    quarantine = filter_images(images, filter_key, filter_op, filter_val)

    if len(quarantine) is 0:
        print("No matches found!")

    # Remove quarantined images
    print("Found %d images matching the criterion. " % len(quarantine))

    choice = raw_input("Are you sure you want to remove them? [y/n] ")

    while choice not in ["y", "n"]:
        print("Invalid choice. Please choice y or n")
        choice = raw_input("\nAre you sure you want to remove them? [y/n] ")

    for file_ in quarantine:
        filepath = remove.remove_from_db(cursor, root_dir, os.path.basename(file_))
        remove.remove_from_archive(filepath, corrupt_dir)

    print("Finished!")