Last active
March 1, 2016 03:26
-
-
Save Resisty/271e1ef4d66250fc9c0a to your computer and use it in GitHub Desktop.
Hashtag Enterprise...ish
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
# modularize |
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 logging | |
LOGGER = logging.getLogger('hashtag') | |
class Hashtag(object): | |
''' Make hashtags safely and responsibly. | |
Class methods: | |
__init__ | |
from_str | |
''' | |
def __init__(self, obj): | |
self._hashtag = Hashtag.from_obj(obj) | |
@property | |
def hashtag(self): | |
return self._hashtag | |
@hashtag.setter | |
def hashtag(self, s): | |
self._hashtag = Hashtag.from_obj(s) | |
return self._hashtag | |
@classmethod | |
def from_obj(cls, obj): | |
try: | |
s = str(obj) | |
except UnicodeEncodeError as e: | |
LOGGING.error('Unable to convert unicode character to hashtag.') | |
return '#' + s |
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 argparse as ap | |
import hashtag | |
def main(): | |
parser = ap.ArgumentParser('Turn stuff into hashtags!') | |
parser.add_argument('untagged', | |
nargs='+', | |
type=str, | |
help='Space-delimited words to be turned into hashtags') | |
args = parser.parse_args() | |
print ' '.join([hashtag.Hashtag.from_obj(i) for i in args.untagged]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment