-
Notifications
You must be signed in to change notification settings - Fork 0
/
flscript.py
72 lines (67 loc) · 2.62 KB
/
flscript.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
from flask import Flask, Response, request
from flask import render_template, make_response
from flask_restful import Resource, Api
import numpy as np
import psycopg2
app = Flask(__name__)
api = Api(app)
def formt(list1):
return str(list1).replace('(','').replace(')','').replace(',','')
def formt1(list1):
sa1 = str(list1).replace('(','').replace(')','')
return sa1[2:len(sa1)-3]
def formt2(list1):
sample = str(list1).replace('(','').replace(')','').replace(',','').replace('[','').replace("]",'')
ec = 0
for i in range (len(sample)):
if sample[i] == "'":
ec = ec+1
if ec%2 == 0 and i < len(sample)-1:
sa = list(sample)
sa[i] = ","
sample = ''.join(sa)
return sample.replace('(','').replace(')','').replace("'",'')
def unique(x):
return list(dict.fromkeys(x))
class data():
def __init__(self, Title, Author, Journal, Url):
self.Title = Title
self.Author = Author
self.Journal = Journal
self.Url = Url
class Display(Resource):
def get(self, string1):
input_keyword = string1
con = psycopg2.connect(host = 'localhost', database = '<Database Name>', user = '<Database Username>', password = '<Database Password>')
cur = con.cursor()
cur.execute("select dspace_object_id from metadatavalue where text_value ILIKE '%{}%'".format(input_keyword))
#cur.execute("select text_value from metadatavalue where text_value ILIKE '%{}%'".format(input_keyword))
rows = cur.fetchall()
if(rows):
rows = unique(rows)
#print(rows)
Title = []
Author = []
Journal = []
Url =[]
for i in range (len(rows)):
obj = formt(rows[i])
cur.execute("select text_value from metadatavalue where metadata_field_id = 31 and dspace_object_id = {}".format(obj))
ss = formt2(cur.fetchall())
if(ss):
Url.append(ss)
else:
continue
cur.execute("select text_value from metadatavalue where metadata_field_id = 70 and dspace_object_id = {}".format(obj))
Title.append(formt1(cur.fetchall()))
cur.execute("select text_value from metadatavalue where metadata_field_id = 9 and dspace_object_id = {}".format(obj))
Author.append(formt2(cur.fetchall()))
cur.execute("select text_value from metadatavalue where metadata_field_id = 24 and dspace_object_id = {}".format(obj))
Journal.append(formt1(cur.fetchall()))
cur.close()
con.close()
return make_response(render_template("result.html",title = Title, author = Author, journal = Journal, url = Url))
return make_response("Unexpected Error")
api.add_resource(Display, '/search/v1/<path:string1>')
if __name__ == '__main__':
app.run()