-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8: Partial implementation of
author
parsing.
- Loading branch information
1 parent
d22695e
commit 74545e7
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Interpreter version: python 2.7 | ||
# | ||
# Imports ===================================================================== | ||
import dhtmlparser | ||
|
||
from shared import parse_meta | ||
|
||
|
||
# Functions & classes ========================================================= | ||
def _get_html_authors(index_page): | ||
""" | ||
Return list of `authors` from HTML ``<meta>`` tags. | ||
""" | ||
return parse_meta(index_page, "author", "HTML") | ||
|
||
|
||
def _get_dc_authors(index_page): | ||
""" | ||
Return list of `authors` parsed from dublin core. | ||
""" | ||
return parse_meta(index_page, "DC.Creator", "DC") | ||
|
||
|
||
def get_author(index_page): | ||
""" | ||
Parse `authors` from HTML ``<meta>`` and dublin core. | ||
""" | ||
dom = dhtmlparser.parseString(index_page) | ||
|
||
authors = [ | ||
_get_html_authors(dom), | ||
_get_dc_authors(dom), | ||
] | ||
|
||
return sum(authors, []) # return flattened list |