Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
mentha
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
mentha
Commits
bd3ced31
Commit
bd3ced31
authored
Dec 07, 2020
by
李小芳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
同步
parent
e43657fb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
cache.py
utils/cache.py
+1
-0
pic.py
utils/pic.py
+49
-0
No files found.
utils/cache.py
View file @
bd3ced31
...
...
@@ -126,4 +126,5 @@ class RedisCache(object):
common_cache
=
RedisWrapper
(
'__common_cache'
,
settings
.
REDIS_TOPIC_1ST
[
'page_cache'
])
picture_tool_cache
=
RedisWrapper
(
'__picture_tool'
,
settings
.
REDIS_TOPIC_1ST
[
'page_cache'
])
common_cache_wrapper
=
RedisCache
(
common_cache
)
utils/pic.py
0 → 100644
View file @
bd3ced31
# coding:utf-8
import
hashlib
import
json
import
requests
"""图片相关"""
info_suffix
=
'-imageinfo'
class
PictureTools
(
object
):
@staticmethod
def
info
(
url
):
try
:
img_info
=
json
.
loads
(
requests
.
get
(
url
=
url
+
info_suffix
)
.
text
)
return
img_info
except
:
return
{}
@classmethod
def
is_dynamic
(
cls
,
url
):
from
.cache
import
picture_tool_cache
if
not
url
:
return
False
encode_url
=
url
if
not
isinstance
(
url
,
bytes
):
encode_url
=
url
.
encode
(
'utf-8'
)
k
=
hashlib
.
md5
(
encode_url
)
.
hexdigest
()
raw
=
picture_tool_cache
.
get
(
k
)
if
raw
is
not
None
:
is_dynamic
=
True
if
int
(
raw
)
else
False
return
is_dynamic
img_info
=
cls
.
info
(
url
)
print
(
img_info
)
fmt
=
img_info
.
get
(
"format"
,
''
)
is_dynamic
=
True
if
fmt
.
lower
()
in
(
'gif'
,
'webp'
)
else
False
picture_tool_cache
.
set
(
k
,
int
(
is_dynamic
))
return
is_dynamic
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment