Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
assignment statistics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Bohn
assignment statistics
Commits
5e259b1d
Commit
5e259b1d
authored
3 years ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Can retrieve students' majors from UNL directory
parent
9265afdf
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
common_functions.py
+19
-1
19 additions, 1 deletion
common_functions.py
majors.py
+39
-7
39 additions, 7 deletions
majors.py
with
58 additions
and
8 deletions
common_functions.py
+
19
−
1
View file @
5e259b1d
import
datetime
import
json
import
re
from
typing
import
List
,
Optional
,
TypeVar
import
ssl
from
typing
import
Dict
,
List
,
Any
,
Optional
,
TypeVar
from
urllib
import
request
from
urllib.error
import
HTTPError
ChoiceType
=
TypeVar
(
"
ChoiceType
"
)
...
...
@@ -51,3 +55,17 @@ def semester_stamp() -> str:
else
:
month
=
8
return
f
'
{
year
}
-0
{
month
}
'
def
finger
(
login
:
str
,
directory
:
str
=
'
https://directory.unl.edu/people/
'
)
->
Dict
[
str
,
Any
]:
finger_url
:
str
=
f
'
{
directory
}{
login
}
.json
'
self_signed_ssl_okay
:
ssl
.
SSLContext
=
ssl
.
create_default_context
()
self_signed_ssl_okay
.
check_hostname
=
False
self_signed_ssl_okay
.
verify_mode
=
ssl
.
CERT_NONE
data
:
str
try
:
with
request
.
urlopen
(
finger_url
,
context
=
self_signed_ssl_okay
)
as
response
:
data
=
str
(
response
.
read
(),
'
UTF=8
'
)
except
HTTPError
:
data
=
f
'
{{
"
cn
"
:
"
{
login
}
"
,
"
unlSISClassLevel
"
:[
"
Unknown
"
],
"
unlSISMajor
"
:[
"
Unknown
"
]}}
'
return
json
.
loads
(
data
)
This diff is collapsed.
Click to expand it.
majors.py
+
39
−
7
View file @
5e259b1d
from
typing
import
Set
from
typing
import
Dict
,
Set
,
Any
,
Optional
from
common_functions
import
finger
class
Major
:
majors
:
Set
[
"
Major
"
]
=
set
()
def
__init__
(
self
,
name
:
str
,
abbreviations
:
Set
[
str
]):
def
__init__
(
self
,
name
:
str
,
alternate_names
:
Set
[
str
]
=
None
,
abbreviations
:
Optional
[
Set
[
str
]]
=
None
,
is_cse_major
:
bool
=
True
):
self
.
name
:
str
=
name
self
.
abbreviations
:
Set
[
str
]
=
abbreviations
self
.
alternate_names
:
Set
[
str
]
=
alternate_names
if
alternate_names
is
not
None
else
set
()
self
.
abbreviations
:
Set
[
str
]
=
abbreviations
if
abbreviations
is
not
None
else
set
()
self
.
is_cse_major
:
bool
=
is_cse_major
Major
.
majors
.
add
(
self
)
@classmethod
def
get_major
(
cls
,
name
:
str
)
->
"
Major
"
:
candidate
=
[
major
for
major
in
cls
.
majors
if
name
==
major
.
name
or
name
in
major
.
alternate_names
]
if
candidate
:
return
candidate
[
0
]
else
:
return
Major
(
name
,
is_cse_major
=
False
)
@staticmethod
def
get_student_majors
(
login
:
str
)
->
Set
[
"
Major
"
]:
student_data
:
Dict
[
str
,
Any
]
=
finger
(
login
)
if
student_data
[
'
unlSISClassLevel
'
]
==
'
GR
'
:
return
{
Major
.
get_major
(
'
Graduate Student
'
)}
else
:
majors
:
Optional
[
Set
[
str
]]
=
student_data
[
'
unlSISMajor
'
]
return
{
Major
.
get_major
(
major
)
for
major
in
majors
}
if
majors
is
not
None
else
Major
.
get_major
(
'
None
'
)
def
__str__
(
self
)
->
str
:
return
self
.
name
def
__repr__
(
self
)
->
str
:
return
f
'
Name:
"
{
self
.
name
}
"
;
\t
Alternate Names:
{
self
.
alternate_names
if
self
.
alternate_names
else
"
{}
"
}
;
\t
'
\
f
'
CSE Major:
{
self
.
is_cse_major
}
;
\t
Abbreviations:
{
self
.
abbreviations
if
self
.
abbreviations
else
"
{}
"
}
'
Major
(
'
Computer Science
'
,
{
'
COMP-BS
'
,
'
COMP-BA
'
,
'
COMP-MAJ
'
,
'
COMP-BSCS
'
,
# we don't yet have BSCS
Major
(
'
Computer Science
'
,
alternate_names
=
{
'
Computer Science (Raikes)
'
},
abbreviations
=
{
'
COMP-BS
'
,
'
COMP-BA
'
,
'
COMP-MAJ
'
,
'
COMP-BSCS
'
,
# we don't yet have BSCS
'
JECS-BS
'
,
'
JECS-BA
'
,
'
JECS-MAJ
'
,
'
JECS-BSCS
'
})
# but I expect we soon will
Major
(
'
Computer Engineering
'
,
{
'
CENG-BSCP
'
,
'
JECE-BSCP
'
})
Major
(
'
Software Engineering
'
,
{
'
SOFT-BSSE
'
,
'
JESE-BSSE
'
})
Major
(
'
Computer Engineering
'
,
alternate_names
=
{
'
Computer Engineering (Raikes)
'
},
abbreviations
=
{
'
CENG-BSCP
'
,
'
JECE-BSCP
'
})
Major
(
'
Software Engineering
'
,
alternate_names
=
{
'
Software Engineering (Raikes)
'
},
abbreviations
=
{
'
SOFT-BSSE
'
,
'
JESE-BSSE
'
})
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