concrete.util.twitter module¶
Convert between JSON and Concrete representations of Tweets
The JSON fields used by the Twitter API are documented at:
-
concrete.util.twitter.
capture_tweet_lid
(tweet)¶ Reads the lang field from a tweet from the twitter API, if it exists, and return corresponding concrete
LanguageIdentification
object.Parameters: tweet (dict) – Object created by deserializing a JSON Tweet string Returns: LanguageIdentification
object, or None if the lang field is not present in the Tweet JSON
-
concrete.util.twitter.
json_tweet_object_to_Communication
(tweet)¶ Convert deserialized JSON Tweet object to
Communication
Parameters: tweet (object) – Object created by deserializing a JSON Tweet string Returns: Communication representing the Tweet, with tweetInfo and text fields set (among others) but with a null (None) sectionList. Return type: Communication
-
concrete.util.twitter.
json_tweet_object_to_TweetInfo
(tweet)¶ Create
TweetInfo
object from deserialized JSON Tweet objectParameters: tweet (dict) – Object created by deserializing a JSON Tweet string Returns: concrete object representing twitter metadata from tweet Return type: TweetInfo
-
concrete.util.twitter.
json_tweet_string_to_Communication
(json_tweet_string, check_empty=False, check_delete=False)¶ Convert JSON Tweet string to Communication
Parameters: - json_tweet_string (str) – JSON Tweet string from Twitter API
- check_empty (bool) – If True, check if json_tweet_string is empty (return None if it is)
- check_delete (bool) – If True, check for presence of delete field in Tweet JSON, and if the ‘delete’ field is present, return None
Returns: Communication representing the Tweet, with tweetInfo and text fields set (among others) but with a null (None) sectionList.
Return type:
-
concrete.util.twitter.
json_tweet_string_to_TweetInfo
(json_tweet_string)¶ Create
TweetInfo
object from JSON Tweet stringParameters: json_tweet_string (str) – JSON Tweet string from Twitter API Returns: concrete twitter metadata object with fields set from json_tweet_string Return type: TweetInfo
-
concrete.util.twitter.
snake_case_to_camelcase
(value)¶ Converts snake case to camel case
Implementation copied from this Stack Overflow post: http://goo.gl/SSgo9k
Parameters: value (str) – snake case (lower case with underscores) value Returns: camel case string corresponding to value (with isolated unscores stripped and sequences of two or more underscores reduced by one underscore) Return type: str
-
concrete.util.twitter.
twitter_lid_to_iso639_3
(twitter_lid)¶ Convert Twitter Language ID string to ISO639-3 code
Parameters: twitter_lid (str) – This can be an iso639-3 code (no-op), iso639-1 2-letter abbr (converted to 3), or combo (split by ‘-’, then first part converted)
Per the Twitter documentation, “The language code may be formatted as ISO 639-1 alpha-2 (en), ISO 639-3 alpha-3 (msa), or ISO 639-1 alpha-2 combined with an ISO 3166-1 alpha-2 localization (zh-tw).”
Returns: the ISO639-3 code corresponding to twitter_lid Return type: str