Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
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
Martin Mareš
Odevzdávací Systém MO
Commits
96a2229a
Commit
96a2229a
authored
2 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Skript na anonymizaci testovací instance
parent
f946922d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/test-anonymize
+80
-0
80 additions, 0 deletions
bin/test-anonymize
with
80 additions
and
0 deletions
bin/test-anonymize
0 → 100755
+
80
−
0
View file @
96a2229a
#!/usr/bin/env python3
import
argparse
import
random
from
unidecode
import
unidecode
import
mo.db
as
db
import
mo.util
from
mo.util
import
die
parser
=
argparse
.
ArgumentParser
(
description
=
'
Anonymizuje všechny účastníky
'
)
parser
.
add_argument
(
'
--really
'
,
default
=
False
,
action
=
'
store_true
'
,
help
=
'
potvrdí, že to opravdu chceme udělat
'
)
parser
.
add_argument
(
'
--seed
'
,
type
=
str
,
default
=
'
seedme
'
,
help
=
'
random seed
'
)
parser
.
add_argument
(
'
-n
'
,
'
--dry-run
'
,
default
=
False
,
action
=
'
store_true
'
,
help
=
'
vyzkouší sloučení nanečisto (necommitne)
'
)
args
=
parser
.
parse_args
()
mo
.
util
.
init_standalone
()
if
not
args
.
really
:
die
(
"
Nejsem si jistý, jestli to chci udělat. Řekni mi, že opravdu.
"
)
def
load
(
name
):
with
open
(
f
'
etc/names/
{
name
}
'
)
as
f
:
return
[
line
.
strip
()
for
line
in
f
]
first_names
=
[
load
(
'
first-f
'
),
load
(
'
first-m
'
)]
last_names
=
[
load
(
'
last-f
'
),
load
(
'
last-m
'
)]
used_names
=
set
()
rng
=
random
.
Random
(
args
.
seed
)
def
norm
(
name
):
return
unidecode
(
name
).
lower
()
def
gen_name
(
orig_last
):
if
orig_last
.
endswith
(
'
á
'
):
gender
=
0
else
:
gender
=
1
while
True
:
f
=
rng
.
choice
(
first_names
[
gender
])
l
=
rng
.
choice
(
last_names
[
gender
])
ff
,
ll
=
norm
(
f
),
norm
(
l
)
stripped
=
f
'
{
ff
}
{
ll
}
'
if
stripped
not
in
used_names
:
used_names
.
add
(
stripped
)
return
f
,
l
,
ff
,
ll
sess
=
db
.
get_session
()
users
=
sess
.
query
(
db
.
User
).
all
()
cnt_anoned
=
0
cnt_orgs
=
0
cnt_already
=
0
for
u
in
users
:
if
u
.
is_org
or
u
.
is_admin
:
cnt_orgs
+=
1
elif
u
.
email
.
endswith
(
'
@test
'
):
cnt_already
+=
1
else
:
first
,
last
,
first_stripped
,
last_stripped
=
gen_name
(
u
.
last_name
)
email
=
f
'
{
first_stripped
}
.
{
last_stripped
}
@test
'
print
(
f
'
{
u
.
first_name
}
{
u
.
last_name
}
->
{
first
}
{
last
}
<
{
email
}
>
'
)
u
.
first_name
=
first
u
.
last_name
=
last
u
.
email
=
email
cnt_anoned
+=
1
if
not
args
.
dry_run
:
sess
.
commit
()
else
:
sess
.
rollback
()
print
(
f
'
Hotovo:
{
cnt_anoned
}
anonymizováno,
{
cnt_already
}
už bylo, ponecháno
{
cnt_orgs
}
organizátorů
'
)
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