Skip to content

Instantly share code, notes, and snippets.

@Vin-Ren
Created October 17, 2021 12:36
Show Gist options
  • Select an option

  • Save Vin-Ren/b2a9201db0d8d5051599f0a7263acc5f to your computer and use it in GitHub Desktop.

Select an option

Save Vin-Ren/b2a9201db0d8d5051599f0a7263acc5f to your computer and use it in GitHub Desktop.
Python based converter for 'Export Chrome History' chrome extension json output to be importable by 'History Trends Unlimited' chrome extension.
from datetime import datetime
import json
"""An converter for
['Export Chrome History'](https://chrome.google.com/webstore/detail/dihloblpkeiddiaojbagoecedbfpifdj)
chrome extension json output to be importable by
['History Trends Unlimited'](https://chrome.google.com/webstore/detail/pnmchffiealhkdloeffcdnbgdnedheme) chrome extension."""
"""
Name Description Example
URL The visited URL http://scores.sports.example.com/team?id=123456
Host* The hostname of the URL scores.sports.example.com
Domain* The domain of the URL example.com
according to
publicsuffix.org
Visit Time (ms) The visit time, in 1384634958041.754
milliseconds since
01 January, 1970
Visit Time The visit time as a string, 2013-11-16 14:49:18.041
(string) in local time, with
the following format:
YYYY-MM-DD HH24:MI:SS.FFF
Day of Week The day of the week for 6
the visit time. Values
are 0-6.
Sunday=0, Monday=1, etc.
Transition How the browser navigated link
Type to the URL
(as defined here)
Page Title* The title of the visited Life, the Universe, and Everything
URL
"""
def entry_parser(entry):
visit_tm = datetime.fromtimestamp(entry['visitTime']/1000)
data = [entry['url'], '', '',
visit_tm.timestamp()*1000, visit_tm.strftime("%F %H:%M:%S.%f"),
visit_tm.weekday(),
entry['transition'],entry['title']]
return data
def main():
import argparse
parser = argparse.ArgumentParser(__name__, description='Convert json based chrome history to csv based with a bit of modification')
parser.add_argument('source', help='Source file')
parser.add_argument('-o', dest='dest', default='', help='destination file')
args = parser.parse_args()
if not len(args.dest):
args.dest = '.'.join(args.source.split('.')[:-1])+'.tsv'
with open(args.source, 'r', encoding='utf-8') as f:
data = json.load(f)
with open(args.dest, 'w', encoding='utf-8') as f:
lines = ['\t'.join([str(d) for d in entry_parser(entry)]) for entry in data]
f.write('\n'.join(lines))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment