Skip to content

Commit

Permalink
Added some non-english characters
Browse files Browse the repository at this point in the history
  • Loading branch information
partofthething committed Dec 30, 2017
1 parent 7ed6915 commit 5c09e4b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
1 change: 1 addition & 0 deletions morsecodelib/__init__.py
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
17 changes: 14 additions & 3 deletions morsecodelib/alphabet.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""
Lookup table for all of Morse code.
Lookup table for all of Morse code.
"""

letters_to_code = {'A': '.-',
Expand Down Expand Up @@ -50,10 +51,20 @@
'(': '-.--.-',
')': '-.--.-',
'_': '..--.-',
'!': '-.-.--'
'!': '-.-.--',
'À': '.--.-',
'Å': '.--.-',
'Ä': '.-.-,',
'Æ': '.-.-',
'É': '..-..',
'È': '.-..-',
'Ö': '---.',
'Ø': '---.',
'Þ':'.--..',
'Ü': '..--',
}

# build reverse lookup too
code_to_letters = {}
for letter, code in letters_to_code.items():
code_to_letters[code] = letter
code_to_letters[code] = letter
10 changes: 6 additions & 4 deletions morsecodelib/sound.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
Make sounds or light pulses from Morse code data
"""
Expand All @@ -10,16 +11,17 @@
import pygame
except ImportError:
pygame = None
from six.moves import xrange

from morsecodelib import config
from morsecodelib import text


class MorsePlayer(object):
"""
Takes text and renders it as something
Use subclasses to choose sound vs. laser vs. whatever.
Take text and render it as something.
Use subclasses to choose sound vs. laser vs. whatever.
"""

def text_to_sound(self, message_text):
Expand Down Expand Up @@ -66,7 +68,7 @@ def stop(self):

class MorseSoundPlayer(MorsePlayer):
"""
Makes audible tones with speaker.
Makes audible tones with speaker.
"""
def __init__(self):
"""
Expand Down
7 changes: 4 additions & 3 deletions morsecodelib/tests/test_text.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
'''
Unit tests
Unit tests
'''
import unittest

Expand All @@ -13,7 +14,7 @@ class TestText(unittest.TestCase):
def setUp(self):
self.message_text = 'testing text to code converSION!'
self.message_code = ('- . ... - .. -. --. - . -..- - - --- '
'-.-. --- -.. . -.-. ... .. --- -. -.-.--')
'-.-. --- -.. . -.-. --- -. ...- . .-. ... .. --- -. -.-.--')

def test_text_to_code(self):
result = text.text_to_code(self.message_text)
Expand All @@ -34,5 +35,5 @@ def test_sanity(self):
self.assertEqual(code1, code2)

if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
# import sys;sys.argv = ['', 'Test.testName']
unittest.main()
21 changes: 12 additions & 9 deletions morsecodelib/text.py
@@ -1,18 +1,20 @@
# -*- coding: utf-8 -*-
"""
Convert Morse code <--> text
"""

import alphabet
from morsecodelib import alphabet


def text_to_code(text):
"""
Convert text to Morse code symbols
Parameters
----------
text : str
text to convert to Morse code.
text to convert to Morse code.
Examples
--------
>>> text_to_code('hi')
Expand All @@ -26,17 +28,18 @@ def text_to_code(text):
code.append(' '.join(morse_word))
return ' '.join(code)


def code_to_text(code):
"""
Convert Morse code to text.
Convert Morse code to text.
Double spaces are considered gaps between words
Parameters
----------
code : str
Morse code string to convert to text
Morse code string to convert to text
Examples
--------
>>> text_to_code('.... ..')
Expand Down

0 comments on commit 5c09e4b

Please sign in to comment.