Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
houshuang committed May 25, 2011
1 parent 4af2b74 commit eedde58
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 19 deletions.
6 changes: 5 additions & 1 deletion bibdesk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@

dt = app('BibDesk')
d = dt.document.selection.get[0]
dt.document.save
ary = Array.new
d.each do |dd|
docu = dd.cite_key.get
ary << docu unless File.exists?("/wiki/data/pages/ref/#{docu}.txt")
ensure_refpage(docu)
# open it in the default browser
`open http://localhost/wiki/ref:#{docu}`
end
`open http://localhost/wiki/ref:#{d[0].cite_key.get}`
make_newimports_page(ary)

#
# @inproceedings{stahl2002contributions,
Expand Down
10 changes: 8 additions & 2 deletions bibtex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
b.parse_names

out = "h1. Bibliography\n\n^Note name ^ Note text ^\n"
out1 = ''
out2 = ''
b.each do |item|
cit = CiteProc.process item.to_citeproc, :style => :apa
out << "| :ref:#{item.key} | #{cit}|\n"
if File.exists?("/wiki/data/pages/ref/#{item.key}.txt")
out1 << "| [[:ref:#{item.key}|:ref:#{item.key}]] | #{cit}|\n"
else
out2 << "| :ref:#{item.key} | #{cit}|\n"
end

end
out << out1 << out2
File.open('/tmp/bibtextmp', 'w') {|f| f << out}
`/wiki/bin/dwpage.php -m 'Automatically generated from BibTeX file' commit /tmp/bibtextmp 'ref:bibliography'`

Expand Down
7 changes: 3 additions & 4 deletions gscholar-y.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def download full_url, to_here

# grabs the name of the currently open BibDesk file, and puts on clipboard formatted as a DokuWiki reference
a = File.open("gscholar-tmp").readlines
citekey = a[0]
citekey = a[0].strip
url = a[ARGV[0].to_i]

