-
Notifications
You must be signed in to change notification settings - Fork 0
/
navody.py
executable file
·86 lines (72 loc) · 3.21 KB
/
navody.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
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
app = Flask(__name__)
from flask import render_template, url_for, redirect
from flask import request
import os
import psycopg2
from contextlib import closing
import stdnum.issn
if 'NAVODY_DEBUG' in os.environ:
app.debug = True
from local_settings import active_config
config = active_config(app)
app.secret_key = config.secret
@app.route('/', methods=['POST', 'GET'])
def index():
return render_template('index.html')
@app.route('/kategorizacia-publikacii')
def kategorizacia():
return render_template('kategorizacia.html')
@app.route('/wos-a-scopus')
def wos_a_scopus():
return render_template('wos-a-scopus.html')
@app.route('/impakt-faktor/')
def impakt_faktor():
if request.remote_user:
return redirect(url_for('impakt_faktor_moje'))
return redirect(url_for('impakt_faktor_fmfi'))
@app.route('/impakt-faktor/vsetky')
def impakt_faktor_vsetky():
def query(cursor):
cursor.execute('SELECT DISTINCT id, COALESCE(source_title, source_abbr) AS source, snip_2012, if_2013, issn FROM impact_factors LEFT JOIN impact_factors_issn ON id = impact_factors_id WHERE (snip_2012 IS NOT NULL OR if_2013 IS NOT NULL) ORDER BY source, id, issn')
return show_impakt_faktor(query, tab='vsetky')
@app.route('/impakt-faktor/fmfi')
def impakt_faktor_fmfi():
def query(cursor):
cursor.execute('SELECT DISTINCT id, COALESCE(source_title, source_abbr) AS source, snip_2012, if_2013, impact_factors_issn.issn FROM impact_factors, impact_factors_issn, issn_login WHERE id = impact_factors_id AND (snip_2012 IS NOT NULL OR if_2013 IS NOT NULL) AND issn_login.issn = impact_factors_issn.issn ORDER BY source, id, issn')
return show_impakt_faktor(query, tab='fmfi')
@app.route('/impakt-faktor/moje')
def impakt_faktor_moje():
user = request.remote_user
def query(cursor):
cursor.execute('SELECT DISTINCT id, COALESCE(source_title, source_abbr) AS source, snip_2012, if_2013, impact_factors_issn.issn FROM impact_factors, impact_factors_issn, issn_login WHERE id = impact_factors_id AND (snip_2012 IS NOT NULL OR if_2013 IS NOT NULL) AND issn_login.issn = impact_factors_issn.issn AND issn_login.login = %s ORDER BY source, id, issn', (user,))
return show_impakt_faktor(query, tab='moje')
def show_impakt_faktor(run_query, **kwargs):
data = []
with closing(psycopg2.connect(config.conn_str)) as conn:
with closing(conn.cursor()) as cursor:
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE, cursor) # unicode support
run_query(cursor)
lastid = None
issns = []
for id, source, snip_2012, if_2013, issn in cursor:
if lastid != id:
data.append((id, source, snip_2012, if_2013, []))
lastid = id
if issn is not None:
data[-1][4].append(stdnum.issn.format(issn))
return render_template('impakt-faktor.html', data=data, **kwargs)
if __name__ == '__main__':
import sys
if len(sys.argv) == 2 and sys.argv[1] == 'cherry':
from cherrypy import wsgiserver
d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
server = wsgiserver.CherryPyWSGIServer(('127.0.0.1', 5000), d)
try:
server.start()
except KeyboardInterrupt:
server.stop()
else:
app.run() # werkzeug