<commit_before>#-*- coding:utf-8 -*-
from tools.httptools import Route
from models import Music
from tools.config import Config
import logging
logging.basicConfig(level=logging.ERROR)
import time
import random
try:
	from qiniu import Auth
	import qiniu.config
except ImportError:
	logging.error("can't import 'qiniu' module")


@Route.get("/music")
def get_music_handler(app):
	m=Music()
	max_id=(yield from m.max('id'))[0]['id']
	if max_id<7:
		max_id=7
	rand_id=random.randrange(1,max_id-6)
	if rand_id>max_id:
		rand_id=max_id-6
	data=(yield from m.fields(['music_name','music_url']).where('id','>=',rand_id).limit(6).findall())
	ret={}
	ret['code']=200
	ret['msg']='ok'
	ret['type']=3
	ret['data']=data
	return ret

@Route.get("/music/token",auth=True)
def post_music_token_handler(app):
	auth=Auth(Config.filesystem.access_key,Config.filesystem.secret_key)
	policy={
		'callbackUrl':'http://localhost/music/callback',
		'callbackBody':'filename=$(fname)&filesize=$(fsize)',
	}
	token=auth.upload_token(Config.filesystem.bucket_name,'',0,policy)
	return {"_token":token}
@Route.get("/music/callback")
def post_music_callback_handler(app):
	m=Music()
	m.uid=1
	m.upload_at=str(time.time())
	m.type_id=1
	m.belong_id=1
	m.music_name='CountingStar'
	m.music_url='http://7xs7oc.com1.z0.glb.clouddn.com/music%2FJason%20Chen%20-%20Counting%20Stars.mp3'
	ret=(yield from m.save())
	if ret:
		return {'code':200,'msg':'o:ok'}<commit_msg>add handler for all music request<commit_after>#-*- coding:utf-8 -*-
from tools.httptools import Route
from models import Music
from tools.config import Config
import logging
logging.basicConfig(level=logging.ERROR)
import time
import random
try:
	from qiniu import Auth
	import qiniu.config
except ImportError:
	logging.error("can't import 'qiniu' module")


@Route.get("/music")
def get_music_handler(app):
	max_id=(yield from Music().max('id'))[0]['id']
	if max_id<7:
		max_id=7
	rand_id=random.randrange(1,max_id-6)
	#data=(yield from m.fields(['music_name','music_url']).where('id','>=',rand_id).limit(6).findall())
	data=(yield from Music().fields({'music_name':'title','music_url':'url'}).where('id','>=',rand_id).limit(6).findall())
	ret={}
	ret['code']=200
	ret['msg']='ok'
	ret['type']=3
	ret['data']=data
	return ret

@Route.get("/music/token",auth=True)
def post_music_token_handler(app):
	auth=Auth(Config.filesystem.access_key,Config.filesystem.secret_key)
	policy={
		'callbackUrl':'http://localhost/music/callback',
		'callbackBody':'filename=$(fname)&filesize=$(fsize)&key=$(key)',
	}
	token=auth.upload_token(Config.filesystem.bucket_name,'',0,policy)
	return {"_token":token}
@Route.get("/music/callback")
def post_music_callback_handler(app):
	m=Music()
	m.uid=1
	m.upload_at=str(time.time())
	m.type_id=1
	m.belong_id=1
	m.music_name='CountingStar'
	m.music_url='http://7xs7oc.com1.z0.glb.clouddn.com/music%2FJason%20Chen%20-%20Counting%20Stars.mp3'
	ret=(yield from m.save())
	if ret:
		return {'code':200,'msg':'ok'}
{'fraction_non_alphanumeric': 0.18842530282637954, 'fraction_numerical': 0.02220726783310902, 'mean_word_length': 6.970509383378016, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5354331', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1145, 'n_words': 173}