Skip to content

Commit

Permalink
Merge pull request #50 from kidd/add-firefox-history
Browse files Browse the repository at this point in the history
Add firefox history module to memacs
  • Loading branch information
novoid authored Jul 21, 2018
2 parents 9981ae3 + 3b17fe5 commit c42e400
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bin/memacs_firefox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Time-stamp: <2013-04-04 16:18:07 vk>

from memacs.firefox import Firefox

PROG_VERSION_NUMBER = u"0.0"
PROG_VERSION_DATE = u"2018-07-14"
PROG_SHORT_DESCRIPTION = u"Memacs for firefox url history "
PROG_TAG = u"firefox"
PROG_DESCRIPTION = u"""
This class will parse firefox history file (places.sqlite) and
produce an org file with all your visited sites
"""
# set CONFIG_PARSER_NAME only, when you want to have a config file
# otherwise you can comment it out
# CONFIG_PARSER_NAME="memacs-example"
COPYRIGHT_YEAR = "2018"
COPYRIGHT_AUTHORS = """Raimon Grau <[email protected]>"""


if __name__ == "__main__":
memacs = Firefox(
prog_version=PROG_VERSION_NUMBER,
prog_version_date=PROG_VERSION_DATE,
prog_description=PROG_DESCRIPTION,
prog_short_description=PROG_SHORT_DESCRIPTION,
prog_tag=PROG_TAG,
copyright_year=COPYRIGHT_YEAR,
copyright_authors=COPYRIGHT_AUTHORS
# use_config_parser_name=CONFIG_PARSER_NAME
)
memacs.handle_main()
31 changes: 31 additions & 0 deletions docs/memacs_firefox_history.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Time-stamp: <2018-07-21>
## This file is best viewed with GNU Emacs Org-mode: http://orgmode.org/

* memacs-firefox_history
** Options

- ~-f~, ~--file~, path to a sqlite db file which contains the firefox history: ~~/.mozilla/firefox/123adsf1.default/places.sqlite~.
- ~--output-format~, format for the headers of the generated org. available tags are: ~guid, url, title, visit_count, timestamp~

** Data Source

The visited sites in Firefox are stored in a ~places.sqlite~ file that
contains every url you visited along with the last visited date.

We can use Memacs_firefox to generate a file with the datetimes of the urls:

** Example Invocation
*** Example with rev-list file:
: python bin/memacs_firefox.py -f "/home/rgrau/.mozilla/firefox/3hlzuwen.default/places.sqlite" >~/org/mozhist.org_archive

** Example Orgmode entries

With the default --output-format, a regular entry looks like this:

: * Memacs for firefox url history :Memacs:firefox:
: ** <2018-07-20 Fri 23:51> [[https://github.com/kidd][kidd (Raimon Grau (rgrau))]]
: :PROPERTIES:
: :URL: https://github.com/kidd
: :VISIT_COUNT: 1
: :ID: 68ff284b25379144784a214e7a0d19631c3d18f1
: :END:
85 changes: 85 additions & 0 deletions memacs/firefox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time-stamp: <2017-02-07 19:25 manu>

import sqlite3
import datetime
import sys
import os
import re

from lib.orgproperty import OrgProperties
from lib.orgformat import OrgFormat
from lib.memacs import Memacs

reload(sys)
sys.setdefaultencoding('utf8')

class Firefox(Memacs):
def _parser_add_arguments(self):
"""
overwritten method of class Memacs
add additional arguments
"""
Memacs._parser_add_arguments(self)

self._parser.add_argument(
"-f", "--file", dest="historystore",
action="store", type=file, required=True,
help="""path to places.sqlite file. usually in
/home/rgrau/.mozilla/firefox/__SOMETHING__.default/places.sqlite """)

self._parser.add_argument(
"--output-format", dest="output_format",
action="store", default="[[{url}][{title}]]",
help="format string to use for the headline")


def _parser_parse_args(self):
"""
overwritten method of class Memacs
all additional arguments are parsed in here
"""
Memacs._parser_parse_args(self)

def _handle_url(self, params):
timestamp = datetime.datetime.fromtimestamp(int(params['timestamp']/1000000))

properties = OrgProperties()
if (params['title'] == "") :
params['title'] = params['url']
properties.add('URL', params['url'])
properties.add('VISIT_COUNT', params['visit_count'])

output = ""
try:
output = self._args.output_format.decode('utf-8').format(**params)
except Exception:
pass

self._writer.write_org_subitem(
timestamp=OrgFormat.datetime(timestamp),
output=output, properties=properties)

def _main(self):
"""
get's automatically called from Memacs class
"""
conn = sqlite3.connect(os.path.abspath(self._args.historystore.name))
query = conn.execute("""
select url, title, visit_count,
-- datetime(last_visit_date/1000000, 'unixepoch')
last_visit_date
from moz_places
where last_visit_date IS NOT NULL
order by last_visit_date """)

for row in query:
self._handle_url({
'url' : row[0],
'title' : row[1],
'visit_count' : row[2],
'timestamp' : row[3],
})

0 comments on commit c42e400

Please sign in to comment.