-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.1.0' | ||
__version__ = "0.1.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import appdirs | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
# fafi | ||
import db | ||
|
||
|
||
def bookmarks_path(): | ||
return appdirs.user_data_dir("Firefox") | ||
|
||
|
||
def get_bookmarks_db(): | ||
|
||
# set the path of firefox folder with databases | ||
bm_path = bookmarks_path() | ||
|
||
# recursively walk tha path | ||
for root, dirs, files in os.walk(bm_path + "/Profiles/"): | ||
for name in files: | ||
if name == "places.sqlite": | ||
db_path = str(root + os.sep + name).strip() | ||
print("Indexing: ", db_path) | ||
return db_path | ||
return None | ||
|
||
|
||
def db_path(): | ||
data_dir = appdirs.user_data_dir("fafi") | ||
if not os.path.exists(data_dir): | ||
os.makedirs(data_dir) | ||
db_path = data_dir + "/data.sqlite" | ||
print("Using: " + db_path) | ||
return db_path | ||
|
||
|
||
# get bookmarks from firefox sqlite database file and print all | ||
def select_bookmarks(cursor): | ||
bookmarks_query = """ | ||
SELECT DISTINCT | ||
url, moz_places.title from moz_places | ||
JOIN | ||
moz_bookmarks on moz_bookmarks.fk=moz_places.id | ||
WHERE | ||
moz_places.url like 'http%' | ||
ORDER BY | ||
dateAdded desc | ||
""" | ||
db.execute_query(cursor, bookmarks_query) | ||
return cursor | ||
|
||
|
||
def create_temporary_copy(path): | ||
temp_dir = tempfile.gettempdir() | ||
temp_path = os.path.join(temp_dir, "temp_file_name") | ||
shutil.copy2(path, temp_path) | ||
return temp_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sqlite3 | ||
|
||
|
||
def create_connection(db_file): | ||
""" create a database connection to the SQLite database | ||
specified by db_file | ||
:param db_file: database file | ||
:return: Connection object or None | ||
""" | ||
conn = None | ||
try: | ||
conn = sqlite3.connect(db_file) | ||
return conn | ||
except sqlite3.Error as e: | ||
print(e) | ||
|
||
return conn | ||
|
||
|
||
def create_table(conn, table_sql): | ||
""" create a table from the table_sql statement | ||
:param conn: Connection object | ||
:param table_sql: a CREATE TABLE statement | ||
:return: | ||
""" | ||
c = conn.cursor() | ||
c.execute(table_sql) | ||
conn.commit() | ||
|
||
|
||
# execute a query on sqlite cursor | ||
def execute_query(cursor, query): | ||
try: | ||
cursor.execute(query) | ||
except Exception as error: | ||
print(str(error) + "\n " + query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters