Maintenance will be performed on,,, and on Tuesday 22nd September 2020 starting at approximately 9am MST.It is expected to take around 15 minutes and there will be a short period of downtime towards the end of the maintenance window. Please address any comments, questions, or concerns to

Commit 63cb1c7d authored by Sean Leavey's avatar Sean Leavey

View record example

parent b7166a51
# -*- coding: utf-8 -*-
"""Example of record functionality"""
from dcc.record import DccArchive, DccNumber
import html2text
# terminal colours
class term_col:
BLUE = '\033[94m'
GREEN = '\033[92m'
END = '\033[0m'
def print_kv(key, val):
"""Prints a key and value pair to the terminal with colours"""
print('{0}{1}: {2}{3}{4}'.format(term_col.BLUE, key, term_col.GREEN, val, term_col.END))
def print_k(key):
"""Prints a key to the terminal"""
print('{0}{1}:{2}'.format(term_col.BLUE, key, term_col.END))
def print_v(val):
"""Prints a value to the terminal"""
print('{0}{1}{2}'.format(term_col.GREEN, val, term_col.END))
# create new archive
archive = DccArchive()
# fetch the record
record = archive.fetch_record("P150914")
# print some information
print_kv('number', record['dcc_number'])
print_kv('url', archive.fetcher.get_record_url(DccNumber(record['dcc_number']), xml=False))
print_kv('title', record['title'])
print_kv('modified', record['contents_revision_date'])
for a in record.authors:
print_kv('keywords', ", ".join(record['keywords']))
for i, f in enumerate(record['files']):
print_v(' {} {}'.format(i, f))
print_k('referenced by')
for r in record['referenced_by']:
print_v(' {}'.format(r))
for r in record['related']:
print_v(' {}'.format(r))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment