diff --git a/twitterstatus.py b/twitterstatus.py index 1d3af83..ef0fbb1 100755 --- a/twitterstatus.py +++ b/twitterstatus.py @@ -28,11 +28,14 @@ ] try: - twitter = Twitter(auth=OAuth( - config.OAUTH_TOKEN, - config.OAUTH_SECRET, - config.CONSUMER_KEY, - config.CONSUMER_SECRET)) + twitter = Twitter( + auth=OAuth( + config.OAUTH_TOKEN, + config.OAUTH_SECRET, + config.CONSUMER_KEY, + config.CONSUMER_SECRET + ) + ) except Exception as e: print('Error in twitter init: ' + e) exit(255) @@ -44,19 +47,32 @@ def write_status(status): def generate_phrase(open_status=True): - phrase = choice(WORDLIST[0]) + " " - phrase += choice(WORDLIST[1]) + " " + """ + Generates a translated phrase to say if the hackspace is open or + closed from a given list of words using random choices if more than + one list item exists. The word order and + """ + try: + """ Get the template and test that the template doesn't contain + unknown variables """ + phrase_template = WORDLIST[6] + phrase = phrase_template.format(space=1, be=1, status=1, qualifier=1) + except IndexError: + phrase_template = "{space} {be} {status}. {qualifier}!" + except KeyError: + print("[WARN]: Loading phrase template failed, using default SVO") + phrase_template = "{space} {be} {status}. {qualifier}!" if open_status: - phrase += choice(WORDLIST[2]) + ". " + status = choice(WORDLIST[2]) + qualifier = choice(WORDLIST[4]) else: - phrase += choice(WORDLIST[3]) + ". " + status = choice(WORDLIST[3]) + qualifier = choice(WORDLIST[5]) - if choice([True, False]): - if open_status: - phrase += choice(WORDLIST[4]).title() + "!" - else: - phrase += choice(WORDLIST[5]).title() + "!" + phrase = phrase_template.format(space=choice(WORDLIST[0]), + be=choice(WORDLIST[1]), status=status, + qualifier=qualifier) return phrase diff --git a/wordlist.py b/wordlist.py index 6f6c605..85072e3 100644 --- a/wordlist.py +++ b/wordlist.py @@ -9,8 +9,6 @@ class MissingTranslationException(Exception): pass -translations = {} - def wordlist(language="en_US"): """ Returns a list of lists containing words to be used in a status update @@ -22,6 +20,7 @@ def wordlist(language="en_US"): * closed * fill words - good * fill words - bad + * (optional) word order of {space}, {be}, {status}, {qualifier} """ if language in translations: return translations[language] @@ -40,4 +39,3 @@ def wordlist(language="en_US"): raise MissingTranslationException( "No translation for %s found" % language) - diff --git a/words/test_RU/wordlist.json b/words/test_RU/wordlist.json new file mode 100644 index 0000000..2c40e10 --- /dev/null +++ b/words/test_RU/wordlist.json @@ -0,0 +1,9 @@ +[ + ["Хакерпространство"], + [""], + ["открыто"], + ["закрыто"], + ["Большой!"], + ["плохой"], + "{space} {status}. {qualifier}!" +]