summaryrefslogtreecommitdiff
path: root/biblio.coffee
diff options
context:
space:
mode:
authorAdrien Friggeri <adrien@friggeri.net>2011-12-07 18:42:51 +0100
committerAdrien Friggeri <adrien@friggeri.net>2011-12-07 18:42:51 +0100
commitea6cc6703fa84eb405d459da94a9a07bbe3de31c (patch)
tree8501d29e2848b1fd55ddf9e70ac8a8faaf4f2db3 /biblio.coffee
parent135d8cc799cc11c887b6ae293ca0b8a98aba6f2d (diff)
first pass
Diffstat (limited to 'biblio.coffee')
-rw-r--r--biblio.coffee56
1 files changed, 56 insertions, 0 deletions
diff --git a/biblio.coffee b/biblio.coffee
new file mode 100644
index 0000000..2346727
--- /dev/null
+++ b/biblio.coffee
@@ -0,0 +1,56 @@
+jsdom = require 'jsdom'
+util = require 'util'
+fs = require 'fs'
+hal = "http://haltools.inrialpes.fr/Public/afficheRequetePubli.php?auteur_exp=Friggeri&CB_auteur=oui&CB_titre=oui&CB_article=oui&langue=Anglais&tri_exp=annee_publi&tri_exp2=typdoc&tri_exp3=date_publi&ordre_aff=TA&Fen=Aff"
+
+jsdom.env hal, ['http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'], (err, window) ->
+ $ = window.$
+
+ types = []
+ entries = {}
+ type = null
+
+ $('#res_script').children().each ->
+ $this = $(this)
+
+ switch this.nodeName.toLowerCase()
+ when 'p'
+ switch $this.attr('class')
+ when 'Rubrique'
+ year = $this.text()
+ when 'SousRubrique'
+ type = $this.text()
+ if types.indexOf(type) == -1
+ entries[type] = []
+ types.push(type)
+
+ when 'dl'
+ cur = null
+ entry = {year}
+ $this.children().each ->
+ $this = $(this)
+ switch this.nodeName.toLowerCase()
+ when 'dt'
+ switch $this.text().toLowerCase()
+ when 'auteurs' then cur = 'authors'
+ when 'détail' then cur = 'more'
+ when 'titre' then cur = 'title'
+ else cur = null
+ when 'dd'
+ if cur
+ if cur == 'authors'
+ entry[cur] = $this.text().split(';').map((s)->s.replace(/^\s*|\s*$/g, ''))
+ else
+ entry[cur] = $this.text().replace(/\[|\]/g, '')
+
+ entries[type].push(entry)
+
+ buf = []
+ for type, items of entries
+ buf.push " \\subsection*{#{type.toLowerCase()}}"
+ for entry in items
+ buf.push " \\btitle{#{entry.title}}"
+ buf.push " \\bauthors{#{entry.authors.join(', ')}}"
+ buf.push " \\bmore{#{entry.more}}"
+ fs.writeFile __dirname+"/biblio.tex", buf.join('\n'), 'utf8', ->
+ console.log "Generated biblio.tex" \ No newline at end of file