Skip to content

Commit 08afaec

Browse files
authored
Merge pull request #145 from pawelmalak/feature
Version 1.7.4
2 parents 88694c7 + 4f2ba0a commit 08afaec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1536
-1114
lines changed
File renamed without changes.

.dev/bookmarks_importer.py

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import sqlite3
2+
from bs4 import BeautifulSoup
3+
from PIL import Image, UnidentifiedImageError
4+
from io import BytesIO
5+
import re
6+
import base64
7+
from datetime import datetime, timezone
8+
import os
9+
import argparse
10+
11+
12+
"""
13+
Imports html bookmarks file into Flame.
14+
Tested only on Firefox html exports so far.
15+
16+
Usage:
17+
python3 bookmarks_importer.py --bookmarks <path to bookmarks file> --data <path to flame data dir>
18+
19+
"""
20+
21+
parser = argparse.ArgumentParser()
22+
parser.add_argument('--bookmarks', type=str, required=True)
23+
parser.add_argument('--data', type=str, required=True)
24+
args = parser.parse_args()
25+
26+
bookmarks_path = args.bookmarks
27+
data_path = args.data
28+
created = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] + datetime.now().astimezone().strftime(" %z")
29+
updated = created
30+
if data_path[-1] != '/':
31+
data_path = data_path + '/'
32+
33+
34+
35+
36+
def Base64toPNG(codec, name):
37+
38+
"""
39+
Convert base64 encoded image to png file
40+
Reference: https://github.com/python-pillow/Pillow/issues/3400#issuecomment-428104239
41+
42+
Parameters:
43+
codec (str): icon in html bookmark format.e.g. 'data:image/png;base64,<image encoding>'
44+
name (str): name for export file
45+
46+
Returns:
47+
icon_name(str): name of png output E.g. 1636473849374--mybookmark.png
48+
None: if image not produced successfully
49+
50+
"""
51+
52+
try:
53+
unix_t = str(int(datetime.now(tz=timezone.utc).timestamp() * 1000))
54+
icon_name = unix_t + '--' + re.sub(r'\W+', '', name).lower() + '.png'
55+
image_path = data_path + 'uploads/' + icon_name
56+
if os.path.exists(image_path):
57+
return image_path
58+
base64_data = re.sub('^data:image/.+;base64,', '', codec)
59+
byte_data = base64.b64decode(base64_data)
60+
image_data = BytesIO(byte_data)
61+
img = Image.open(image_data)
62+
img.save(image_path, "PNG")
63+
return icon_name
64+
except UnidentifiedImageError:
65+
return None
66+
67+
68+
69+
70+
def FlameBookmarkParser(bookmarks_path):
71+
72+
"""
73+
Parses HTML bookmarks file
74+
Reference: https://stackoverflow.com/questions/68621107/extracting-bookmarks-and-folder-hierarchy-from-google-chrome-with-beautifulsoup
75+
76+
Parameters:
77+
bookmarks_path (str): path to bookmarks.html
78+
79+
Returns:
80+
None
81+
82+
"""
83+
84+
soup = BeautifulSoup()
85+
with open(bookmarks_path) as f:
86+
soup = BeautifulSoup(f.read(), 'lxml')
87+
88+
dt = soup.find_all('dt')
89+
folder_name =''
90+
for i in dt:
91+
n = i.find_next()
92+
if n.name == 'h3':
93+
folder_name = n.text
94+
continue
95+
else:
96+
url = n.get("href")
97+
website_name = n.text
98+
icon = n.get("icon")
99+
if icon != None:
100+
icon_name = Base64toPNG(icon, website_name)
101+
cat_id = AddFlameCategory(folder_name)
102+
AddFlameBookmark(website_name, url, cat_id, icon_name)
103+
104+
105+
106+
107+
def AddFlameCategory(cat_name):
108+
"""
109+
Parses HTML bookmarks file
110+
111+
Parameters:
112+
cat_name (str): category name
113+
114+
Returns:
115+
cat_id (int): primary key id of cat_name
116+
117+
"""
118+
119+
120+
121+
con = sqlite3.connect(data_path + 'db.sqlite')
122+
cur = con.cursor()
123+
count_sql = ("SELECT count(*) FROM categories WHERE name = ?;")
124+
cur.execute(count_sql, [cat_name])
125+
count = int(cur.fetchall()[0][0])
126+
if count > 0:
127+
getid_sql = ("SELECT id FROM categories WHERE name = ?;")
128+
cur.execute(getid_sql, [cat_name])
129+
cat_id = int(cur.fetchall()[0][0])
130+
return cat_id
131+
132+
is_pinned = 1
133+
134+
insert_sql = "INSERT OR IGNORE INTO categories(name, isPinned, createdAt, updatedAt) VALUES (?, ?, ?, ?);"
135+
cur.execute(insert_sql, (cat_name, is_pinned, created, updated))
136+
con.commit()
137+
138+
getid_sql = ("SELECT id FROM categories WHERE name = ?;")
139+
cur.execute(getid_sql, [cat_name])
140+
cat_id = int(cur.fetchall()[0][0])
141+
return cat_id
142+
143+
144+
145+
146+
def AddFlameBookmark(website_name, url, cat_id, icon_name):
147+
con = sqlite3.connect(data_path + 'db.sqlite')
148+
cur = con.cursor()
149+
if icon_name == None:
150+
insert_sql = "INSERT OR IGNORE INTO bookmarks(name, url, categoryId, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?);"
151+
cur.execute(insert_sql, (website_name, url, cat_id, created, updated))
152+
con.commit()
153+
else:
154+
insert_sql = "INSERT OR IGNORE INTO bookmarks(name, url, categoryId, icon, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?);"
155+
cur.execute(insert_sql, (website_name, url, cat_id, icon_name, created, updated))
156+
con.commit()
157+
158+
159+
160+
161+
162+
163+
164+
165+
if __name__ == "__main__":
166+
FlameBookmarkParser(bookmarks_path)

