File tree 8 files changed +116
-0
lines changed
8 files changed +116
-0
lines changed Original file line number Diff line number Diff line change
1
+ from configparser import ConfigParser
2
+
3
+
4
+ def dbconfig (filename = 'backend\dbandsupport.ini' , section = 'postgresql' ):
5
+ # create a parser
6
+ parser = ConfigParser ()
7
+ # read config file
8
+ parser .read (filename )
9
+
10
+ # get section, default to postgresql
11
+ db = {}
12
+ if parser .has_section (section ):
13
+ params = parser .items (section )
14
+ for param in params :
15
+ db [param [0 ]] = param [1 ]
16
+ else :
17
+ raise Exception ('Section {0} not found in the {1} file' .format (section , filename ))
18
+
19
+ return db
20
+
21
+ def skconfig (filename = 'backend\dbandsupport.ini' , section = 'flask' ):
22
+ # create a parser
23
+ parser = ConfigParser ()
24
+ # read config file
25
+ parser .read (filename )
26
+
27
+ # get section for flask
28
+ skey = {}
29
+ if parser .has_section (section ):
30
+ params = parser .items (section )
31
+ for param in params :
32
+ skey [param [0 ]] = param [1 ]
33
+ else :
34
+ raise Exception ('Section {0} not found in the {1} file' .format (section , filename ))
35
+
36
+ return skey
Original file line number Diff line number Diff line change
1
+ [postgresql]
2
+ host =localhost
3
+ database =demo
4
+ user =postgres
5
+ password =tbcpdx
6
+
7
+
8
+ [flask]
9
+ secret_key =7Jwp<Y\m,jX@+sG+*
Original file line number Diff line number Diff line change
1
+ import psycopg2
2
+ from backend .config import dbconfig
3
+ import os
4
+
5
+ def onequery ():
6
+ """ Connect to the PostgreSQL database server """
7
+ conn = None
8
+ try :
9
+ # read connection parameters
10
+ params = dbconfig ()
11
+
12
+ # connect to the PostgreSQL server
13
+ conn = psycopg2 .connect (** params )
14
+
15
+ # create a cursor
16
+ cur = conn .cursor ()
17
+
18
+ # execute a statement
19
+ with open (r"backend\sqlfiles\all.sql" , 'r' ) as f :
20
+ cur .execute (f .read ())
21
+ conn .commit ()
22
+
23
+ # return all records
24
+ queryone = cur .fetchall ()
25
+
26
+ # close the PostgreSQL cursor
27
+ cur .close ()
28
+ except (Exception , psycopg2 .DatabaseError ) as error :
29
+ print (error )
30
+ finally :
31
+ if conn is not None :
32
+ # close the cursor with the PostgreSQL
33
+ cur .close ()
34
+ # close the connection with the PostgreSQL
35
+ conn .close ()
36
+ print ("The database is closed." )
37
+ return queryone
38
+
39
+
40
+ # print(onequery())
Original file line number Diff line number Diff line change
1
+ select * from peps
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+
3
+ < html lang ="en ">
4
+ < head >
5
+ < meta charset ="utf-8 ">
6
+
7
+ < title > Demo</ title >
8
+
9
+ </ head >
10
+
11
+
12
+ < body >
13
+ {% block content %}
14
+ {% endblock %}
15
+ </ body >
16
+ </ html >
Original file line number Diff line number Diff line change
1
+ {% extends "base.html" %}
2
+
3
+ {% block content %}
4
+ {% for row in data %}
5
+ < details >
6
+ < summary >
7
+ Name: {{ row[1] }} {{ row[2]}}
8
+ </ summary >
9
+ < br >
10
+ email: {{row[3]}}; employer: {{row[8]}}
11
+ </ details >
12
+ < br >
13
+ {% endfor %}
14
+ {% endblock %}
You can’t perform that action at this time.
0 commit comments