puts url
domain = url.scan(/http:\/\/(.+?)\//)[0][0]

`/usr/local/bin/growlnotify -t "Download started" -m "Downloading from #{domain}"`
Expand All @@ -23,8 +23,7 @@ def download full_url, to_here

dt = app('BibDesk')
d = dt.search({:for=>citekey})

f = MacTypes::FileURL.path('/tmp/pdftmp.pdf')
d[0].linked_files.add(f,{:to =>d[0]})
d[0].auto_file
`/usr/local/bin/growlnotify -t "PDF added" -m "File added successfully to #{d.cite_key.key}"`
`/usr/local/bin/growlnotify -t "PDF added" -m "File added successfully to #{d.cite_key.get}"`
2 changes: 1 addition & 1 deletion gscholar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
out = ''
c = 0
File.open("gscholar-tmp","w") do |f|
f << "#{d.cite_key.key}\n"
f << "#{d[0].cite_key.get}\n"
items.each do |item|
c += 1
out << "#{c}: #{item[:title]}\n"
Expand Down
3 changes: 0 additions & 3 deletions kindle-clippings.sh

This file was deleted.

69 changes: 67 additions & 2 deletions kindle-mount.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
#!/usr/bin/ruby
# encoding: UTF-8

File.open("/Volumes/Home/stian/src/folders2web/kindle","a"){|f| f<<Time.now.to_s << File.exists?("/Volumes/Kindle").to_s <<
"\n"}
#File.open("/Volumes/Home/stian/src/folders2web/kindle","a"){|f| f<<Time.now.to_s << File.exists?("/Volumes/Kindle").to_s <<"\n"}
# encoding: UTF-8
require 'pp'
require 'rubygems'
curpath = File.dirname(File.expand_path(__FILE__)) + "/"
require curpath + 'wiki-lib'
require 'appscript'
include Appscript

`/usr/local/bin/growlnotify -m "Starting import of Kindle highlights"`

app("BibDesk").document.save
#a = File.open("/Volumes/Kindle/documents/My\ Clippings.txt")
a = File.open("/Volumes/Home/stian/src/folders2web/My Clippings.txt")
annotations = Hash.new

def format(text,label, loc)
highlight = (label == 2 ? "::" : "")
return "#{highlight}#{text.strip}#{highlight} **(loc: #{loc})**\n\n"
end


while !a.eof? # until we've gone through the whole file, line by line
title = a.readline.strip
meta = a.readline.strip
loc, added = meta.split(" | ")
loc = loc.gsub("- Highlight", "").strip
content = ''
while 1
c = a.readline
break if c[0..9] == "==========" # end of record
content << c
end

content.strip!

label = loc.index("- Note") ? 2 : 0 # colors it blue if it is a note, rather than highlight

annotations[title] = {:clippings => Array.new} unless annotations[title]

loc = loc.gsub("- Note", "").gsub("Loc. ", "")
annotations[title][:clippings] << {:text => content, :label => label, :loc => loc}
end

# now let's connect to DevonThink, and create the notes
c = 0
new_imports = Array.new
annotations.each do |title, article|
next unless title =~ /\[(.+?)\] \((.+?)\)$/
citekey = $1
puts $1
#next if File.exists?("/wiki/data/pages/kindle/#{citekey}.txt")
new_imports << citekey
c += 1
out = "h1. Kindle highlights\n\n"

article[:clippings].each do |clip|
out << format(clip[:text], clip[:label],clip[:loc])
end

File.open("/tmp/kindletmp", "w") {|f| f << out}
`/wiki/bin/dwpage.php -m 'Automatically extracted from Kindle' commit /tmp/kindletmp 'kindle:#{citekey}'`
ensure_refpage(citekey)
end

make_newimports_page(new_imports)
`/usr/local/bin/growlnotify -t "Kindle import complete" -m "Imported #{c} publication(s)"`
3 changes: 3 additions & 0 deletions kindle-mount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

ruby -KU /Volumes/Home/stian/src/folders2web/kindle-mount.rb
1 change: 1 addition & 0 deletions skim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ def format(text,page,type)
`/wiki/bin/dwpage.php -m 'Automatically extracted from Skim' commit /tmp/skimtmp 'clip:#{docu}'`

ensure_refpage(docu)
make_newimports_page([docu])
`open http://localhost/wiki/ref:#{docu}`
26 changes: 20 additions & 6 deletions wiki-lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,32 @@ def cb(text)
# ensure that main refpage exists for a given citekey, taking info from BibDesk (needs to be running,
# maybe replace with taking info from Bibtex file eventually)
def ensure_refpage(citekey)
unless false #File.exists?("/wiki/data/pages/ref/#{citekey}.txt")
unless false #File.exists?("/wiki/data/pages/ref/#{citekey}.txt")

b = BibTeX.open("/Volumes/Home/stian/Dropbox/Archive/Bibliography.bib")
b.parse_names
item = b[citekey.to_sym]

p item
p citekey
citation = CiteProc.process(item.to_citeproc, :style => :apa)
citation = "^ Citation | " + citation + " ^ <html><a href=\"javascript:var MyFrame='<frameset cols=\\'*,*\\'><frame src=\\'/wiki/notes:#{citekey}?do=edit&vecdo=print\\'><frame src=\\'/wiki/clip:#{citekey}?vecdo=print\\'></frameset>';with(document) { write(MyFrame);};return false;\">Sidewiki</a></html>^\n^[[bibdesk://#{citekey}|BibDesk]] | ::: ^ [[skimx://#{citekey}|PDF]] ^ "
File.open('/tmp/bibdesktmp', 'w') {|f| f << "h1. #{cb(item[:title])}\n\n#{citation}\n\n<hidden BibTex>\n #{item.to_s}\n</hidden>\n\n{{page>notes:#{citekey}}}\n\nh2. Links here\n{{backlinks>.}}\n\n{{page>clip:#{citekey}}}"}

File.open('/tmp/bibdesktmp', 'w') {|f| f << "h1. #{cb(item[:title])}\n\n#{citation}\n\n<hidden BibTex>\n #{item.to_s}\n</hidden>\n\n{{page>notes:#{citekey}}}\n\nh2. Links here\n{{backlinks>.}}\n\n{{page>clip:#{citekey}}}\n\n{{page>kindle:#{citekey}}}"}
`/wiki/bin/dwpage.php -m 'Automatically generated from Bibdesk' commit /tmp/bibdesktmp 'ref:#{citekey}'`
end
end

#ensure_refpage("scardamalia2006knowledge")
def make_newimports_page(ary)
b = BibTeX.open("/Volumes/Home/stian/Dropbox/Archive/Bibliography.bib")
b.parse_names

out = "h1. Recently imported items\n\n^Note name ^ Note text ^\n"
ary.each do |citekey|
item = b[citekey.to_sym]
cit = CiteProc.process item.to_citeproc, :style => :apa
out << "| [[:ref:#{item.key}]] | #{cit}|\n"
end

File.open('/tmp/bibtextmp', 'w') {|f| f << out}
`/wiki/bin/dwpage.php -m 'Automatically generated from BibTeX file' commit /tmp/bibtextmp 'ref:recent_imports'`
end

0 comments on commit eedde58

Please sign in to comment.