Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
PeopleFinderAPI
Commits
f1e5f239
Commit
f1e5f239
authored
Sep 22, 2016
by
Nicholas Anderson
Browse files
Added LDAP fallback lookup
parent
1d3db92f
Changes
2
Hide whitespace changes
Inline
Side-by-side
app.py
View file @
f1e5f239
from
flask
import
Flask
,
jsonify
,
render_template
from
peoplefinder
import
call_standard
from
peoplefinder
import
call_standard
,
call_ldap
app
=
Flask
(
__name__
)
...
...
@@ -10,7 +10,15 @@ def base_api():
@
app
.
route
(
'/basic/all/<search>'
,
defaults
=
{
'page'
:
1
})
@
app
.
route
(
'/basic/all/<search>/<page>'
)
def
search_all
(
search
,
page
):
return
jsonify
(
call_standard
(
search
,
page
=
page
))
standardResults
=
call_standard
(
search
,
page
=
page
)
if
len
(
standardResults
[
'results'
])
<
1
:
try
:
res
=
jsonify
(
call_ldap
(
search
))
except
Exception
as
e
:
print
(
e
)
return
res
else
:
return
jsonify
(
standardResults
)
@
app
.
route
(
'/basic/students/<search>'
,
defaults
=
{
'page'
:
1
})
@
app
.
route
(
'/basic/students/<search>/<page>'
)
...
...
@@ -20,7 +28,11 @@ def search_students(search, page):
@
app
.
route
(
'/basic/faculty/<search>'
,
defaults
=
{
'page'
:
1
})
@
app
.
route
(
'/basic/faculty/<search>/<page>'
)
def
search_faculty
(
search
,
page
):
return
jsonify
(
call_standard
(
search
,
group
=
"students"
,
page
=
page
))
return
jsonify
(
call_standard
(
search
,
group
=
"faculty"
,
page
=
page
))
@
app
.
route
(
'/ldap/<search>'
)
def
search_ldap
(
search
):
return
jsonify
(
call_ldap
(
search
))
if
__name__
==
"__main__"
:
import
os
...
...
peoplefinder.py
View file @
f1e5f239
import
re
import
requests
import
simpleldap
from
bs4
import
BeautifulSoup
BASE_URL
=
"http://peoplefinder.gmu.edu/index.php"
...
...
@@ -52,6 +53,23 @@ def call_standard(search, group="all", page=1):
return
{
'results'
:
people
,
'hasNextPage'
:
bool
(
soup
.
find
(
'li'
,
{
'class'
:
'next'
}))
'hasNextPage'
:
bool
(
soup
.
find
(
'li'
,
{
'class'
:
'next'
})),
'method'
:
'peoplefinder'
}
def
call_ldap
(
search
):
conn
=
simpleldap
.
Connection
(
'directory.gmu.edu'
)
res
=
conn
.
get
(
"uid=%s"
%
search
)
return
{
"results"
:
[
{
"name"
:
res
[
'cn'
][
0
],
"mail"
:
res
[
'mail'
][
0
],
"surname"
:
res
[
'sn'
][
0
],
"givenname"
:
res
[
'givenName'
][
0
],
"dn"
:
res
.
dn
}
],
"hasNextPage"
:
False
,
"method"
:
"ldap"
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment