本文整理汇总了Python中database.DatabaseManager.add_to_citation_table方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.add_to_citation_table方法的具体用法?Python DatabaseManager.add_to_citation_table怎么用?Python DatabaseManager.add_to_citation_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.add_to_citation_table方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: citation_add
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import add_to_citation_table [as 别名]
def citation_add(cite_type):
clean_params = dict([(k, v) for k, v in request.form.items() if not v or v != 'None'])
if cite_type == GAME_CITE_REF:
cite = generate_cite_ref(GAME_CITE_REF, GAME_SCHEMA_VERSION, **clean_params)
elif cite_type == PERF_CITE_REF:
cite = generate_cite_ref(PERF_CITE_REF, PERF_SCHEMA_VERSION, **clean_params)
dbm.add_to_citation_table(cite, fts=True)
return redirect(url_for('citation_page', uuid=cite['uuid']))
示例2: search_globally_with_game_partial
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import add_to_citation_table [as 别名]
def search_globally_with_game_partial(citation_partial):
citations = []
NEW = 'new'
OLD = 'old'
@coroutine
def process_citation_url():
while True:
url = (yield)
if not dbm.is_attr_in_db('source_url', url, dbm.GAME_CITATION_TABLE):
click.echo('Extracting url {} through coroutine.'.format(url))
extractor = get_extractor_for_uri(url, get_url_source(url))
extractor.extract()
citation, extracted_options = extractor.create_citation()
citations.append((citation, NEW))
else:
click.echo('Found {} in local db.'.format(url))
citation = dbm.create_cite_ref_from_db(GAME_CITE_REF,
dbm.retrieve_attr_from_db(
'source_url',
url,
dbm.GAME_CITATION_TABLE)[0])
citations.append((citation, OLD))
# Currently this search is only through MobyGames, may work on federated search
# in the future. Also only searches on title for now
# Just need the extractor, don't need its state
search_string = citation_partial['description']['title']
limit = citation_partial['limit'] if 'limit' in citation_partial else None
search_uris = get_extractor_for_uri('http://www.mobygames.com', None).get_search_uris(search_string)
if limit and limit <= len(search_uris) - 1:
search_uris = search_uris[:limit]
# Process coroutine
# Send uris to coroutine generator
for uri in search_uris:
process_citation_url().send(uri)
# Block until all the search citations return
while len(citations) != len(search_uris):
pass
for c in citations:
if c[1] == NEW:
dbm.add_to_citation_table(c[0], fts=True)
return [c for c, _ in citations]
示例3: performance_add
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import add_to_citation_table [as 别名]
def performance_add(uuid):
record = json.loads(request.form.get('record'))
perf_ref = generate_cite_ref(PERF_CITE_REF, PERF_SCHEMA_VERSION, game_uuid=uuid, **record)
dbm.add_to_citation_table(perf_ref, fts=True)
return jsonify({'record': perf_ref.elements})
示例4: extract_uri
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import add_to_citation_table [as 别名]
def extract_uri(ctx, uri):
verbose = ctx.obj['VERBOSE']
no_prompts = ctx.obj['NO_PROMPTS']
source_name = get_uri_source_name(uri)
if source_name:
cond_print(verbose, "Starting extraction of {} source".format(source_name))
else:
click.echo("Could not find extractor for given uri:{}. Goodbye!".format(uri))
sys.exit(1)
try:
source = get_url_source(uri)
except SourceError as e:
click.echo(e.message)
sys.exit(1)
extractor = get_extractor_for_uri(uri, source)
cond_print(verbose, "Using {} for extraction".format(extractor.__class__.__name__))
# Check for duplicate entries, by url from source, this is needed since there might be a redirect from the
# input uri, like http -> https. Could check this in the extractor or tell the user that the url is changing.
# Though if the redirect always happens it wouldn't matter anyway, since the database retains the redirected url
cond_print(verbose, 'Checking for duplicates...')
if not no_prompts and has_potential_duplicates(source.url, 'source_uri', dbm.EXTRACTED_TABLE):
if settle_for_duplicate(source.url, 'source_uri', dbm.EXTRACTED_TABLE):
sys.exit(1)
cond_print(verbose, 'Validating URI...')
# Check if this is a game url for extraction
if not extractor.validate():
if no_prompts or not click.confirm('This doesn\'t appear to be a game related uri. Extract anyway?'):
sys.exit(1)
cond_print(verbose, 'Extracting URI...')
# These are separate since file downloads might rely on subprocesses
try:
extractor.extract()
except ExtractorError as e:
click.echo(e.message)
sys.exit(1)
# Block until extraction complete, needed for anything requiring sub-processes
while not extractor.extracted_info:
pass
extracted_info = extractor.extracted_info
# Create citation from extracted information
if no_prompts or click.confirm('Create citation from extracted data?'):
citation, extracted_options = extractor.create_citation()
if not no_prompts:
citation = get_citation_user_input(citation, extracted_options)
if citation.ref_type == GAME_CITE_REF:
alternate_citation = choose_game_citation(search_locally_with_citation(citation))
elif citation.ref_type == PERF_CITE_REF:
alternate_citation = choose_performance_citation(search_locally_with_citation(citation))
if not alternate_citation:
dbm.add_to_citation_table(citation, fts=True)
click.echo('Citation added to database.')
else:
dbm.add_to_citation_table(citation, fts=True)
if 'errors' not in extracted_info and dbm.add_to_extracted_table(extracted_info):
cond_print(verbose, "Extraction Successful!")
if not no_prompts:
summary_prompt(extracted_info)
else:
cond_print(verbose, "Extraction Failed!")
pprint.pprint(extracted_info)
示例5: cite_performance
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import add_to_citation_table [as 别名]
def cite_performance(ctx, export, file_path, url, partial, schema_version):
verbose = ctx.obj['VERBOSE']
no_prompts = ctx.obj['NO_PROMPTS']
alternate_citation = None
# Make sure that only one input flag is used
if sum(map(lambda x: 1 if x else 0, [file_path, url, partial])) > 1:
click.echo('Please use only one option for citation source data.')
click.echo('Usage:\n\t{} --file_path PATH_TO_FILE\n\t{} --url URL\n\t{} --partial JSON_OBJECT'.format('cite_performance'))
sys.exit(1)
if not file_path and not url and not partial:
if no_prompts:
cond_print(verbose, 'Cannot create a blank citation with no-prompts flag active.')
cond_print(verbose, 'Creating a new citation...')
citation = get_citation_user_input(generate_cite_ref(PERF_CITE_REF, PERF_SCHEMA_VERSION))
cond_print(verbose, 'Searching for similar citations...')
alternate_citation = choose_performance_citation(search_locally_with_citation(citation))
if file_path:
extractor = get_extractor_for_file(os.path.expanduser(file_path))
try:
extractor.extract()
except ExtractorError as e:
click.echo(e.message)
sys.exit(1)
citation, extracted_options = extractor.create_citation()
if not no_prompts:
citation = get_citation_user_input(citation, extracted_options)
alternate_citation = search_locally_with_citation(citation)
elif url:
try:
source = get_url_source(url)
except SourceError as e:
click.echo(e.message)
sys.exit(1)
extractor = get_extractor_for_uri(url, source)
try:
extractor.extract()
except ExtractorError as e:
click.echo(e.message)
sys.exit(1)
# Block while waiting for extraction to finish, necessary for video downloads
while not extractor.extracted_info:
pass
citation, extracted_options = extractor.create_citation()
if not no_prompts:
citation = get_citation_user_input(citation, extracted_options)
alternate_citation = choose_game_citation(search_locally_with_citation(citation))
elif partial:
partial_json = json.loads(partial)
# Create citation based on partial description
citation = generate_cite_ref(PERF_CITE_REF, PERF_SCHEMA_VERSION, **partial_json['description'])
# Search locally based on partial description
if not no_prompts:
alternate_citation = choose_performance_citation(search_locally_with_citation(citation))
if alternate_citation:
citation = alternate_citation
else:
if citation:
dbm.add_to_citation_table(citation, fts=True)
if export and citation:
click.echo(citation.to_json_string())
示例6: cite_game
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import add_to_citation_table [as 别名]
#.........这里部分代码省略.........
if executable:
options['main_executable'] = executable
# If there's additional information from a partial, load it
if partial:
partial_json = json.loads(partial)
citation = generate_cite_ref(GAME_CITE_REF, GAME_SCHEMA_VERSION, **partial_json['description'])
else:
citation = generate_cite_ref(GAME_CITE_REF, GAME_SCHEMA_VERSION, title=directory.split('/')[-1])
# Get input if prompts are allowed
if not no_prompts:
citation = get_citation_user_input(citation)
alternate_citation = choose_citation(search_locally_with_citation(citation))
# Extract all the files and paths
try:
extractor.extract(options=options)
except ExtractorError as e:
click.echo(e.message)
sys.exit(1)
# Add file_paths to game data store if this is a new citation
file_info = extractor.extracted_info['file_info']
if not alternate_citation:
for fd in file_info:
fd['game_uuid'] = citation['uuid']
dbm.insert_into_table(dbm.GAME_FILE_PATH_TABLE, fd.keys(), fd.values())
else:
# Clean up extracted data if alternate citation found (only for prompts call)
for fd in file_info:
shutil.rmtree(os.path.join(LOCAL_GAME_DATA_STORE, fd['source_data'], fd['file_path'].split('/')[-1]))
# URL citation
elif url:
try:
source = get_url_source(url)
except SourceError as e:
click.echo(e.message)
sys.exit(1)
extractor = get_extractor_for_uri(url, source)
try:
extractor.extract()
except ExtractorError as e:
click.echo(e.message)
sys.exit(1)
# Block if this is a link to a video or other extractor process
while not extractor.extracted_info:
pass
citation, extracted_options = extractor.create_citation()
if not no_prompts:
citation = get_citation_user_input(citation, extracted_options)
alternate_citation = choose_game_citation(search_locally_with_citation(citation))
# TITLE citation
elif title:
if no_prompts:
cond_print(verbose, 'Cannot do citation by title with no-prompts flag active.')
sys.exit(1)
# Try a local citation search
alternate_citation = choose_game_citation(search_locally_with_game_title(title))
citation = None
# If that didn't work try to search internet
# Current hard-coded limit as 10, may allow flag for future
if not alternate_citation:
citation = choose_game_citation(search_globally_with_game_title(title, limit=10))
# If that didn't work, make a new citation
if not citation and not alternate_citation:
citation = generate_cite_ref(GAME_CITE_REF,
GAME_SCHEMA_VERSION,
title=title)
# Edit the citation if needed
citation = get_citation_user_input(citation)
# PARTIAL citation
elif partial:
partial_json = json.loads(partial)
# Create citation based on partial description
citation = generate_cite_ref(GAME_CITE_REF, GAME_SCHEMA_VERSION, **partial_json['description'])
if not no_prompts:
# Search locally based on partial description
alternate_citation = choose_game_citation(search_locally_with_citation(citation))
# Search globally if that didn't work
if not alternate_citation:
citation = choose_game_citation(search_globally_with_game_partial(partial_json))
# If an alternate was found, don't do anything
if alternate_citation:
citation = alternate_citation
else:
# Add the new citation to the database
if citation:
dbm.add_to_citation_table(citation, fts=True)
if export and citation:
click.echo(citation.to_json_string())
示例7: extract_file
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import add_to_citation_table [as 别名]
def extract_file(ctx, path_to_file, partial_citation):
verbose = ctx.obj['VERBOSE']
no_prompts = ctx.obj['NO_PROMPTS']
source_name = get_file_source_name(path_to_file)
# Convert to full path if needed
full_path = os.path.join(os.getcwd(), path_to_file) if not os.path.isabs(path_to_file) else path_to_file
# Check if there's actually a file there
if not os.path.isfile(full_path):
click.echo("There doesn\'t appear to be a readable file at:{}.\nExiting.".format(path_to_file))
sys.exit(1)
# Check if it's actually a potentially valid source
if source_name:
cond_print(verbose, "Starting extraction of {} source".format(source_name))
else:
click.echo("Could not find extractor for given file path:{}. Goodbye!".format(path_to_file))
sys.exit(1)
# Get the appropriate extractor
extractor = get_extractor_for_file(full_path)
cond_print(verbose, "Using {} for extraction".format(extractor.__class__.__name__))
# Check if this is a valid file
cond_print(verbose, 'Validating File...')
if not extractor.validate():
if no_prompts or click.confirm('This doesn\'t appear to be a game related file. Extract anyway?'):
sys.exit(1)
# Check for duplicate entries, by hash of source file
file_hash = get_file_hash(full_path)
cond_print(verbose, 'Checking for duplicates...')
if not no_prompts and has_potential_duplicates(file_hash, 'source_file_hash', dbm.EXTRACTED_TABLE):
if settle_for_duplicate(file_hash, 'source_file_hash', dbm.EXTRACTED_TABLE):
sys.exit(1)
cond_print(verbose, 'Extracting URI...')
try:
extractor.extract()
except ExtractorError as e:
click.echo(e.message)
sys.exit(1)
extracted_info = extractor.extracted_info
if no_prompts or click.confirm('Create citation from extracted data?'):
citation, extracted_options = extractor.create_citation()
if partial_citation:
partial = json.loads(partial_citation)
citation.elements = merge_with_ordered_dict(partial['description'], citation.elements)
if not no_prompts:
citation = get_citation_user_input(citation, extracted_options)
if citation.ref_type == GAME_CITE_REF:
alternate_citation = choose_game_citation(search_locally_with_citation(citation))
elif citation.ref_type == PERF_CITE_REF:
alternate_citation = choose_performance_citation(search_locally_with_citation(citation))
if not alternate_citation:
dbm.add_to_citation_table(citation, fts=True)
cond_print(verbose, 'Citation added to database.')
else:
dbm.add_to_citation_table(citation, fts=True)
if 'errors' not in extracted_info and dbm.add_to_extracted_table(extracted_info):
cond_print(verbose, "Extraction Successful!")
if not no_prompts:
summary_prompt(extracted_info)
else:
cond_print(verbose, "Extraction Failed!")
pprint.pprint(extracted_info)