Skip to content
Browse files

Making progress: added year of publication

  • Loading branch information...
1 parent 890e942 commit 08136a37af5ce8bbc4a4a17c72631a9b43f748dd @egonw committed Mar 14, 2011
Showing with 22 additions and 16 deletions.
  1. +22 −16 cul2html.groovy
View
38 cul2html.groovy
@@ -2,21 +2,28 @@ import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import groovy.xml.MarkupBuilder
import static groovyx.net.http.ContentType.JSON
+import net.sf.json.JSONSerializer
-// culUrl = "http://www.citeulike.org/";
-culUrl = "file:///home/egonw/";
+doMisc = false;
+
+culUrl = "http://www.citeulike.org/";
culAccount = "egonw";
http = new HTTPBuilder(culUrl)
def outputAuthors = { xml, authors ->
xml.span{
authors.each { author ->
- xml.span(author) + ', '
+ span(author)
}
}
}
+def getYear = { published ->
+ list = JSONSerializer.toJava(published)
+ return (list != null ? list.get(0) : "");
+}
+
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
@@ -26,32 +33,31 @@ xml.'html'(
'xmlns:dcterms':'http://purl.org/dc/terms/'
) {
http.request(Method.valueOf("GET"), JSON) {
- // uri.path = "/json/user/$culAccount/publications"
- uri.path = "/publications"
+ uri.path = "/json/user/$culAccount/publications"
response.success = { resp,json ->
- xml.body() { xml.ol() {
+ body() { ol() {
json.each { article ->
// this is where I should use CSL
title = article.title
title = title.replaceAll("\\{","").replaceAll("\\}","")
if (article.type.equals("BOOK")) {
- xml.li('id':'#'+article.article_id, typeof:'bibo:Article') {
+ li('id':'#'+article.article_id, typeof:'bibo:Article') {
outputAuthors(xml, article.authors)
- xml.span(property:'bibo:title', article.title) + ', '
- xml.span(property:'dcterms:created', article.year)
+ span(property:'bibo:title', article.title)
+ span(property:'dcterms:date', getYear(article.published))
}
} else if (article.type.equals("JOUR")) {
- xml.li('id':'#'+article.article_id, typeof:'bibo:Book') {
+ li('id':'#'+article.article_id, typeof:'bibo:Book') {
outputAuthors(xml, article.authors)
- xml.span(property:'bibo:title', article.title) + ', '
- xml.span(property:'dcterms:created', article.year)
+ span(property:'bibo:title', article.title)
+ span(property:'dcterms:date', getYear(article.published))
}
- } else { // MISC
- xml.li('id':'#'+article.article_id, typeof:'bibo:Document') {
+ } else if (doMisc) { // MISC
+ li('id':'#'+article.article_id, typeof:'bibo:Document') {
outputAuthors(xml, article.authors)
- xml.span(property:'bibo:title', article.title) + ', '
- xml.span(property:'dcterms:created', article.year)
+ span(property:'bibo:title', article.title) + ', '
+ span(property:'dcterms:date', article.year)
}
}
}

0 comments on commit 08136a3

Please sign in to comment.
Something went wrong with that request. Please try again.