.dev/getMdi.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Script to get all icon names from materialdesignicons.com
2+
const getMdi = () => {
3+
const icons = document.querySelectorAll('#icons div span');
4+
const names = [...icons].map((icon) => icon.textContent.replace('mdi-', ''));
5+
const output = names.map((name) => ({ name }));
6+
output.pop();
7+
const json = JSON.stringify(output);
8+
console.log(json);
9+
};

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
PORT=5005
22
NODE_ENV=development
3-
VERSION=1.7.3
3+
VERSION=1.7.4

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
data
33
public
4+
!client/public
45
build.sh

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### v1.7.4 (2021-11-08)
2+
- Added option to set custom greetings and date ([#103](https://github.com/pawelmalak/flame/issues/103))
3+
- Fallback to web search if local search has zero results ([#129](https://github.com/pawelmalak/flame/issues/129))
4+
- Added iOS "Add to homescreen" icon ([#131](https://github.com/pawelmalak/flame/issues/131))
5+
- Added experimental script to import bookmarks ([#141](https://github.com/pawelmalak/flame/issues/141))
6+
- Added 3 new themes
7+
18
### v1.7.3 (2021-10-28)
29
- Fixed bug with custom CSS not updating
310

Dockerfile

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
FROM node:14-alpine
2-
3-
RUN apk update && apk add --no-cache nano curl
1+
FROM node:14 as builder
42

53
WORKDIR /app
64

@@ -18,6 +16,12 @@ RUN mkdir -p ./public ./data \
1816
&& mv ./client/build/* ./public \
1917
&& rm -rf ./client
2018

19+
FROM node:14-alpine
20+
21+
COPY --from=builder /app /app
22+
23+
WORKDIR /app
24+
2125
EXPOSE 5005
2226

2327
ENV NODE_ENV=production

Dockerfile.multiarch

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
FROM node:14-alpine
2-
3-
RUN apk update && apk add --no-cache nano curl
1+
FROM node:14 as builder
42

53
WORKDIR /app
64

75
COPY package*.json ./
86

9-
RUN apk --no-cache --virtual build-dependencies add python make g++ \
10-
&& npm install --production
7+
RUN npm install --production
118

12-
COPY . .
9+
COPY . .
1310

1411
RUN mkdir -p ./public ./data \
1512
&& cd ./client \
1613
&& npm install --production \
1714
&& npm run build \
1815
&& cd .. \
1916
&& mv ./client/build/* ./public \
20-
&& rm -rf ./client \
21-
&& apk del build-dependencies
17+
&& rm -rf ./client
18+
19+
FROM node:14-alpine
20+
21+
COPY --from=builder /app /app
22+
23+
WORKDIR /app
2224

2325
EXPOSE 5005
2426

2527
ENV NODE_ENV=production
2628

27-
CMD ["node", "server.js"]
29+
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)