"""gutenberg.

Usage:
  dasem.gutenberg list

"""


from __future__ import print_function

from pandas import DataFrame

from sparql import Service


SPARQL_QUERY = """
SELECT ?work ?workLabel ?authorLabel ?gutenberg WHERE {
  ?work wdt:P2034 ?gutenberg.
  ?work wdt:P407 wd:Q9035 .
  OPTIONAL { ?work wdt:P50 ?author . }
  service wikibase:label { bd:serviceParam wikibase:language "da" }
}
"""


def get_list_from_wikidata():
    """Get list of works from Wikidata.

    Returns
    -------
    df : pandas.DataFrame
        DataFrame with information from Wikidata.

    """
    service = Service("https://query.wikidata.org/sparql", method="GET")
    result = service.query(SPARQL_QUERY)
    df = DataFrame(result.fetchall(), columns=result.variables)
    return df


def main():
    """Handle command-line interface."""
    from docopt import docopt

    arguments = docopt(__doc__)

    if arguments['list']:
        df = get_list_from_wikidata()
        print(df.to_csv(encoding='utf-8'))


if __name__ == '__main__':
    main()

@@ -15,16 +15,43 @@
 %0AUsage:%0A
+  dasem.gutenberg get %3Cid%3E%0A
   dasem.
@@ -111,16 +111,27 @@
 nction%0A%0A
+import re%0A%0A
 from pan
@@ -152,16 +152,33 @@
 aFrame%0A%0A
+import requests%0A%0A
 from spa
@@ -454,499 +454,1638 @@
 def 
-get_list_from_wikidata():%0A    %22%22%22Get list of works from Wikidata.%0A%0A    Returns%0A    -------%0A    df : pandas.DataFrame%0A        DataFrame with information from Wikidata.%0A%0A    %22%22%22%0A    service = Service(%22https://query.wikidata.org/sparql%22, method=%22GET%22)%0A    result = service.query(SPARQL_QUERY)%0A    df = DataFrame(result.fetchall(), columns=result.variables)%0A    return df%0A%0A%0Adef main():%0A    %22%22%22Handle command-line interface.%22%22%22%0A    from docopt import docopt%0A%0A    arguments = docopt(__doc__)%0A%0A    
+extract_text(text):%0A    %22%22%22Extract text from downloaded text.%0A%0A    Start:%0A%0A      *** START OF THIS PROJECT GUTENBERG EBOOK ... ***%0A%0A      Some multiple lines of text%0A%0A    End:%0A%0A      End of the Project Gutenberg EBook of ...%0A%0A      *** END OF THIS PROJECT GUTENBERG EBOOK ... ***%0A%0A    %22%22%22%0A    # TODO: There is still some text to be dealt with.%0A    matches = re.findall(%0A        (r%22%5E%5C*%5C*%5C* START OF THIS PROJECT.+?$%22%0A         r%22(.+?)%22  # The text to capture%0A         r%22%5E%5C*%5C*%5C* END OF THIS PROJECT.+?$%22),%0A        text, flags=re.DOTALL %7C re.MULTILINE %7C re.UNICODE)%0A    return matches%5B0%5D.strip()%0A%0A%0Adef get_list_from_wikidata():%0A    %22%22%22Get list of works from Wikidata.%0A%0A    Returns%0A    -------%0A    df : pandas.DataFrame%0A        DataFrame with information from Wikidata.%0A%0A    %22%22%22%0A    service = Service(%22https://query.wikidata.org/sparql%22, method=%22GET%22)%0A    result = service.query(SPARQL_QUERY)%0A    df = DataFrame(result.fetchall(), columns=result.variables)%0A    return df%0A%0A%0Adef get_text_by_id(id):%0A    %22%22%22Get text from Gutenberg based on id%0A%0A    Parameters%0A    ----------%0A    id : int or str%0A        Identifier.%0A%0A    Returns%0A    -------%0A    text : str or None%0A        The text. Returns none if the page does not exist.%0A%0A    %22%22%22%0A    url = %22http://www.gutenberg.org/ebooks/%7Bid%7D.txt.utf-8%22.format(id=id)%0A    response = requests.get(url)%0A    return response.content%0A%0A%0Adef main():%0A    %22%22%22Handle command-line interface.%22%22%22%0A    from docopt import docopt%0A%0A    arguments = docopt(__doc__)%0A%0A    if arguments%5B'get'%5D:%0A        text = get_text_by_id(arguments%5B'%3Cid%3E'%5D)%0A        extracted_text = extract_text(text)%0A        print(extracted_text)%0A%0A    el
 if a

Implement text get and extraction