зеркало из https://github.com/mozilla/matchpoint.git
Server up and running.
- Move from __main__.py to app.py. - Update docs. - Add views. - Add Model.to_dict() methods
This commit is contained in:
Родитель
20da95519f
Коммит
6a0e97446e
|
@ -0,0 +1,6 @@
|
|||
#from __future__ import absolute_import
|
||||
|
||||
from matchpoint import app
|
||||
|
||||
|
||||
app.run(debug=True)
|
|
@ -33,7 +33,7 @@ Start MongoDB::
|
|||
|
||||
Start Flask::
|
||||
|
||||
python -m matchpoint
|
||||
python app.py
|
||||
|
||||
By default, the server will now be running on port 5000.
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from flask import Flask
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
import matchpoint.views
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from matchpoint import app
|
||||
|
||||
app.run()
|
|
@ -7,12 +7,26 @@ class Match(Document):
|
|||
keywords = fields.ListField(fields.StringField())
|
||||
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'domains': self.domains,
|
||||
'keywords': self.keywords,
|
||||
}
|
||||
|
||||
|
||||
class InterestVersion(Document):
|
||||
modified = fields.DateTimeField()
|
||||
duration = fields.IntField()
|
||||
threshold = fields.IntField()
|
||||
matches = fields.ListField(fields.DocumentField(Match))
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'duration': self.duration,
|
||||
'threshold': self.threshold,
|
||||
'matches': [m.to_dict() for m in self.matches],
|
||||
}
|
||||
|
||||
|
||||
class Interest(Document):
|
||||
name = fields.StringField()
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
|
||||
from flask import jsonify, request, make_response
|
||||
from mongoalchemy.session import Session
|
||||
|
||||
from matchpoint import app
|
||||
from matchpoint.models import Namespace
|
||||
|
||||
|
||||
@app.route('/api/v1/<name>', methods=['GET', 'HEAD'])
|
||||
def get_namespace(name):
|
||||
s = Session.connect('default') # XXX
|
||||
ns = s.query(Namespace).filter(Namespace.name == name).first()
|
||||
|
||||
if ns is None:
|
||||
return '', 404, {'Content-Type': 'application/json'}
|
||||
|
||||
fmt = lambda s: '/'.join((ns.name, s))
|
||||
interests = dict(((fmt(i.name), i.current.to_dict()) for i in ns.interests))
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Last-Modified': ns.modified.isoformat() + 'Z',
|
||||
}
|
||||
|
||||
return json.dumps(interests), 200, headers
|
Загрузка…
Ссылка в новой задаче