Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions twitterstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
4 changes: 1 addition & 3 deletions wordlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -40,4 +39,3 @@ def wordlist(language="en_US"):
raise MissingTranslationException(
"No translation for %s found" %
language)

9 changes: 9 additions & 0 deletions words/test_RU/wordlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
["Хакерпространство"],
[""],
["открыто"],
["закрыто"],
["Большой!"],
["плохой"],
"{space} {status}. {qualifier}!"
]