-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject.py
executable file
·78 lines (66 loc) · 2.27 KB
/
project.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
import os,sys
from flask import Flask, jsonify, render_template, request, abort, make_response
from flask import Response
import lxml.etree as etree
import requests
ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
file_path = ROOT_PATH + "/" + "rsdl"
app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
@app.route('/api/rsdl',methods=['GET','POST'])
def rsdl() :
parser = etree.XMLParser(ns_clean=True)
tree = etree.parse(file_path, parser)
result = etree.tostring(tree, pretty_print = False)
return Response(result, mimetype='application/xml')
@app.route('/')
def webprint():
return render_template('index.html')
@app.route('/api/weather',methods=['GET','POST'])
def weather() :
zip = request.args.get('zip')
parameters = {"zip": zip, "appid": "f0f34657beaede0f908cf2218c677927"}
response=requests.get("http://api.openweathermap.org/data/2.5/weather",parameters)
return Response(response.content,status = response.status_code,mimetype="application/json")
@app.route('/api/sort',methods=['GET','POST'])
def get_sort():
a = request.args.get('array')
a = a.split(',')
a = list(map(int, a))
for i in range(1,len(a)):
tmp = a[i]
j = i
while j>0 and a[j-1]>tmp:
a[j]=a[j-1]
j = j-1
a[j]=tmp
return jsonify({'result': a})
@app.route('/api/wordfreq', methods = ['GET', 'POST'])
def upload_file():
count = 0
a = request.form['word']
f = request.files['file']
for i in f.read(102400).split():
if a == i.strip('.,;:"\''):
count=count+1
return jsonify({"result":count})
@app.route('/api/prime',methods=['GET','POST'])
def get_prime():
a = request.args.get('number')
cou = 0
n = int(a)
if n == 1:
return jsonify({'result': "Not a Prime Number"})
elif n > 1 :
for i in range(2,n):
if n%i == 0 :
cou = cou + 1
if cou == 0:
return jsonify({'result': "Prime Number"})
else:
return jsonify({'result': "Not a Prime Number"})
else:
return jsonify({'result':'error:number should be a positive integer'})
if __name__ == '__main__':
app.run(host='0.0.0.0')