Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
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
0
Merge Requests
0
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
钟尚武
physical
Commits
a057d2cd
Commit
a057d2cd
authored
Nov 26, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
69df59b5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
3 deletions
+92
-3
cache.py
libs/cache.py
+5
-0
es.py
libs/es.py
+2
-2
settings.py
physical/settings.py
+1
-1
pick.py
search/utils/pick.py
+31
-0
pick.py
search/views/pick.py
+53
-0
No files found.
libs/cache.py
0 → 100644
View file @
a057d2cd
import
redis
from
django.conf
import
settings
redis_client
=
redis
.
StrictRedis
.
from_url
(
settings
.
REDIS_URL
)
\ No newline at end of file
libs/es.py
View file @
a057d2cd
...
...
@@ -174,4 +174,4 @@ class ESPerform(object):
return
result_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
None
\ No newline at end of file
return
{
"total_count"
:
0
,
"hits"
:[]}
\ No newline at end of file
physical/settings.py
View file @
a057d2cd
...
...
@@ -70,7 +70,7 @@ TEMPLATES = [
WSGI_APPLICATION
=
'physical.wsgi.application'
REDIS_URL
=
"redis://127.0.0.1:6379"
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
...
...
search/utils/pick.py
0 → 100644
View file @
a057d2cd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
logging
import
traceback
import
datetime
from
libs.es
import
ESPerform
from
libs.cache
import
redis_client
class
PickUtils
(
object
):
@classmethod
def
refresh_redis_data
(
cls
,
have_read_celebrity_list
,
redis_cli
,
redis_key
,
key_exist
):
try
:
if
key_exist
:
redis_cli
.
set
(
redis_key
,
have_read_celebrity_list
)
else
:
now
=
datetime
.
datetime
.
now
()
str_end_time
=
"
%
s-
%
s-
%
s 23:59:59"
%
(
now
.
year
,
now
.
month
,
now
.
day
)
end_time
=
datetime
.
datetime
.
strptime
(
str_end_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
valid_seconds
=
(
end_time
-
now
)
.
seconds
redis_cli
.
setex
(
redis_key
,
have_read_celebrity_list
,
valid_seconds
)
return
True
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
\ No newline at end of file
search/views/pick.py
0 → 100644
View file @
a057d2cd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
gm_rpcd.all
import
bind
import
logging
import
traceback
import
json
from
libs.cache
import
redis_client
from
libs.es
import
ESPerform
from
search.utils.pick
import
PickUtils
@bind
(
"physical/search/pick_celebrity"
)
def
pick_celebrity
(
user_id
,
pick_id
,
offset
=
0
,
size
=
10
):
try
:
redis_key
=
"physical:pick_celebrity:"
+
"user_id:"
+
str
(
user_id
)
+
":pick_id:"
+
str
(
pick_id
)
have_read_pick_celebrity_ids
=
list
()
try
:
redis_celebrity_info
=
redis_client
.
get
(
redis_key
)
have_read_pick_celebrity_ids
=
json
.
loads
(
redis_celebrity_info
)
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
q
=
dict
()
q
[
"query"
]
=
{
"pick_id"
:
pick_id
,
"bool"
:{
"must_not"
:{
"terms"
:{
"id"
:
have_read_pick_celebrity_ids
}
}
}
}
q
[
"_source"
]
=
{
"include"
:[
"id"
]
}
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
"pick_celebrity"
,
query_body
=
q
,
offset
=
offset
,
size
=
size
)
recommend_pick_celebrity_list
=
[
item
[
"id"
]
for
item
in
result_dict
[
"hits"
]]
key_exist
=
len
(
have_read_pick_celebrity_ids
)
>
0
PickUtils
.
refresh_redis_data
(
have_read_celebrity_list
=
have_read_pick_celebrity_ids
.
extend
(
recommend_pick_celebrity_list
),
redis_cli
=
redis_client
,
redis_key
=
redis_key
,
key_exist
=
key_exist
)
return
result_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"total_count"
:
0
,
"hits"
:[]}
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