Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AUTO-soa-lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eckl, Máté
AUTO-soa-lab
Commits
8c6af0e9
Commit
8c6af0e9
authored
Mar 31, 2017
by
dnsadmin
Browse files
Options
Downloads
Patches
Plain Diff
4. Feladat
parent
1358b30c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
service.py
+62
-10
62 additions, 10 deletions
service.py
with
62 additions
and
10 deletions
service.py
+
62
−
10
View file @
8c6af0e9
...
@@ -157,44 +157,97 @@ def vehicles():
...
@@ -157,44 +157,97 @@ def vehicles():
conn
.
close
()
conn
.
close
()
def
__get_nevnap
(
date
):
def
__get_nevnap
(
date
):
try
:
resp
=
requests
.
get
(
"
https://db.bme.hu/~marton/shared/bin/nameday/nameday.cgi?month=%d&day=%d&format=json
"
%
(
date
.
month
,
date
.
day
)).
text
resp
=
requests
.
get
(
"
https://db.bme.hu/~marton/shared/bin/nameday/nameday.cgi?month=%d&day=%d&format=json
"
%
(
date
.
month
,
date
.
day
)).
text
except
:
return
None
logging
.
debug
(
resp
)
logging
.
debug
(
resp
)
resp
=
json
.
loads
(
resp
)
resp
=
json
.
loads
(
resp
)
return
resp
[
"
names
"
]
return
resp
[
"
names
"
]
@app.route
(
'
/jarmuvek/<jarmu_kulcs>.json
'
)
def
__get_vehicle
(
jarmu_kulcs
):
def
show_vehicle
(
jarmu_kulcs
):
conn
=
get_db
()
conn
=
get_db
()
try
:
try
:
try
:
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
try
:
logging
.
debug
(
"
Getting data for vehicle with id %d
"
%
jarmu_kulcs
)
cur
.
execute
(
'
select telephely, berelheto, rendszam, alvazszam, uzembehelyezes, muszaki_ervenyesseg, marka, tipus, szin, teljesitmeny, ulesek, legkondicionalo from jarmu where jarmu_kulcs= :jk
'
,
jk
=
jarmu_kulcs
)
cur
.
execute
(
'
select telephely, berelheto, rendszam, alvazszam, uzembehelyezes, muszaki_ervenyesseg, marka, tipus, szin, teljesitmeny, ulesek, legkondicionalo from jarmu where jarmu_kulcs= :jk
'
,
jk
=
jarmu_kulcs
)
res
=
cur
.
fetchone
()
res
=
cur
.
fetchone
()
if
(
res
==
None
):
if
(
res
==
None
):
abort
(
404
)
return
None
# else
# else
telephely
,
berelheto
,
rendszam
,
alvazszam
,
uzembehelyezes
,
muszaki_ervenyesseg
,
marka
,
tipus
,
szin
,
teljesitmeny
,
ulesek
,
legkondicionalo
=
res
telephely
,
berelheto
,
rendszam
,
alvazszam
,
uzembehelyezes
,
muszaki_ervenyesseg
,
marka
,
tipus
,
szin
,
teljesitmeny
,
ulesek
,
legkondicionalo
=
res
nevnap
=
__get_nevnap
(
uzembehelyezes
)
if
(
uzembehelyezes
!=
None
):
uzembehelyezes
=
uzembehelyezes
.
isoformat
()
if
(
muszaki_ervenyesseg
!=
None
):
muszaki_ervenyesseg
=
muszaki_ervenyesseg
.
isoformat
()
result
=
{
result
=
{
"
telephely
"
:
telephely
,
"
telephely
"
:
telephely
,
"
berelheto
"
:
bool
(
berelheto
),
"
berelheto
"
:
bool
(
berelheto
),
"
rendszam
"
:
rendszam
,
"
rendszam
"
:
rendszam
,
"
alvazszam
"
:
alvazszam
,
"
alvazszam
"
:
alvazszam
,
"
uzembehelyezes
"
:
uzembehelyezes
.
isoformat
()
,
"
uzembehelyezes
"
:
uzembehelyezes
,
"
muszaki_ervenyesseg
"
:
muszaki_ervenyesseg
.
isoformat
()
,
"
muszaki_ervenyesseg
"
:
muszaki_ervenyesseg
,
"
marka
"
:
marka
,
"
marka
"
:
marka
,
"
tipus
"
:
tipus
,
"
tipus
"
:
tipus
,
"
szin
"
:
szin
,
"
szin
"
:
szin
,
"
teljesitmeny
"
:
teljesitmeny
,
"
teljesitmeny
"
:
teljesitmeny
,
"
ulesek
"
:
ulesek
,
"
ulesek
"
:
ulesek
,
"
legkondicionalo
"
:
bool
(
legkondicionalo
),
"
legkondicionalo
"
:
bool
(
legkondicionalo
),
"
neve_napja
"
:
__get_nevnap
(
uzembehelyezes
)
"
neve_napja
"
:
nevnap
}
}
return
jsonify
(
result
)
return
result
finally
:
finally
:
cur
.
close
()
cur
.
close
()
finally
:
finally
:
conn
.
close
()
conn
.
close
()
@app.route
(
'
/jarmuvek/<jarmu_kulcs>.json
'
)
def
show_vehicle
(
jarmu_kulcs
):
resp
=
__get_vehicle
(
jarmu_kulcs
)
if
(
resp
==
None
):
abort
(
404
)
return
jsonify
(
resp
)
def
__search
(
by
,
attr
):
conn
=
get_db
()
try
:
cur
=
conn
.
cursor
()
try
:
cur
.
execute
(
"
select jarmu_kulcs from jarmu where %s like :attribute
"
%
by
,
attribute
=
(
"
%%
"
+
attr
+
"
%%
"
))
# TODO: escape %
ids
=
[]
for
id
in
cur
:
ids
.
append
(
id
[
0
])
logging
.
debug
(
"
Searched by %s. The selected vehicles are: %s
"
%
(
by
,
str
(
ids
)))
return
ids
finally
:
cur
.
close
()
finally
:
conn
.
close
()
@app.route
(
'
/jarmuvek/telephely-szerint/<telephely>.json
'
)
def
search_by_depot
(
telephely
):
resp
=
__search
(
"
telephely
"
,
telephely
)
if
(
resp
==
None
):
abort
(
404
)
# else:
vehicles
=
[]
for
id
in
resp
:
vehicles
.
append
(
__get_vehicle
(
id
))
return
jsonify
(
jarmuvek
=
vehicles
)
@app.route
(
'
/jarmuvek/marka-szerint/<marka>.json
'
)
def
search_by_brand
(
marka
):
resp
=
__search
(
"
marka
"
,
marka
)
if
(
resp
==
None
):
abort
(
404
)
# else
vehicles
=
[]
for
id
in
resp
:
vehicles
.
append
(
__get_vehicle
(
id
))
return
jsonify
(
jarmuvek
=
vehicles
)
def
get_db
():
def
get_db
():
"""
Connects to the RDBMS and returns a connection object
"""
"""
Connects to the RDBMS and returns a connection object
"""
# when used with a `file` object, `with` ensures it gets closed
# when used with a `file` object, `with` ensures it gets closed
...
@@ -202,7 +255,6 @@ def get_db():
...
@@ -202,7 +255,6 @@ def get_db():
config
=
json
.
load
(
config_file
)
config
=
json
.
load
(
config_file
)
return
cx_Oracle
.
connect
(
config
[
'
user
'
],
config
[
'
pass
'
],
config
[
'
host
'
])
return
cx_Oracle
.
connect
(
config
[
'
user
'
],
config
[
'
pass
'
],
config
[
'
host
'
])
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
# pylint: disable=wrong-import-position,wrong-import-order
# pylint: disable=wrong-import-position,wrong-import-order
import
os
import
os
...
...
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