Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Temperaturverteilung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s39174
Temperaturverteilung
Commits
228e01c1
Commit
228e01c1
authored
3 years ago
by
Clemens Berteld
Browse files
Options
Downloads
Patches
Plain Diff
API works and is finished (?)
parent
a2b89b7a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dataacquisition/api.py
+13
-2
13 additions, 2 deletions
dataacquisition/api.py
with
13 additions
and
2 deletions
dataacquisition/api.py
+
13
−
2
View file @
228e01c1
...
@@ -13,6 +13,7 @@ app.config['TESTING'] = False
...
@@ -13,6 +13,7 @@ app.config['TESTING'] = False
@app.route
(
'
/
'
,
methods
=
[
'
GET
'
])
@app.route
(
'
/
'
,
methods
=
[
'
GET
'
])
def
index
():
def
index
():
columns
=
sql
.
SQL
(
'
*
'
)
wheres
=
sql
.
SQL
(
''
)
wheres
=
sql
.
SQL
(
''
)
values
=
''
# Gets used in cursor.execute()s' second parameter for safety reasons
values
=
''
# Gets used in cursor.execute()s' second parameter for safety reasons
...
@@ -22,6 +23,16 @@ def index():
...
@@ -22,6 +23,16 @@ def index():
for
n
in
[
int
(
station_id
)]:
for
n
in
[
int
(
station_id
)]:
values
=
(
*
values
,
n
)
# adding n to existing tuple
values
=
(
*
values
,
n
)
# adding n to existing tuple
if
'
years
'
in
request
.
args
:
years
=
request
.
args
[
'
years
'
].
split
(
'
,
'
)
years_clean
=
[]
for
year
in
years
:
years_clean
.
append
(
'"'
+
year
+
'"'
)
years_clean
=
str
(
years_clean
).
replace
(
'
[
'
,
''
).
replace
(
'
]
'
,
''
).
replace
(
"'"
,
""
).
replace
(
'
\n
'
,
''
).
replace
(
'
'
,
''
)
columns
=
sql
.
SQL
(
'
id,
'
)
+
sql
.
SQL
(
years_clean
)
# Just for development
# Just for development
# if 'country' in request.args:
# if 'country' in request.args:
# country = request.args['country']
# country = request.args['country']
...
@@ -30,9 +41,9 @@ def index():
...
@@ -30,9 +41,9 @@ def index():
# values = (*values, n) # adding n to existing tuple
# values = (*values, n) # adding n to existing tuple
query
=
sql
.
SQL
(
"
SELECT array_to_json(array_agg(row_to_json(t))) from (
"
query
=
sql
.
SQL
(
"
SELECT array_to_json(array_agg(row_to_json(t))) from (
"
"
SELECT
*
FROM stations WHERE lon IS NOT NULL
"
"
SELECT
{}
FROM stations WHERE lon IS NOT NULL
"
"
{}
"
"
{}
"
"
) t;
"
).
format
(
wheres
)
"
) t;
"
).
format
(
columns
,
wheres
)
with
psycopg2
.
connect
(
database
=
'
temperatures_berteld_morstein
'
,
user
=
'
postgres
'
,
password
=
'
postgres
'
,
host
=
'
localhost
'
,
port
=
5432
)
as
connection
:
with
psycopg2
.
connect
(
database
=
'
temperatures_berteld_morstein
'
,
user
=
'
postgres
'
,
password
=
'
postgres
'
,
host
=
'
localhost
'
,
port
=
5432
)
as
connection
:
with
connection
.
cursor
()
as
cursor
:
with
connection
.
cursor
()
as
cursor
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment