-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatefinder_api.py
42 lines (36 loc) · 1.3 KB
/
datefinder_api.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
from flask import Flask
from flask_jsonpify import jsonify
from flask import request
app = Flask(__name__)
import json
import datefinder
import datetime
@app.route("/find")
def train():
inp=request.args['text']
cat=request.args['cat']
now = datetime.datetime.now()
matches = list(datefinder.find_dates(inp,strict=True,base_date=now))
matches.sort()
if cat=='Flight' or cat=='flights' or cat=='Flights' or cat=='flight':
try:
ret=jsonify({'Invoice Date': str(matches[0].day) + '/'+ str(matches[0].month) + '/' + str(matches[0].year)})
except:
ret= jsonify({'Invoice Date': 0})
return ret
elif (cat=='hotel') or (cat=='hotels') or (cat=='Hotel') or (cat=='Hotels'):
try:
i=len(matches) - 1
ret=jsonify({'Invoice Date': str(matches[i].day) + '/'+ str(matches[i].month) + '/' + str(matches[i].year)})
except:
ret= jsonify({'Invoice Date': 0})
return ret
else:
try:
ret=jsonify({'Invoice Date': str(matches[0].day) + '/'+ str(matches[0].month) + '/' + str(matches[0].year)})
except:
ret= jsonify({'Invoice Date': 0})
return ret
@app.route("/")
def webfind():
return "underproduction"