Commit 99e8d186 authored by 王浩's avatar 王浩

Merge branch 'haow/new' into 'master'

add tools virtual_vote api

See merge request !169
parents 13f36757 d58e826b
import time
from utils.base import APIView
from gm_upload import upload, upload_file
from openpyxl import load_workbook
class VirtualVote(APIView):
def post(self, request):
xls_file = request.FILES.get('file')
if not xls_file:
return {'message': u'上传失败,请重新上传', 'code': 500}
wb = load_workbook(xls_file)
data = wb.get_sheet_by_name(wb.get_sheet_names()[0])
columns = [item for item in data.columns]
column_data = columns[0]
column_data = [item.value for item in column_data]
if '用户id' not in column_data:
return {'message': u'文件数据格式错误,请确保内容中有”用户id“标题', 'code': 500}
user_ids = []
for item in column_data:
try:
user_id = int(item)
user_ids.append(user_id)
except:
continue
if not user_ids:
return {'message': u'上传失败,文件第一列不存在user_id数据', 'code': 500}
self.rpc['venus/sun/tools/virtual_vote'](user_ids=user_ids).unwrap()
return {'message': u'上传成功', 'code': 200}
class BatchUpdateTopicTag(APIView):
def post(self, request):
xls_file = request.FILES.get('file')
if not xls_file:
return {'message': u'上传失败,请重新上传', 'code': 500}
wb = load_workbook(xls_file)
data = wb.get_sheet_by_name(wb.get_sheet_names()[0])
rows_data = [item.value for row in data.rows for item in row if item.value]
topic_infos = []
topic_tag_info = {}
for index, item in enumerate(rows_data):
if index == len(rows_data) - 1:
topic_infos.append(topic_tag_info)
if item.startswith('http:'):
print(item)
if topic_tag_info.get('url'):
topic_infos.append(topic_tag_info)
print(topic_tag_info)
topic_tag_info = {}
topic_tag_info['url'] = item.split('-')[0].replace('http://alpha.iyanzhi.com/', '')
continue
if item.split(':')[-1] and topic_tag_info.get('url'):
if not topic_tag_info.get('tags'):
topic_tag_info['tags'] = [item.split(':')[-1]]
else:
topic_tag_info['tags'].append(item.split(':')[-1])
self.rpc['venus/sun/tools/batch_update_topic_tags'](topic_infos=topic_infos).unwrap()
return {'message': u'上传成功', 'code': 200}
...@@ -21,6 +21,8 @@ from .advertise import * ...@@ -21,6 +21,8 @@ from .advertise import *
from .channel_build import * from .channel_build import *
from .commons import * from .commons import *
from .pictorial import * from .pictorial import *
from .tools import *
urlpatterns = [ urlpatterns = [
# 登陆,注销相关 # 登陆,注销相关
...@@ -130,6 +132,10 @@ urlpatterns = [ ...@@ -130,6 +132,10 @@ urlpatterns = [
url(r'^pictorial/create$', PictorialUpdateOrCreate.as_view()), url(r'^pictorial/create$', PictorialUpdateOrCreate.as_view()),
url(r'^pictorial/topics$', PictorialTopics.as_view()), url(r'^pictorial/topics$', PictorialTopics.as_view()),
url(r'^pictorial/user/list$', PictorialUserList.as_view()), url(r'^pictorial/user/list$', PictorialUserList.as_view()),
# 工具
url(r'^tools/virtual_vote$', VirtualVote.as_view()),
url(r'^tools/batch_update_topic_tag$', BatchUpdateTopicTag.as_view()),
] ]
search_urlpatterns = [ search_urlpatterns = [
......
...@@ -19,3 +19,4 @@ celery==4.2.1 ...@@ -19,3 +19,4 @@ celery==4.2.1
kombu==4.2.2.post1 kombu==4.2.2.post1
requests==2.21.0 requests==2.21.0
redis==2.10.6 redis==2.10.6
openpyxl==2.6.2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment