urlicon 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- urlicon/{string_cache.py → simple_cache.py} +17 -4
- urlicon/urlicon.py +13 -4
- {urlicon-0.1.0.dist-info → urlicon-0.2.0.dist-info}/METADATA +6 -6
- urlicon-0.2.0.dist-info/RECORD +7 -0
- urlicon-0.1.0.dist-info/RECORD +0 -7
- {urlicon-0.1.0.dist-info → urlicon-0.2.0.dist-info}/WHEEL +0 -0
- {urlicon-0.1.0.dist-info → urlicon-0.2.0.dist-info}/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class simple_cache:
|
|
5
5
|
cache_folder: str | None = None
|
|
6
|
-
cache_files_extension: str = "
|
|
6
|
+
cache_files_extension: str = "cache"
|
|
7
7
|
|
|
8
8
|
def __init__(self, cache_folder: str | None = None):
|
|
9
9
|
if cache_folder is not None:
|
|
@@ -45,7 +45,7 @@ class string_cache:
|
|
|
45
45
|
|
|
46
46
|
new_file_name = f"{new_file_index}.{self.cache_files_extension}"
|
|
47
47
|
new_file_path = os.path.join(cache_folder, new_file_name)
|
|
48
|
-
with open(new_file_path, "
|
|
48
|
+
with open(new_file_path, "wb") as new_file_writer:
|
|
49
49
|
new_file_writer.write(text)
|
|
50
50
|
|
|
51
51
|
@safe_cache_id
|
|
@@ -90,7 +90,12 @@ class string_cache:
|
|
|
90
90
|
cached_file_path = os.path.join(cache_folder, cached_file_name)
|
|
91
91
|
if not os.path.exists(cached_file_path):
|
|
92
92
|
return None
|
|
93
|
-
|
|
93
|
+
if self.is_file_binary(cached_file_path):
|
|
94
|
+
read_mode = "rb"
|
|
95
|
+
else:
|
|
96
|
+
read_mode = "r"
|
|
97
|
+
|
|
98
|
+
with open(cached_file_path, read_mode) as cached_file_reader:
|
|
94
99
|
code = cached_file_reader.read()
|
|
95
100
|
return code
|
|
96
101
|
|
|
@@ -114,3 +119,11 @@ class string_cache:
|
|
|
114
119
|
|
|
115
120
|
tmpdirname = tempfile.mkdtemp()
|
|
116
121
|
return tmpdirname
|
|
122
|
+
|
|
123
|
+
def is_file_binary(self, file_path: str) -> bool:
|
|
124
|
+
try:
|
|
125
|
+
with open(file_path, "r") as fp:
|
|
126
|
+
fp.read(16)
|
|
127
|
+
return False
|
|
128
|
+
except UnicodeDecodeError:
|
|
129
|
+
return True
|
urlicon/urlicon.py
CHANGED
|
@@ -7,12 +7,12 @@ from bs4 import BeautifulSoup
|
|
|
7
7
|
from dotenv import load_dotenv
|
|
8
8
|
|
|
9
9
|
from urlicon import urls
|
|
10
|
-
from urlicon.
|
|
10
|
+
from urlicon.simple_cache import simple_cache
|
|
11
11
|
|
|
12
12
|
load_dotenv()
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
cache =
|
|
14
|
+
SIMPLE_CACHE_ROOT_DIR = os.getenv("SIMPLE_CACHE_ROOT_DIR", None)
|
|
15
|
+
cache = simple_cache(cache_folder=SIMPLE_CACHE_ROOT_DIR)
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def get_url_icon(url):
|
|
@@ -152,6 +152,15 @@ def requests_get(url):
|
|
|
152
152
|
if req.status_code != 200:
|
|
153
153
|
return None
|
|
154
154
|
|
|
155
|
-
code = req.
|
|
155
|
+
code = req.content
|
|
156
156
|
cache.set(text=code, cache_id=cache_prefix + url)
|
|
157
157
|
return code
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def is_file_binary(file_path: str) -> bool:
|
|
161
|
+
try:
|
|
162
|
+
with open(file_path, "r") as fp:
|
|
163
|
+
fp.read(16)
|
|
164
|
+
return False
|
|
165
|
+
except UnicodeDecodeError:
|
|
166
|
+
return True
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: urlicon
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: `URLicon` helps you to discover an possible icon from a URL.
|
|
5
5
|
Author-email: Cesar Cardoso <hello@cesarcardoso.cc>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -10,7 +10,7 @@ Requires-Dist: bs4>=0.0.2
|
|
|
10
10
|
Requires-Dist: dotenv>=0.9.9
|
|
11
11
|
Requires-Dist: requests>=2.32.5
|
|
12
12
|
|
|
13
|
-
# URLicon - v0.
|
|
13
|
+
# URLicon - v0.2.0
|
|
14
14
|
|
|
15
15
|
`URLicon` helps you to discover an possible icon from a URL.
|
|
16
16
|
|
|
@@ -45,16 +45,16 @@ print("icon:", icon_url)
|
|
|
45
45
|
`URLicon` use a simple "cache" method to avoid unecessary URL requests.
|
|
46
46
|
It uses a [temp dir](https://docs.python.org/3/library/tempfile.html) for each
|
|
47
47
|
execution. But you can define a your own directory and use the cache as much as
|
|
48
|
-
you want setting `
|
|
48
|
+
you want setting `SIMPLE_CACHE_ROOT_DIR` env var.
|
|
49
49
|
|
|
50
50
|
```python
|
|
51
|
-
|
|
52
|
-
cache =
|
|
51
|
+
SIMPLE_CACHE_ROOT_DIR = os.getenv("SIMPLE_CACHE_ROOT_DIR", None)
|
|
52
|
+
cache = simple_cache(cache_folder=SIMPLE_CACHE_ROOT_DIR)
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
And you can clean the cache with:
|
|
56
56
|
```python
|
|
57
|
-
urlicon.
|
|
57
|
+
urlicon.simple_cache.clean()
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
## See Also
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
urlicon/simple_cache.py,sha256=hQAkStSiT2dQa3OBVi8C_5AH8wWgoiL03VqI0q_Z8i4,4488
|
|
2
|
+
urlicon/urlicon.py,sha256=7yVyDhIdr2GtbFZ5TBCP6cMT3pw4V0nNbRSJ3M62LH4,4265
|
|
3
|
+
urlicon/urls.py,sha256=ErdlgRva3bxs6HuBX2iHng21PqpWGIF1etZFToJq4jc,2235
|
|
4
|
+
urlicon-0.2.0.dist-info/METADATA,sha256=46rMyA1xHnoSyKg-moWW7KMjUZ2lyOcvLbzr6HVyZaE,1713
|
|
5
|
+
urlicon-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
urlicon-0.2.0.dist-info/top_level.txt,sha256=Jts8QbeWp-6xANJ9KVj3CHk6L-8D950AQ_ZKXmF4YGI,8
|
|
7
|
+
urlicon-0.2.0.dist-info/RECORD,,
|
urlicon-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
urlicon/string_cache.py,sha256=fY4ZtAdZC3PDfdotuHZmuSAcQxQLA4WyJJ6pmOUZZMc,4130
|
|
2
|
-
urlicon/urlicon.py,sha256=zcbevt29l2xbr14z9jFxz64TrvyS8O-fk29mCSQIoqI,4066
|
|
3
|
-
urlicon/urls.py,sha256=ErdlgRva3bxs6HuBX2iHng21PqpWGIF1etZFToJq4jc,2235
|
|
4
|
-
urlicon-0.1.0.dist-info/METADATA,sha256=1SEq8BOcKYjoGQhcFFrgQFscuJoe0Sv0wDcXyq3YBLw,1713
|
|
5
|
-
urlicon-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
-
urlicon-0.1.0.dist-info/top_level.txt,sha256=Jts8QbeWp-6xANJ9KVj3CHk6L-8D950AQ_ZKXmF4YGI,8
|
|
7
|
-
urlicon-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|