Skip to content

Commit

Permalink
update to 1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rettinghaus authored Sep 30, 2018
2 parents 050202d + afa29b6 commit 0e4c539
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmi2csv.xsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- * cmi2csv * -->
<!-- 2.2.0 -->
<!-- 2.2.1 -->
<!-- * programmed by * -->
<!-- * Klaus Rettinghaus * -->
<xsl:stylesheet xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" exclude-result-prefixes="tei">
Expand Down Expand Up @@ -34,7 +34,7 @@
<xsl:value-of select="$sep"/>
<xsl:text>"key"</xsl:text>
<xsl:value-of select="$sep"/>
<xsl:text>"notes"</xsl:text>
<xsl:text>"note"</xsl:text>
<xsl:value-of select="'&#10;'"/>
<xsl:apply-templates/>
</xsl:template>
Expand Down
3 changes: 2 additions & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"identifier": "CSV2CMI",
"name": "CSV2CMI",
"description": "converts a table of letters into CMI format",
"softwareVersion": "1.6.0",
"softwareVersion": "1.6.1",
"license": "OSI Approved :: MIT License",
"programmingLanguage": "Python :: 3",
"maintainer": "https://orcid.org/0000-0003-1898-2543",
Expand All @@ -15,6 +15,7 @@
"@type": "Person",
"givenName": "Klaus",
"familyName": "Rettinghaus",
"name": "Rettinghaus, Klaus",
"email": "[email protected]"
}]
}
30 changes: 25 additions & 5 deletions csv2cmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from xml.etree.ElementTree import Element, SubElement, Comment, ElementTree

__license__ = "MIT"
__version__ = '1.6.0'
__version__ = '1.6.1'

# define log output
logging.basicConfig(format='%(levelname)s: %(message)s')
Expand Down Expand Up @@ -64,6 +64,26 @@ def checkIsodate(datestring):
return False


def checkDatableW3C(datestring):
try:
checkIsodate(datestring)
return True
except ValueError:
try:
datetime.strptime(datestring, '--%m-%d')
return True
except ValueError:
try:
datetime.strptime(datestring, '--%m')
return True
except ValueError:
try:
datetime.strptime(datestring, '---%d')
return True
except ValueError:
return False


def checkConnectivity():
try:
urllib.request.urlopen('http://193.175.100.220', timeout=1)
Expand Down Expand Up @@ -216,18 +236,18 @@ def createCorrespondent(namestring):
def createDate(dateString):
date = Element('date')
normalized_date = dateString.translate(
dateString.maketrans('', '', '[]()?~'))
dateString.maketrans('', '', '[]()?~%'))
if normalized_date != dateString:
date.set('cert', 'medium')
logging.info(
'Added @cert for <date> in line %s', table.line_num)
date_list = normalized_date.split('/')
if len(date_list) == 2:
if checkIsodate(date_list[0]):
if checkDatableW3C(date_list[0]):
date.set('from', str(date_list[0]))
if checkIsodate(date_list[1]):
if checkDatableW3C(date_list[1]):
date.set('to', str(date_list[1]))
elif checkIsodate(normalized_date):
elif checkDatableW3C(normalized_date):
date.set('when', str(normalized_date))
else:
return None
Expand Down
4 changes: 2 additions & 2 deletions example/Example.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sender,senderID,senderPlace,senderPlaceID,senderDate,addressee,addresseeID,addresseePlace,addresseePlaceID,edition,key
Johann Sebastian Bach,http://viaf.org/viaf/12304462,Leipzig,http://www.geonames.org/2879139,1730-10-28,Georg Erdmann,http://viaf.org/viaf/3264804,Danzig,http://www.geonames.org/3099434,"Bach-Dokumente Bd. 1, Leipzig 1963",23
sender,senderID,senderPlace,senderPlaceID,senderDate,addressee,addresseeID,addresseePlace,addresseePlaceID,edition,key,note
Johann Sebastian Bach,http://viaf.org/viaf/12304462,Leipzig,http://www.geonames.org/2879139,1730-10-28,Georg Erdmann,http://viaf.org/viaf/3264804,Danzig,http://www.geonames.org/3099434,"Bach-Dokumente Bd. 1, Leipzig 1963",23,four years later
Binary file modified example/Example.ods
Binary file not shown.

0 comments on commit 0e4c539

Please sign in to comment.