Module: BookmarksReader
- Included in:
- Fundler
- Defined in:
- lib/fundler/bookmarks_reader.rb
Overview
# coding: utf-8
Constant Summary collapse
- MOZILLA_FIREFOX_CONF_DIR =
Schema
References
stackoverflow.com/questions/464516/firefox-bookmarks-sqlite-structure developer.mozilla.org/en-US/docs/Places developer.mozilla.org/en-US/docs/Retrieving_part_of_the_bookmarks_tree developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavBookmarksService davidkoepi.wordpress.com/2010/11/27/firefoxforensics/
Queries
select moz_places.url, moz_bookmarks.title from moz_places,moz_bookmarks where moz_places.id = moz_bookmarks.fk and moz_bookmarks.title != ”;
select keyword,url from moz_keywords left join moz_bookmarks on (moz_keywords.id = keyword_id) left join moz_places on (fk = moz_places.id);
select moz_places.url, datetime((moz_historyvisits.visit_date/1000000), ‘unixepoch’, ‘localtime’), moz_historyvisits.visit_type from moz_places, moz_historyvisits where moz_historyvisits.place_id = moz_places.id order by moz_historyvisits.visit_date desc;
File.('~') + '/.mozilla/firefox/'
- BOOKMARKS_QUERY =
BOOKMARKS_QUERY = %qmoz_places.url, moz_bookmarks.title from moz_places, moz_bookmarks where moz_places.id = moz_bookmarks.fk and moz_bookmarks.title != ”;
<<-SQL SELECT DISTINCT moz_places.url AS url, moz_bookmarks.title AS title, moz_items_annos.content AS description FROM moz_places, moz_bookmarks, moz_items_annos, moz_anno_attributes WHERE moz_anno_attributes.name = 'bookmarkProperties/description' AND moz_items_annos.anno_attribute_id = moz_anno_attributes.id AND moz_items_annos.item_id = moz_bookmarks.id AND moz_places.id = moz_bookmarks.fk AND moz_places.id IN ( SELECT DISTINCT fk FROM moz_bookmarks WHERE parent IN ( SELECT moz_bookmarks.id FROM moz_bookmarks, moz_bookmarks_roots WHERE moz_bookmarks_roots.root_name = 'tags' AND moz_bookmarks.parent = moz_bookmarks_roots.folder_id ) ) ORDER BY UPPER(moz_bookmarks.title) ASC SQL
Instance Method Summary collapse
-
#drop_bookmarks(format = :plain) ⇒ Object
drop_bookmarks
browse the home directory of the current user, locate theplaces.sqlite
db_file generated by Firefox and retrieve all the bookmarks stored. - #dump_places ⇒ Object
- #locate_places ⇒ Object
Instance Method Details
#drop_bookmarks(format = :plain) ⇒ Object
drop_bookmarks
browse the home directory of the current user, locate the places.sqlite
db_file generated by Firefox and retrieve all the bookmarks stored.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fundler/bookmarks_reader.rb', line 70 def drop_bookmarks(format = :plain) require 'sqlite3' output = [] if locate_places db = SQLite3::Database.new(locate_places) rows = db.execute(BOOKMARKS_QUERY) rows.each_with_index do |row, index| case format when :plain output << "#{index}: #{row.join(' | ')}" output << '---' when :html puts "TODO" when :markdown puts "TODO" when :json puts "TODO" end end end File.open('./bookmarks_dump.txt', 'w') do |file| file.puts output end end |
#dump_places ⇒ Object
107 108 109 |
# File 'lib/fundler/bookmarks_reader.rb', line 107 def dump_places FileUtils.cp(locate_places, pwd) end |
#locate_places ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fundler/bookmarks_reader.rb', line 95 def locate_places begin dot_firefox = Dir.open(MOZILLA_FIREFOX_CONF_DIR) profile_dir = dot_firefox.select {|dir| dir =~ /.*default/} db_file = MOZILLA_FIREFOX_CONF_DIR + profile_dir.join + '/places.sqlite' rescue Errno::ENOENT puts "no db_bookmarks found" # exit 1 nil end end |