Exemple #1
0
def build_digest(file_name,
                 temp_dir="tmp",
                 digest_config=None,
                 image_file_name=None):
    "build a digest object from a DOCX input file"
    digest = None
    docx_file_name, zip_image_file_name = handle_zip(file_name, temp_dir)
    LOGGER.info("build_digest file '%s' has docx_file_name: '%s'", file_name,
                docx_file_name)
    LOGGER.info(
        "build_digest file '%s' has zip_image_file_name: '%s'",
        file_name,
        zip_image_file_name,
    )
    if not image_file_name:
        image_file_name = zip_image_file_name
    content = parse_content(docx_file_name)
    if content:
        digest = Digest()
        digest.author = build_author(content)
        digest.title = build_title(content)
        digest.summary = build_summary(content)
        digest.keywords = build_keywords(content)
        digest.manuscript_number = build_manuscript_number(content)
        digest.doi = build_doi(content, digest_config)
        digest.text = build_text(content)
        digest.image = build_image(content, image_file_name)
    return digest
Exemple #2
0
 def test_digest_json_empty(self):
     "test json output for an empty digest where there is no text or image file"
     digest = Digest()
     # reset some lists to None for testing
     digest.text = None
     digest.keywords = None
     digest.subjects = None
     expected = OrderedDict([
         ("id", "None"),
         ("title", None),
         ("impactStatement", None),
         ("content", []),
     ])
     self.assertEqual(json_output.digest_json(digest, None), expected)