forked from shangma/Bookmark-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookmarkreader.py
More file actions
107 lines (94 loc) · 2.37 KB
/
bookmarkreader.py
File metadata and controls
107 lines (94 loc) · 2.37 KB
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
100
101
102
103
104
105
106
107
'''
Author : Jay Rambhia
email : jayrambhia777@gmail.com
Git : https://github.com/jayrambhia
gist : https://gist.github.com/jayrambhia
=============================================
Name : bookmarkreader
Repo : Bookmark-Manager
Git : https://github.com/jayrambhia/Bookmark-Manager
version : 0.2
'''
import gdbm
import pickle
import os
def __getDB():
'''
Returns bookmark gdbm databse if found
'''
filename = __getFilename()
if not filename:
return
if os.path.isfile(filename):
db = gdbm.open(filename,'c')
if db.has_key('@author@'):
name, email, add_date = pickle.loads(db['@author@'])
if name == 'Jay Rambhia'and email == 'jayrambhia777@gmail.com':
return db
print 'Bookmark database not found'
return None
def __getFilename():
'''
Returns path of the bookmark database if found
'''
dirs = os.listdir('.')
if 'bookmarkDB' in dirs:
filename = 'bookmarkDB'
file_path = os.path.join(os.path.abspath('.'),filename)
print file_path
return file_path
else:
print 'bookmark database not found'
print '1. Search for bookmark database'
print '2. Enter bookmark database name'
print '3. Exit'
n = int(raw_input())
if n == 1 :
for path, dirs, filenames in os.walk(os.environ['HOME']):
if 'bookmarkDB' in filenames:
break
file_path = os.path.join(path,'bookmarkDB')
return file_path
elif n == 2:
filename = str(raw_input('File Name: '))
print filename
if os.path.isfile(filename):
path, file_name = os.path.split(filename)
print path
if path:
return filename
file_path = os.path.join(os.path.abspath('.'),filename)
return file_path
else:
print 'Bookamrk database not found'
return None
elif n==3:
print 'Exit'
return None
else:
__getFilename()
def bookmarkReader(db):
'''
Prints all the bookmarks from the bookmark database
'''
if not db:
return
keys = db.keys()
author_tuple = pickle.loads(db['@author@'])
name, email, add_date = author_tuple
print 'Author:',name
print 'email:',email
keys.remove('@author@')
bookmark_list = []
for key in keys:
bookmark_tuple = (key,pickle.loads(db[key]))
bookmark_list.append(bookmark_tuple)
bookmark_list.sort(key = lambda b:b[1][1])
for bookmark in bookmark_list:
print bookmark[1][0],'tag:',bookmark[1][1]
print bookmark[0]
print ''
return
if __name__ == '__main__':
db = __getDB()
bookmarkReader(db)