Skip to content

Instantly share code, notes, and snippets.

@ngeraci
Last active November 29, 2018 02:17
Show Gist options
  • Save ngeraci/91b36587e751541ee4495b6ab228671b to your computer and use it in GitHub Desktop.
Save ngeraci/91b36587e751541ee4495b6ab228671b to your computer and use it in GitHub Desktop.
for a given collection, open a random sample of calisphere-test pages in a web browser (for qc)
"""
This script takes a collection's CDL registry number and the number of items in a collection, and
opens calisphere-test tabs in a web browser representing a specified percentage of the collection's
total pages.
"""
import argparse
import math
import random
import sys
import webbrowser as wb
def main(args=None):
"""Parse command line arguments and pass their values to calisphere_page_qc().
"""
parser = argparse.ArgumentParser(
description='''within a given collection, use a web browser to open a random selection of
x percent of the collection's pages in calisphere-test''')
parser.add_argument("collection_number", type=int, nargs=1,
help='''Collection's CDL registry number''')
parser.add_argument("item_count", type=int, nargs=1,
help='''total number of digital objects in the collection''')
parser.add_argument("qc_percent", type=int, nargs='?', default=10,
help='''percentage of pages to QC, as a whole number.
To check 15%%, use 15.
If no value supplied, default is 10.''')
# print help if no args given
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
# parse
if args is None:
args = parser.parse_args()
calisphere_page_qc(args.collection_number[0], args.item_count[0], args.qc_percent)
def calisphere_page_qc(collection_number, item_count, qc_percent):
# how many pages does this collection have in Calisphere?
# divide by 24 (default item count per page) and round up
page_count = int(math.ceil(item_count/24))
print("Collection contains", page_count, "pages")
# how many pages do we need to check to check 1/10 of the pages? (round up)
percent = int(math.ceil(qc_percent/100 * page_count))
print("Opening", percent, "pages for QC.")
# a sorted list of random pages within page_count with len(percent)
check_pages = sorted(random.sample(range(1, page_count), percent))
for page in check_pages:
# generate "start" value for url
start = (page - 1) * 24
# make calisphere-test url
url = "".join(["http://calisphere-test.cdlib.org/collections/", str(collection_number),
"?start=", str(start)])
wb.open_new_tab(url)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment