-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ?censor and ?safe params #270
base: main
Are you sure you want to change the base?
Conversation
i wanna be in the messages! :D
i don't have poor eyesight but staring at the page for long enough i noticed that the link was really hard to see
enabling everyone to shit up their workplaces :D
7ba5ccc
to
61f715b
Compare
Really like the direction this is going on. I have some small changes and feedback that I'll get to next week. |
I'm still curious about the feedback on this one. I'm not a python developer by day so it would be appreciated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts, all take-it-or-leave-it stuff of course. Some bikeshedding, but not too much (I hope).
GRAWLIX = "!@#$%&*" | ||
|
||
def _censor_swearing(txt, censor=False): | ||
grawlix_chars = censor if type(censor) == str else GRAWLIX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grawlix_chars = censor if type(censor) == str else GRAWLIX | |
grawlix_chars = censor if isinstance(censor, str) else GRAWLIX |
safe_f = open("commit_messages/safe.txt", "w") | ||
unsafe_f = open("commit_messages/unsafe.txt", "w") | ||
|
||
with open("./commit_messages.txt") as original_f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, for the future, this can be done in one statement as:
with (
open("commit_messages/safe.txt", "w") as safe_f,
open("commit_messages/unsafe.txt", "w") as unsafe_f,
open("./commit_messages.txt") as original_f,
):
...And then you don't need any explicit .close()
es.
(Python 3.10+ is required to surround the open()
s with ()
s, otherwise they all need to be on one line.)
<p class="permalink"> | ||
<p class="link-wrapper"> | ||
[<a href="/{{ message_hash }}">permalink</a>] | ||
</p> | ||
<p class="link-wrapper"> | ||
[<a href="/">unsafe</a>] | ||
</p> | ||
<p class="link-wrapper"> | ||
[<a href="/?safe">safe only</a>] | ||
</p> | ||
<p class="link-wrapper"> | ||
[<a href="/?censor">censored</a>] | ||
</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having all these links just... kind of "dumped" here might be confusing, especially since the permalink and the others are completely different animals. (The other three links are completely unconnected to the current commit reason being shown.) Having them all together feels sort of like it's implying that the link goes to a "safe only or "censored" version of the current message. At least, it could be misinterpreted that way.
I wonder if it would look cleaner (and be clearer to users) to separate the site-links out a bit from the current output, and maybe add some sort of heading? e.g:
<h3>Get another</h3>
<ul class="link-list">
<li class="link-wrapper"><a href="/">unsafe</a></li>
<li class="link-wrapper"><a href="/?safe">safe only</a></li>
<li class="link-wrapper"><a href="/?censor">censored</a></li>
</ul>
(The UL can always be styled to remove the bullets:)
.link-list { list-style: none; }
@@ -82,6 +82,7 @@ Name: github:KneeNinetySeven | |||
Name: Rafael Reis (github:reisraff) | |||
Name: github:ShanTulshi | |||
Name: Jonatha Daguerre (github:jonathadv) | |||
Name: Odin Heggvold Bekkelund (github: odinhb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name: Odin Heggvold Bekkelund (github: odinhb) | |
Name: Odin Heggvold Bekkelund (github:odinhb) |
😉
with open(humans_file, 'r', encoding='utf-8') as f: | ||
for line in f: | ||
if "Name:" in line: | ||
data = line[6:].rstrip() | ||
if data.find("github:") == 0: | ||
names.append(data[7:]) | ||
else: | ||
names.append(data.split(" ")[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with open(humans_file, 'r', encoding='utf-8') as f: | |
for line in f: | |
if "Name:" in line: | |
data = line[6:].rstrip() | |
if data.find("github:") == 0: | |
names.append(data[7:]) | |
else: | |
names.append(data.split(" ")[0]) | |
def _extract_name(name): | |
if name.startswith("github:"): | |
return name.removeprefix("github:") | |
return name.split(" ")[0] | |
with open(humans_file, 'r', encoding='utf-8') as f: | |
names = [ | |
_extract_name(line.rstrip().removeprefix("Name: ")) | |
for line in f | |
if line.startswith("Name: ") | |
] |
List comprehensions are much faster than looping .append()
s, as they avoid repeated list reallocations. And then you don't need to create the empty list variable in advance.
(Though IMHO the code to extract the names should be in a function that returns the list, and names
should be defined in one go with names = _read_name_list(humans_file)
.)
str.removeprefix
is Python 3.9+, if that's too high a minimum version the string-index math is still an option.
with open(safe_templates_file, 'r', encoding='utf-8') as f: | ||
for line in f: | ||
_hash_and_store(line, safe_templates) | ||
with open(unsafe_templates_file, 'r', encoding='utf-8') as f: | ||
for line in f: | ||
_hash_and_store(line, unsafe_templates) | ||
with open(censorable_templates_file, 'r', encoding='utf-8') as f: | ||
for line in f: | ||
_hash_and_store(line, censorable_templates) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto:
with open(safe_templates_file, 'r', encoding='utf-8') as f: | |
for line in f: | |
_hash_and_store(line, safe_templates) | |
with open(unsafe_templates_file, 'r', encoding='utf-8') as f: | |
for line in f: | |
_hash_and_store(line, unsafe_templates) | |
with open(censorable_templates_file, 'r', encoding='utf-8') as f: | |
for line in f: | |
_hash_and_store(line, censorable_templates) | |
with open(safe_templates_file, 'r', encoding='utf-8') as f: | |
safe_templates = { | |
_hash_template(line): line | |
for line in f | |
} | |
with open(unsafe_templates_file, 'r', encoding='utf-8') as f: | |
unsafe_templates = { | |
_hash_template(line): line | |
for line in f | |
} | |
with open(censorable_templates_file, 'r', encoding='utf-8') as f: | |
censorable_templates = { | |
_hash_template(line): line | |
for line in f | |
} |
...And you can get rid of _hash_and_store()
completely.
list(censorable_templates.keys())) | ||
if len(all_template_digests) != len(set(all_template_digests)): | ||
raise Exception("uniqueness problem with source data") | ||
check_for_collisions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line before this call, please. (black
and safepep8
will actually tell you they want two blank lines on either side of it. But at least one.)
def _fill_template(txt, censor=False): | ||
txt = txt.replace('XNAMEX', random.choice(names)) | ||
txt = txt.replace('XUPPERNAMEX', random.choice(names).upper()) | ||
txt = txt.replace('XLOWERNAMEX', random.choice(names).lower()) | ||
if censor: | ||
txt = _censor_swearing(txt, censor=censor) | ||
|
||
nums = num_re.findall(txt) | ||
|
||
while nums: | ||
start = 1 | ||
end = 999 | ||
value = nums.pop(0) or str(end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A documentation comment would be helpful here, because I have no idea what this function is doing.
@@ -387,7 +360,6 @@ Updated framework to the lattest version | |||
Use a real JS construct, WTF knows why this works in chromium. | |||
Useful text | |||
Version control is awful | |||
WHO THE FUCK CAME UP WITH MAKE? | |||
WIP, always | |||
WIPTF | |||
WTF is this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some argument to be made that all of the *TF
messages also belong in the unsafe file. They're not really usefully censorable, but they're not really censored per se, either.
Closes #264