Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mycampusscript
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
agse
Mycampusscript
Commits
e9c83396
Commit
e9c83396
authored
5 months ago
by
prechelt
Browse files
Options
Downloads
Patches
Plain Diff
mycampusscript.py after session 1 with Linus
parent
54718d63
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
mycampusscript.py
+78
-0
78 additions, 0 deletions
mycampusscript.py
with
78 additions
and
0 deletions
mycampusscript.py
0 → 100644
+
78
−
0
View file @
e9c83396
import
re
import
sys
import
typing
as
tg
import
bs4
import
yaml
import
requests
import
base
as
b
usage
=
"""
mycampusscript create_multigroup_assgmt config.yaml
Creates an Sakai
'
assignment
'
entry in a site with separate deadlines per section
"""
site_url_help
=
"""
site_url: URL of the MyCampus site
'
s homepage
"""
cookies_help
=
"""
cookies: a dictionary of cookie names to cookie values
You need to obtain the following cookies: SAKAI2SESSIONID. How to do that:
Log into MyCampus,
visit the site where you want to create the multigroup assignment,
open the developer tools in your browser (in Firefox: F12),
open the
'
network
'
tab in the developer tools,
visit the assignment creation form (
'
Assignments
'
->
'
Add
'
),
select the first requests in the network tab
'
s request list,
in the panel on the right, select
'
Headers
'
->
'
Request Headers
'
, turn on
'
raw
'
view,
copy the entire line that starts with
"
Cookie:
"
and paste into your config as the value
for the
'
cookies
'
config parameter; you must enclose it in double quotes.
"""
ASSIGNMENTS_CREATION_FORM_PATH
=
'
tool/1f8f054a-4e58-4965-8d32-141b236e0023?panel=Main
'
StrAnyDict
=
dict
[
str
,
tg
.
Any
]
def
main
(
scriptname
:
str
,
cmdname
:
str
,
configfile
:
str
):
with
open
(
configfile
,
'
rt
'
)
as
f
:
config
=
yaml
.
load
(
f
,
Loader
=
yaml
.
Loader
)
site_url
:
str
=
find_value_or_help
(
config
,
'
site_url
'
)
parse_cookies
(
config
)
group_ids
:
str
=
find_value_or_help
(
config
,
'
group_ids
'
)
def
find_value_or_help
(
config
:
StrAnyDict
,
key
:
str
)
->
tg
.
Any
:
if
key
in
config
:
return
config
[
key
]
the_help
=
globals
()[
f
"
{
key
}
_help
"
]
if
callable
(
the_help
):
!!!
the_help
=
...
b
.
critical
(
the_help
)
def
parse_cookies
(
config
:
StrAnyDict
):
def
perhaps_complain
(
mm
):
if
not
mm
:
b
.
critical
(
"
config param
'
cookies
'
must have format
'
Cookie:
\"
NAME1=value1; name2=value
\"
"
)
cookiesheader_re
=
r
"
Cookie: (.+)
"
mm
=
re
.
fullmatch
(
cookiesheader_re
,
config
[
'
cookies
'
])
perhaps_complain
(
mm
)
cookiepairs
=
mm
.
group
(
1
).
split
(
"
;
"
)
result
=
dict
()
for
pair
in
cookiepairs
:
mm
=
re
.
fullmatch
(
r
"
(.+?)=(.+)
"
,
pair
)
# split at the first equals sign
perhaps_complain
(
mm
)
result
[
mm
.
group
(
1
)]
=
mm
.
group
(
2
)
print
(
result
)
config
[
'
cookies
'
]
=
result
if
__name__
==
'
__main__
'
:
if
len
(
sys
.
argv
)
!=
2
+
1
or
sys
.
argv
[
1
]
!=
'
create_multigroup_assgmt
'
:
print
(
usage
)
else
:
try
:
main
(
*
sys
.
argv
)
except
b
.
CritialError
:
pass
# just stop
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