Last active
November 23, 2020 22:28
-
-
Save FiXato/f93104c3334a773a88d101af888e1825 to your computer and use it in GitHub Desktop.
Read Medium.com article through Morse code pulsed via your ScrollLock light, and on Windows via Winsound.beep() too
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyautogui | |
pyautogui.FAILSAFE = False | |
from pyautogui import press, FAILSAFE | |
from morse3 import Morse as m | |
from bs4 import BeautifulSoup | |
import urllib.request | |
from time import sleep | |
URL = "https://medium.com/risan/upgrade-your-ssh-key-to-ed25519-c6e8d60d3c54" | |
req = urllib.request.Request( | |
URL, | |
data=None, | |
headers={ | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36' | |
} | |
) | |
f = urllib.request.urlopen(req) | |
TimeUnit = .1 | |
Duration = { | |
'dot': TimeUnit, | |
'dash': TimeUnit * 3, | |
'intracharacter': TimeUnit, | |
'intercharacter': TimeUnit * 3, | |
'interword': TimeUnit * 7, | |
} | |
def pulse(character): | |
frequency = 1000 | |
press('ScrollLock') | |
if character == '-': | |
duration = Duration['dash'] | |
elif character == '.': | |
duration = Duration['dot'] | |
else: | |
duration = "UNKNOWN CHARACTER" | |
try: | |
import winsound | |
winsound.Beep(frequency, int(duration * 1000)) | |
except Exception as inst: | |
print(type(inst)) # the exception instance | |
print(inst.args) # arguments stored in .args | |
print(inst) # __str__ allows args to be printed directly, but may be overridden in exception subclasses | |
sleep(duration) | |
press('ScrollLock') | |
allowed_letters = m('').codes.keys() | |
soup = BeautifulSoup(f, features="html.parser", from_encoding='utf-8') | |
content = soup.find('article').find('div').find('section').get_text('\n', strip=True).lower() | |
for sentence in content.splitlines(): | |
if not sentence: | |
continue | |
try: | |
stripped_content = ''.join([character.lower() for character in sentence if character.lower() in allowed_letters or character.isspace()]) | |
except Exception as inst: | |
print(type(inst)) # the exception instance | |
print(inst.args) # arguments stored in .args | |
print(inst) # __str__ allows args to be printed directly, but may be overridden in exception subclasses | |
continue | |
morse_sentence = m(stripped_content).stringToMorse() | |
print(stripped_content) | |
print(morse_sentence) | |
for word in morse_sentence.split(): | |
print(' ' + word) | |
for character in word: | |
print(' ' + character) | |
pulse(character) | |
sleep(Duration['intercharacter']) | |
sleep(Duration['interword'] - Duration['intercharacter']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment