Skip to content

Commit

Permalink
bringing up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
houshuang committed May 22, 2011
1 parent 4d2f7cd commit b38e80b
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 35 deletions.
18 changes: 18 additions & 0 deletions bibdesk-copy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: UTF-8
curpath = File.dirname(File.expand_path(__FILE__)) + "/"
require 'pp'
require 'rubygems'
require 'appscript'
require curpath + 'wiki-lib'
include Appscript

# grabs the name of the currently open BibDesk file, and puts on clipboard formatted as a DokuWiki reference

dt = app('BibDesk')
d = dt.document.selection.get[0]
out = ''
d.each do |dd|
docu = dd.cite_key.get
out << "[(:ref:#{docu})]"
end
`echo "#{out}" | pbcopy`
4 changes: 3 additions & 1 deletion bibdesk-kindle.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# encoding: UTF-8
curpath = File.dirname(File.expand_path(__FILE__)) + "/"
require 'rubygems'
require 'appscript'
require './mail-lib'
require curpath + 'mail-lib'
include Appscript

# grabs the name of the currently open Skim file, uses skimnotes to extract notes and highlights to a text file,
Expand Down
15 changes: 4 additions & 11 deletions bibdesk.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# encoding: UTF-8
curpath = File.dirname(File.expand_path(__FILE__)) + "/"
require 'pp'
require 'rubygems'
require 'appscript'
require curpath + 'wiki-lib'
include Appscript

# grabs the name of the currently open Skim file, uses skimnotes to extract notes and highlights to a text file,
Expand All @@ -11,17 +14,7 @@
d = dt.document.selection.get[0]
d.each do |dd|
docu = dd.cite_key.get

# check if main page exists, and if not, create it
unless File.exists?("/wiki/data/pages/ref/#{docu}.txt")
bibtex =dd.BibTeX_string.get.gsub(/Bdsk(.+?)$/,"")
bibtex =dd.BibTeX_string.get.gsub(/\Abstract(.+?)$/,"")
bibtex =dd.BibTeX_string.get.gsub(/\n\n/,"\n")
title = dd.title.get.gsub("{","").gsub("}","")
File.open('/tmp/bibdesktmp', 'w') {|f| f << "h1. #{title}\n\n<hidden BibTex>\n #{bibtex}\n</hidden>\n\n{{page>notes:#{docu}}}\n\n{{page>clip:#{docu}}}"}
`/wiki/bin/dwpage.php -m 'Automatically generated from Bibdesk' commit /tmp/bibdesktmp 'ref:#{docu}'`
end

ensure_refpage(docu)
# open it in the default browser
`open http://localhost/wiki/ref:#{docu}`
end
Expand Down
1 change: 1 addition & 0 deletions convert.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: UTF-8
require 'pp'
require 'rubygems'
require 'appscript'
Expand Down
7 changes: 4 additions & 3 deletions folders.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# encoding: UTF-8
require 'find'
require 'fileutils'
require './library'

#######################################################################
searchpath = "MA/"
TITLE = "Raw notes from research on Top Level Courses Project"
searchpath = "../kindle/Clippings"
TITLE = "Raw Kindle clippings"
OUT = "/Users/stian/src/folders2web/out/"
layout = 3
#######################################################################
Expand All @@ -21,7 +22,7 @@ def sanitize_filename(filename)
end

def skip?(filename)
true if ['index.html','Images'].index(filename) || filename[0..1] == '.'
true if ['index.html','Images','.png','.jpg','.gif','dirs.html'].index(filename) || filename[0..1] == '.'
end

def clean_name(path) # takes full path, moves file, returns new rel path and display name
Expand Down
5 changes: 3 additions & 2 deletions gscholar-y.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ 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
url = a[ARGV[0].to_i-1]
citekey = a[0]
url = a[ARGV[0].to_i]

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

Expand All @@ -21,7 +22,7 @@ def download full_url, to_here
download(url, "/tmp/pdftmp.pdf")

dt = app('BibDesk')
d = dt.document.selection.get[0]
d = dt.search({:for=>citekey})

f = MacTypes::FileURL.path('/tmp/pdftmp.pdf')
d[0].linked_files.add(f,{:to =>d[0]})
Expand Down
3 changes: 1 addition & 2 deletions gscholar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
include Appscript

# grabs the name of the currently open BibDesk file, and puts on clipboard formatted as a DokuWiki reference
f = File.open(curpath + "log","a")

`/usr/local/bin/growlnotify -m "Starting lookup on Google Scholar"`

dt = app('BibDesk')
d = dt.document.selection.get[0]
title = d[0].title.get.gsub(" ","%20").gsub(/[\{|\}]/,'')
author = d[0].author.get[0].name.get.gsub(" ","%20")
f << "#{title}, #{author}\n"

url = "http://scholar.google.com/scholar?&as_q=#{title}&as_sauthors=#{author}"
page = open(url).read
Expand All @@ -31,6 +29,7 @@
out = ''
c = 0
File.open("gscholar-tmp","w") do |f|
f << "#{d.cite_key.key}\n"
items.each do |item|
c += 1
out << "#{c}: #{item[:title]}\n"
Expand Down
1 change: 1 addition & 0 deletions library.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: UTF-8
def indexhtml(title,layout)

if layout == 2
Expand Down
4 changes: 3 additions & 1 deletion mail-lib.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# encoding: UTF-8
require 'mail'
require 'yaml'

# helper function for emailing stuff to Kindle, etc
def mail_file(file)
curpath = File.dirname(File.expand_path(__FILE__)) + "/"
# get passwords and email
conf = YAML::load(File.read("config.yaml"))
conf = YAML::load(File.read(curpath + "config.yaml"))

# we're using GMail
options = { :address => "smtp.gmail.com",
Expand Down
40 changes: 38 additions & 2 deletions skim.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# encoding: UTF-8
curpath = File.dirname(File.expand_path(__FILE__)) + "/"
require 'pp'
require 'rubygems'
require 'appscript'
require curpath + 'wiki-lib'
include Appscript

# grabs the name of the currently open Skim file, uses skimnotes to extract notes and highlights to a text file,
Expand All @@ -10,6 +13,39 @@
dt.save(dt.document)
docu = dt.document.name.get[0][0..-5]
`/Applications/Skim.app/Contents/SharedSupport/skimnotes get -format text #{dt.document.file.get[0].to_s}`
File.open('/tmp/skimtmp', 'w') {|f| f << "h1. Notes\n\n" << File.read("/Volumes/Home/stian/Documents/Bibdesk/#{docu}.txt").gsub("\n","\n\n") }

# format notes
a = File.readlines("/Volumes/Home/stian/Documents/Bibdesk/#{docu}.txt")
text=''
lineno=nil
Citekey = docu
type = ""
out = "h1. Highlights\n\n"

def format(text,page,type)
highlight = (type == "Text Note" ? "::" : "")
return "#{highlight}#{text.strip}#{highlight} [[skimx://#{Citekey}##{page}|p. #{page}]]\n\n"
end

a.each do |line|
# puts "###{line}"
if line =~ /^\* (Highlight|Text Note), page (.+?)$/
if lineno != nil
out << format(text,lineno,type)
end
lineno = $2.to_i
type = $1
text = ''
else
text << line
end
end
highlight = (type == "Text Note" ? "**" : "")
out << format(text,lineno,type)

File.open("/tmp/skimtmp", "w") {|f| f << out}

`/wiki/bin/dwpage.php -m 'Automatically extracted from Skim' commit /tmp/skimtmp 'clip:#{docu}'`
`open http://localhost/wiki/clip:#{docu}`

ensure_refpage(docu)
`open http://localhost/wiki/ref:#{docu}`
13 changes: 0 additions & 13 deletions test.rb

This file was deleted.

0 comments on commit b38e80b

Please sign in to comment.