Created
May 14, 2015 20:32
-
-
Save glortho/54ac535edbe82e3b76af to your computer and use it in GitHub Desktop.
Filter your simplified tweets by the language they're written in. Choose your language from the dropdown box below.
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
#!/bin/sh | |
"exec" "twxec" "-e" "filter_by_language" "$0" "$@" | |
{{docstring "Filter your simplified tweets by the language they're written in. Choose your language from the dropdown box below."}} | |
language = {{string Language ["English", "French", "Arabic", "Japanese", "Spanish", "German", "Italian", "Indonesian", "Portuguese", "Korean", "Turkish", "Russian"]}} | |
language_map = { | |
"English": "en", | |
"French": "fr", | |
"Arabic": "ar", | |
"Japanese": "ja", | |
"Spanish": "es", | |
"German": "de", | |
"Italian": "it", | |
"Indonesian": "id", | |
"Portuguese": "pt", | |
"Korean": "ko", | |
"Turkish": "tr", | |
"Russian": "ru", | |
"Dutch": "nl", | |
"Filipino": "fil", | |
"Malay": "msa", | |
"Traditional Chinese": "zh-tw", | |
"Simplified Chinese": "zh-con", | |
"Hindi": "hi", | |
"Norwegian": "no", | |
"Swedish": "sv", | |
"Finnish": "fi", | |
"Danish": "da", | |
"Polish": "pl", | |
"Hungarian": "hu", | |
"Farsi": "fa":, | |
"Hebrew": "he", | |
"Urdu": "ur", | |
"Thai": "th", | |
"English UK": "en-gb" | |
} | |
def filter_by_language(msg): | |
if "lang" in msg: | |
if language in language_map.keys() and msg["lang"] == language_map[language]: | |
return msg | |
else: | |
return None | |
elif "twitter_lang" in msg: | |
if language in language_map.keys() and msg["lang"] == language_map[language]: | |
return msg | |
else: | |
return None | |
else: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment