Commit 2615f6a8 authored by 王浩's avatar 王浩

Merge branch 'haow/dev' into 'test'

Haow/dev

See merge request alpha/saturn!3
parents 27daf69c 4205fb3e
......@@ -3,8 +3,10 @@ from django.conf.urls import url
from .views import user
from .views import topic
from .views import tag
urlpatterns = [
url(r'^v1/update_grasp_status$', user.UpdateGraspStatus.as_view(), name='update_grasp_status$'),
url(r'^v1/create_topic_for_batch$', topic.CreateTopicForBatch.as_view(), name='create_topic_for_batch'),
url(r'^v1/create_tag_for_batch$', tag.CreateTagForBatch.as_view(), name='create_tag_for_batch'),
]
from xlrd import open_workbook
from urllib.request import urlopen, Request
from urllib import parse
import json
import math
import requests
PAGE_SIZE = 100
def read_excel():
wb = open_workbook(filename='/Users/apple/Desktop/nice_tag20181225.xlsx')
sheet1 = wb.sheet_by_index(0)
tags = []
for i in range(1, sheet1.nrows):
item = sheet1.row_values(i)
if item:
if item[1]:
tags.append({'name': item[1], 'img': item[-1]})
print(len(tags))
return tags
def create_tags(tags):
url='http://127.0.0.1:8090/api/v1/create_tag_for_batch'
post_data = json.dumps(tags)
textmod= {"tags": post_data}
print(textmod)
req = requests.post(url=url, data=textmod)
print(req.text)
def process():
tags = read_excel()
# create_tags([{"name": "aaa", "img": "http://www.baidu.com"}, {"name": "bbb", "img": "http://www.baidu.com"}])
count = math.ceil(len(tags) / PAGE_SIZE)
print(count)
for i in range(0, count):
if i == 5:
break
if i < 4:
continue
print(i)
item = tags[PAGE_SIZE * i: PAGE_SIZE * i + PAGE_SIZE]
# print(item, len(item))
create_tags(item)
if __name__ == "__main__":
process()
import json
from api.views.base_view import BaseView
from api.utils.sensitive import Sensitive
class CreateTagForBatch(BaseView):
"""
内部使用,批量建标签
"""
def post(self, request):
tag_list = json.loads(request.POST.get("tags", '[]'))
print(request.POST)
tags = []
# 敏感词检测,获取可用的帖子
check_info = Sensitive.check([item["name"] for item in tag_list if item.get("name")])
for tag in tag_list:
succ = check_info.get(tag.get("name")) if tag.get("name") else True
if not succ:
tags.append(tag)
error, data = self.call_rpc('venus/community/tag/batch_create_not_classify', data=tags)
if error:
return self.error(error)
return self.ok(data=data)
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