Skip to content

Commit

Permalink
增加云函数
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyecao committed Jun 9, 2017
1 parent e9ecfd1 commit 26c2e0c
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 89 deletions.
56 changes: 54 additions & 2 deletions card.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,64 @@
from qiniu import put_data, put_file, put_stream
from qiniu import BucketManager, build_batch_copy, build_batch_rename, build_batch_move, build_batch_stat, build_batch_delete
from qiniu import urlsafe_base64_encode, urlsafe_base64_decode
import os
import os
import datetime
from weixin import weixin


class Card(Object):
pass
class Photo(Object):
pass
pass

def temlate_send(card):
user = card.get('user')
openId = user.get('authData').get('lc_weapp').get('openid')
#lc_weapp = authData.get('lc_weapp')
#openId = lc_weapp.get('openid')
template_id = 'kiS8i4JzVR8mZ-gRnS1gaawCLa_dGe0zhy1JFnJTwPE'
form_id = card.get('formId')
payload = {}
payload['touser'] = openId
payload['template_id'] = template_id
payload['form_id'] = form_id
payload['page'] = 'pages/detail/detail?id='+card.id
payload['emphasis_keyword'] = 'keyword3.DATA'
keyword1 = { "value": "码图"}
keyword2 = { "value": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
keyword3 = { "value": "审核通过"}
keyword4 = { "value": "用户创作"}
data = { "keyword1": keyword1, "keyword2": keyword2, "keyword3": keyword3, "keyword4": keyword4 }
payload['data'] = data
app_id = os.environ["WXA_APP_ID"]
app_secret = os.environ["WXA_APP_SECRET"]
wx = weixin(app_id,app_secret)
ret = wx.template_send(payload);
return ret

def review(request,id):
try:
query = Card.query
query.include('user')
card = query.get(id)
if(card):
update = Card.create_without_data(id)
update.set('publish',True)
if(card.get('formId')):
data = temlate_send(card)
#return HttpResponse(json.dumps(str(data)),content_type="application/json")
ret = {'code':200,'message':'审核通过'}
return HttpResponse(json.dumps(ret),content_type="application/json")
else:
ret = {'code':203,'message':'词卡不存在'}
return HttpResponse(json.dumps(ret),content_type="application/json")
except LeanCloudError as e:
if e.code == 101: # 服务端对应的 Class 还没创建
card = ''
return HttpResponse(e,content_type="application/json")
else:
raise e
return HttpResponse(e,content_type="application/json")

def generate(request,id):
try:
Expand Down
61 changes: 60 additions & 1 deletion cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,81 @@ def hello(**params):
else:
return 'Hello, LeanCloud!'

@engine.define
def explore(**params):
page = 1
if 'page' in params:
page = params['page']
count = 10
if 'count' in params:
count = params['count']
skip = (page-1)*count
query = Card.query
query.include('user')
query.not_equal_to('publish', False)
query.add_descending('likes')
count = query.count()
query.limit(10)
query.skip(skip)
cards = query.find()
ret = {}
ret['code'] = 200
dataList = []
for card in cards:
data = {}
data['objectId'] = card.id
data['name'] = card.get('name')
data['content'] = card.get('content')
data['img_url'] = card.get('img_url')
data['shares'] = card.get('shares')
data['likes'] = card.get('likes')
#data['createdAt'] = card.get('createdAt')
#data['updatedAt'] = card.get('updatedAt')
user = {}
_user = card.get('user')
user['id'] = _user.id
user['nickName'] = _user.get('nickName')
user['avatarUrl'] = _user.get('avatarUrl')
user['gender'] = _user.get('gender')
user['city'] = _user.get('city')
user['province'] = _user.get('province')
data['user'] = user
dataList.append(data)
#ret['data'] = cards
return dataList

@engine.define
def maker(**params):
name = params['name']
content = params['content']
file = params['file']
img_url = params['img_url']
username = params['username']
template = params['template']
template = params['template']
card = Card()
card.set('name',name)
card.set('content',content)
card.set('img_url',img_url)
card.set('username',username)
card.set('template',template)
if 'formId' in params:
formId = params['formId']
card.set('formId',formId)
image = _File.create_without_data(file)
if 'userid' not in params:
query = User.query
query.equal_to('username',username)
user = query.first()
card.set('user',user)
else:
userid = params['userid']
user = User.create_without_data(userid)
card.set('user',user)
card.set('user',user)
card.set('image',image)
card.set('publish',False)
card.set('likes',0)
card.set('shares',0)
card.save()
stat = generateCloud(card)
if stat == 'ok':
Expand Down
2 changes: 1 addition & 1 deletion generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,6 @@ def template4(card,msstream):
print('progess:('+str(progress)+'/'+str(count)+')')
progress = progress+1
else:
print('no data')
print('end')


48 changes: 0 additions & 48 deletions movie.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 9 additions & 6 deletions recovery.py → spider/recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class _File(Object):
print('Total:'+str(count))
filelist = query.find()
cardquery = Card.query
userquery = _User.query
for file in filelist:
meta = file.get('metaData')
username = meta['owner']
Expand All @@ -66,15 +67,17 @@ class _File(Object):
count = cardquery.count()

if(count>0):
card = cardquery.first()
data = Card.create_without_data(card.get('objectId'))
data.set('username',username)
data.save()
print(card.get('objectId'))
card = cardquery.first()
data = Card.create_without_data(card.get('objectId'))
data.set('username',username)
user = userquery.get(username)
data.set('user',user)
data.save()

#user = userquery.first()
#print(user.get('id'))
#print(card)
print(username)
#print(username)

else:
print('end')
Expand Down
File renamed without changes.
File renamed without changes.
154 changes: 154 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,157 @@
margin: 0 auto;
width: 960px;
}
/** users **/
.summary{
width:100%;
}
.summary .total{
width: 200px;
font-size: 30px;
text-align: center;
color: #d43939;
margin: 20px auto;
}
.summary .total span{
font-size: 14px;
color: #aaa;
}
.user-list{
list-style: none;
margin: 0;
border: 0;
padding: 0;
}
.user-list::after{
content:'';
display: block;
clear: both;
}
.user-list li{
width:20%;
list-style: none;
margin: 0;
border: 0;
padding: 0;
display: block;
float: left;
}
.user-item{
width:100%;
height: 150px;
margin-bottom: 20px;
}
.user-item .avatar{
width:100px;
margin:0 auto;
}
.user-item .avatar img{
width:100px;
height:100px;
}
.user-item .meta{
margin:20px 0;
}
.user-item .meta .nickname{
text-align: center;
font-size: 14px;
color: #aaa;
}


/** cards **/
.summary{
width:100%;
}
.summary .total{
width: 200px;
font-size: 30px;
text-align: center;
color: #d43939;
margin: 20px auto;
}
.summary .total span{
font-size: 14px;
color: #aaa;
}
.card-list{
list-style: none;
margin: 0;
border: 0;
padding: 0;
}
.card-list::after{
content:'';
display: block;
clear: both;
}
.card-list li{
width:30%;
list-style: none;
margin: 0 10px;
border: 0;
padding: 0;
display: block;
float: left;
}
.card-item{
width:100%;
height: 450px;
margin-bottom: 20px;
}
.photo{
width:100%;
height: 200px;
overflow: hidden;
margin:0 auto;
}
.photo img{
width:100%;
}
.meta{
margin:20px 0;
}
.meta .title{
text-align: center;
font-size: 16px;
height: 20px;
line-height: 20px;
font-weight: 800;
color: #000;
}

.meta .content{
text-align: left;
height: 80px;
overflow: hidden;
font-size: 14px;
line-height: 20px;
margin-top: 20px;
color: #aaa;
}
.userinfo::after{
content: '';
display: block;
clear: both;
}
.userinfo .avatar{
display: block;
float: left;
width: 50px;
height: 50px;
}
.userinfo .avatar img{
width: 50px;
height: 50px;
border-radius: 5px;
}
.userinfo .info{
display: block;
float: left;
height: 50px;
}
.userinfo .info .nickname{
font-size: 14px;
color: #aaa;
padding-left: 10px;
}
Loading

0 comments on commit 26c2e0c

Please sign in to comment.