-
Notifications
You must be signed in to change notification settings - Fork 3
/
uploader.py
35 lines (30 loc) · 1.34 KB
/
uploader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
from flask import Flask, jsonify, request
def filenamify_url(url_str):
return_val = url_str
return return_val.replace('http://','').replace('https://','').replace('/','!').replace('#','_').replace('?','_')
app=Flask(__name__)
@app.route("/rest/",methods=['GET','POST'])
def index():
if request.method=='GET':
return jsonify({"msg":"Hello Flask!"})
if request.method=='POST':
#content_type = request.headers.get('Content-Type')
#if (content_type == 'application/json'): OR 'text/plain'
#data = response.json() OR data = request.get_json()
data=json.loads(request.data)
print("Got json data from POST " + str(data))
#tested with curl -XPOST -H "Content-Type: application/json" [email protected] http://10.160.0.24/rest/
#codeRepository or @id values
value=data['codeRepository'] + ".codemeta.json"
filename=filenamify_url(value)
filepath="/tmp/out/" + filename
print("cleaned filename: " + filename)
with open(filepath, 'w', encoding='utf-8') as my_file:
json.dump(data, my_file)
#subprocess.Popen(['sh', '/usr/bin/event-harvest.sh']).wait()
return jsonify(data)
if __name__ == '__main__':
print ("Running Python uploader.py")
from waitress import serve
serve(app,host='127.0.0.1',port=5555)