Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 limit 参数不生效 #4

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ubuntu:14.04

# Install Python.
RUN \
apt-get update && \
apt-get install -y python python-dev python-pip python-virtualenv && \
rm -rf /var/lib/apt/lists/*

ADD ./apis /apis

WORKDIR /apis

RUN pip install -r requirements.txt
EXPOSE 80

ENTRYPOINT ["python","index.py"]
21 changes: 0 additions & 21 deletions LICENSE.txt

This file was deleted.

79 changes: 0 additions & 79 deletions README.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/api.py → apis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def search(self, s, stype=1, offset=0, total='true', limit=60):
'type': stype,
'offset': offset,
'total': total,
'limit': 60
'limit': limit
}
return self.httpRequest('POST', action, data)

Expand Down
67 changes: 67 additions & 0 deletions apis/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
#encoding: UTF-8
from api import NetEase
from flask import Flask, jsonify, request
import requests
import json

app = Flask(__name__)

@app.route('/music/search/<q>/<limit>')
def search_music(q, limit):
netease = NetEase()
r = netease.search(q, limit=limit)
if r['code'] != 200:
return jsonify({
"error" : True
})
else:
ids = []
for song in r['result']['songs']:
ids.append(song['id'])
musics = netease.songs_detail(ids)
outputs = []
for music in musics:
outputs.append({
"error" : False,
"name" : music['name'],
"cover" : music['album']['blurPicUrl'],
"album_name": music['album']['name'],
"author": music['artists'][0]['name'],
"url" : music['mp3Url']
})
outputs = {
"error" : False,
"type" : "music",
"musics" : outputs
}
return jsonify(outputs)

@app.route('/music/search', methods=['POST'])
def search():
q = request.form['content']
return search_music(q, 1)

@app.route("/weather/<location>")
def weather(location):
url = "http://api.map.baidu.com/telematics/v3/weather?location=%s&output=json&ak=65VSjZ1CEe8lnb5q3XGzlCUc"%location
print url
r = requests.get(url)
r = r.json()
if r['error'] != 0:
return jsonify({
"error" : True
})
else:
return json.dumps({
"error" : False,
"weathers" : r["results"][0]['weather_data']
})

@app.route('/weather', methods=['POST'])
def check_weather():
location = request.form['content']
return weather(location)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=80,debug=True)
2 changes: 2 additions & 0 deletions apis/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests==2.7.0
flask==0.10.1
60 changes: 0 additions & 60 deletions setup.py

This file was deleted.

11 changes: 0 additions & 11 deletions src/__init__.py

This file was deleted.

Loading