Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added external api for project entry, now only support name

  • Loading branch information...
commit a214fac7425d32bc2854807652ab4e0e1c8a5981 1 parent 7d14d17
@sweemeng authored
Showing with 53 additions and 0 deletions.
  1. +45 −0 scrapedump/project/api.py
  2. +8 −0 scrapedump/webapp.py
View
45 scrapedump/project/api.py
@@ -105,3 +105,48 @@ def get_project(self,name):
return temp
+class EntryApi(MethodView):
+ def get(self,project_id,entry_id):
+ project = Project()
+ project.get(project_id)
+ data = project.get_entry(entry_id)
+ data = json.dumps(data,default=bson.json_util.default)
+ resp = Response(data,status=200,mimetype='application/json')
+ resp.headers['Link'] = 'http://localhost:5000'
+
+ def post(self,project_id):
+ api_key = request.args.get('api_key')
+ if not authorized(api_key,project_id):
+ return jsonify({'status':False})
+ project = Project()
+ project.get(project_id)
+ data = request.json
+ project.add_entry(data['name'],data['description'],data['source'])
+ return jsonify({'status':True,'msg':'entry created'})
+
+ def put(self,project_id,entry_id):
+ api_key = request.args.get('api_key')
+ if not authorized(api_key,project_id):
+ return jsonify({'status':False})
+
+ project = Project()
+ project.get(project_id)
+ data = request.json
+ entry = project.project.entry[entry_id]
+ entry['description'] = data['description']
+ entry['source'] = data['source']
+ project.save()
+ return jsonify({'status':True,'msg':'entry updated'})
+
+ def delete(self,project_id,entry_id):
+ api_key = request.args.get('api_key')
+ if not authorized(api_key,project_id):
+ return jsonify({'status':False})
+
+ project = Project()
+ project.get(project_id)
+ del(project.project.entry[entry_id])
+ del(project.project.stats[entry_id])
+ del(project.project.export[entry_id])
+ del(project.project.input_file[entry_id])
+ project.save()
View
8 scrapedump/webapp.py
@@ -21,6 +21,7 @@
from api.data import DataApi
from project.api import ProjectApi
+from project.api import EntryApi
from user.model import User
from user.permission import admin_permission
from user.permission import user_permission
@@ -86,6 +87,7 @@ def unauthorized():
api_views = DataApi.as_view('api')
project_api = ProjectApi.as_view('project')
+entry_api = EntryApi.as_view('entry')
app.add_url_rule('/api/project/',defaults={'project_id':None},
view_func=project_api,methods=['GET',])
@@ -99,6 +101,12 @@ def unauthorized():
app.add_url_rule('/api/db/<project_id>/<entry>/<entry_id>/',
view_func=api_views,methods=['GET','PUT','DELETE',])
+app.add_url_rule('/api/entry/<project_id>/',defaults={'entry_id':None},
+ view_func=entry_api,methods=['GET',])
+app.add_url_rule('/api/entry/<project_id>/',view_func=entry_api,methods=['POST',])
+app.add_url_rule('/api/entry/<project_id>/<entry_id>/',
+ view_func=entry_api,methods=['GET','PUT','DELETE',])
+
app.register_blueprint(frontend,url_prefix='')
Please sign in to comment.
Something went wrong with that request. Please try again.