-
Notifications
You must be signed in to change notification settings - Fork 3
/
Chrome_Bookmarks_backup.py
99 lines (86 loc) · 3.28 KB
/
Chrome_Bookmarks_backup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import platform
import re
import sys
from shutil import copy
import subprocess
# Variable declarations
userhome = os.path.expanduser('~').replace('\\', '\\\\')
useros = platform.system()
destination = os.path.dirname(os.path.realpath(__file__))
cmd = ['python', 'Chrome_Bookmarks_Parser.py']
def osWalk():
for dirname, dirnames, filenames in os.walk('C:\\'):
for filename in filenames:
if "Bookmarks.bak" in filename and "Chrome" in dirname:
return os.path.join(dirname, filename)
def findChrome():
# Directory references for Chrome pulled from Chromium docs.
# https://www.chromium.org/user-experience/user-data-directory
vernum = platform.version()
# Check if platform is Windows.
if useros == 'Windows':
# Determine if OS is XP.
if re.search('^5\.', vernum):
profilePath = os.path.normpath(os.path.join(
userhome, 'Local Settings\\Application Data\\'
'Google\Chrome\\User Data\\Default'))
filePath = os.path.normpath(os.path.join(
profilePath, "Bookmarks.bak"))
if os.path.exists(filePath):
copy(filePath, destination)
else:
try:
copy(osWalk(), destination)
except Exception as e:
print("{}".format(e))
sys.exit("Cannot find Bookmarks.bak file.")
# Else, assume OS is 10 / 8 / 7 / Vista.
else:
profilePath = os.path.normpath(os.path.join(
userhome, 'AppData\\Local\\Google\\Chrome'
'\\User Data\\Default'))
filePath = os.path.normpath(os.path.join(
profilePath, "Bookmarks.bak"))
if os.path.exists(filePath):
copy(filePath, destination)
else:
try:
copy(osWalk(), destination)
except Exception as e:
print("{}".format(e))
sys.exit("Cannot find Bookmarks.bak file.")
# Check if platform is Mac OS X.
elif useros == 'Darwin':
profilePath = os.path.normpath(os.path.join(
userhome, 'Library/Application Support/Google/Chrome/Default'))
filePath = os.path.normpath(os.path.join(
profilePath, "Bookmarks.bak"))
if os.path.exists(filePath):
copy(filePath, destination)
else:
try:
copy(osWalk(), destination)
except Exception as e:
print("{}".format(e))
sys.exit("Cannot find Bookmarks.bak file.")
# Check if platform is Linux.
elif useros == 'Linux':
profilePath = os.path.normpath(os.path.join(
userhome, '/.config/google-chrome/Default'))
filePath = os.path.normpath(os.path.join(
profilePath, "Bookmarks.bak"))
if os.path.exists(filePath):
copy(filePath, destination)
else:
try:
copy(osWalk(), destination)
except Exception as e:
print("{}".format(e))
sys.exit("Cannot find Bookmarks.bak file.")
try:
findChrome()
subprocess.Popen(cmd)
except Exception as e:
print("{}".format(e))
sys.exit("Oops. Something went wrong.")