Skip to content

Commit

Permalink
Updates to docs, convert formatter to a Class
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneSutro committed Feb 9, 2021
1 parent c49f672 commit 31ea885
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 19 deletions.
49 changes: 39 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ vboard.post('Triage Status\n\n{63}High -3{0}{0}items\n {65}Med -18 items\n{66}Lo

### Raw

The `.raw()` method allows you to specify exactly where each tile should be on the board. `.raw()` takes an argument of a list of lists (a 6 x 22 array) where each character has been converted into its corresponding character code.

```python
import vestaboard

Expand All @@ -127,27 +129,54 @@ vboard = vestaboard.Board(installable)

vboard.raw(characters)
```
![Board with raw input example](../media/rawexample.png?raw=true)

To assist with character conversion, use the `Formatter` class.
The `Formatter` has two public helper options:

## Upcoming Support
- Formatting
- Want to right justify, left justify, or center? Coming soon!
- `.convert()`
- `.convertLine()`

- Color codes
- Add in color chips alongside letters, numbers, and symbols to create unique combinations
#### Convert
If converting a string, use the `.convert()` method. By default, `.convert()` will split by letter and return an array of character codes corresponding to the string you passed in:

- Raw Mode
- Vestaboard supports a "list of lists" to send a message. This will allow you to precisely place characters exactly where you want them. Upcoming support to pass in a 6 x 22 array to place characters, complete with conversion from letters, numbers, and symbols into the corresponding character.
```python
from vestaboard.formatter import Formatter

- Templates
- Choose from a list of templates to send to your board, including calendars, Q&A, trivia, and more
Formatter.convert('Oh hi!')
# Returns [15, 8, 0, 8, 9, 37]
```

To split by word, pass in the argument `byWord=True` along with your input string:

```python
from vestaboard.formatter import Formatter

Formatter.convert('Oh hi!', byWord=True)
# Returns [[15, 8], [8, 9, 37]]
```

#### Convert Line
If you'd like to convert an entire line at once, use the `.convertLine()` method. `.convertLine()` centers text by default. To left justify or right justify, pass `left=True` or `right=True`.

```python
from vestaboard.formatter import Formatter

Formatter.convertLine('Happy Birthday!')
# Returns [0, 0, 0, 8, 1, 16, 16, 25, 0, 2, 9, 18, 20, 8, 4, 1, 25, 37, 0, 0, 0, 0]
```

## Upcoming Support
- Formatting
- Want to right justify, left justify, or center the entire content? Coming soon!

- Templates
- Choose from a list of templates to send to your board, including calendars, Q&A, trivia, and more

***
## Repository Info
### Needs
- Additional formatting for 6 x 22 list of lists for sending custom messages
- Conversion from string to list of lists for `.raw()` method
- Unit and other tests inside the `/test` folder
- Suggestions or ideas for improvement are always welcome!

Expand Down
41 changes: 39 additions & 2 deletions tests/test_formatting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
import vestaboard.formatter as formatter
from vestaboard.formatter import Formatter

validCharacters = [
[63, 64, 65, 66, 67, 68, 69, 63, 64, 65, 66, 67, 68, 69, 63, 64, 65, 66, 67, 68, 69, 63],
[64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64],
[65, 0, 0, 0, 8, 1, 16, 16, 25, 0, 2, 9, 18, 20, 8, 4, 1, 25, 0, 0, 0, 65],
[66, 0, 0, 0, 0, 0, 0, 0, 13, 9, 14, 1, 20, 15, 37, 0, 0, 0, 0, 0, 0, 66],
[67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67],
[68, 69, 63, 64, 65, 66, 67, 68, 69, 63, 64, 65, 66, 67, 68, 69, 63, 64, 65, 66, 67, 68]
]

validCharactersResult= {
'characters': validCharacters
}

def test_standard_formatting():
assert formatter.standard('Love is all you need') == {'text': 'Love is all you need'}, 'Should return a dict with a "text" key and the passed in value.'
assert Formatter._standard('Love is all you need') == {'text': 'Love is all you need'}, 'Should return a dict with a "text" key and the passed in value.'

def test_raw_formatting():
assert Formatter._raw(validCharacters) == validCharactersResult, 'Should return a dict with a "characters" key and the passed in list of lists as the value.'

def test_character_conversion_by_letter():
assert Formatter.convert('test') == [20, 5, 19, 20], 'Should convert by letter into a list.'

def test_character_ignores_case():
Formatter.convert('tHiS Is A sCHEdulEd TESt')

def test_character_conversion_by_word():
assert Formatter.convert('test message', byWord=True) == [[20, 5, 19, 20], [13, 5, 19, 19, 1, 7, 5]], 'Should return a list with nested lists - each nested list should contain the character codes.'

def test_convert_line_with_centering():
assert len(Formatter.convertLine('test message')) == 22, 'Should return a list with 22 elements'
assert Formatter.convertLine('test message') == [0, 0, 0, 0, 0, 20, 5, 19, 20, 0, 13, 5, 19, 19, 1, 7, 5, 0, 0, 0, 0, 0], 'Should add padding to reach 22 characters'

def test_convert_line_left_justified():
assert len(Formatter.convertLine('Oh hi!', left=True)) == 22, 'Should return a list with 22 elements'
assert Formatter.convertLine('Oh hi!', left=True) == [15, 8, 0, 8, 9, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'Should left justify up to 22 characters'

def test_convert_line_right_justified():
assert len(Formatter.convertLine('Oh hi!', right=True)) == 22, 'Should return a list with 22 elements'
assert Formatter.convertLine('Oh hi!', right=True) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 8, 0, 8, 9, 37], 'Should left justify up to 22 characters'
6 changes: 3 additions & 3 deletions vestaboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Installable - Class
"""
import requests
import vestaboard.formatter as formatter
from vestaboard.formatter import Formatter
import vestaboard.vbUrls as vbUrls

class Board:
Expand Down Expand Up @@ -47,7 +47,7 @@ def post(self, text):
"X-Vestaboard-Api-Key" : self.apiKey,
"X-Vestaboard-Api-Secret" : self.apiSecret
}
finalText = formatter.standard(text)
finalText = Formatter._standard(text)
r = requests.post(vbUrls.post.format(self.subscriptionId), headers=headers, json=finalText)
print(r.status_code)
print(r.text)
Expand All @@ -67,7 +67,7 @@ def raw(self, charList):
"X-Vestaboard-Api-Key" : self.apiKey,
"X-Vestaboard-Api-Secret" : self.apiSecret
}
finalText = formatter.raw(charList)
finalText = Formatter._raw(charList)
r = requests.post(vbUrls.post.format(self.subscriptionId), headers=headers, json=finalText)
print(r.status_code)
print(r.text)
Expand Down
43 changes: 39 additions & 4 deletions vestaboard/formatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
def standard(text):
return {'text': text}
from vestaboard.characters import characters

def raw(charList):
return {'characters': charList}
class Formatter:
def _standard(text):
return {'text': text}

def _raw(charList):
return {'characters': charList}

def convert(inputString, byLetter=True, byWord=False):
inputString = inputString.lower()
converted = []
if byWord:
wordList = inputString.split(' ')
for word in wordList:
convertedWord = []
for letter in word:
convertedWord.append(characters[letter])
converted.append(convertedWord)
elif byLetter:
for letter in inputString:
converted.append(characters[letter])

return converted

def convertLine(inputString, center=True, left=False, right=False):
inputString = inputString.lower()
converted = []
if len(inputString) > 22:
return Exception('Convert line method takes in a string less than or equal to 22 characters.')
if left:
inputString = inputString.ljust(22)
elif right:
inputString = inputString.rjust(22)
elif center:
inputString = inputString.center(22)
for letter in inputString:
converted.append(characters[letter])

return converted

0 comments on commit 31ea885

Please sign in to comment.