def to_element(data): """ Covert dict to lxml element. Only standard elements are inserted. If the post does not meet standards, raises ValueError. See http://openmicroblog.com for information about the standard elements.""" try: data = standardize(data) except ValueError: print 'The post data provided does not meet Open Microblog standards. \n\ Please see http://openmicroblog.com for information on required elements.' raise ValueError # Check if the post is a reply. if 'is_reply' in data.keys(): return E.item( # General Info E.guid(data['guid']), E.pubDate(data['pubdate'].strftime(DATE_STR_FORMAT)), E.description(CDATA(data['description'])), E.language(data['language']), # Replying E.in_reply_to_status_id(data['in_reply_to_status_id']), E.in_reply_to_user_id(data['in_reply_to_user_id']), E.in_reply_to_user_link(data['in_reply_to_user_link']) ) # Check if the post is a repost. elif 'is_repost' in data.keys(): return E.item( # General Info E.guid(data['guid']), E.pubDate(data['pubdate'].strftime(DATE_STR_FORMAT)), E.description(CDATA(data['description'])), E.language(data['language']), # Reposting E.reposted_status_id(data['reposted_status_id']), E.reposted_status_pubdate(data['reposted_status_pubdate'].strftime(DATE_STR_FORMAT)), E.reposted_status_user_id(data['reposted_status_user_id']), E.reposted_status_user_link(data['reposted_status_user_link']) ) # Normal post. else: return E.item( # General Info E.guid(data['guid']), E.pubDate(data['pubdate'].strftime(DATE_STR_FORMAT)), E.description(CDATA(data['description'])), E.language(data['language']) )
def to_element(self): """ Covert dict to lxml element. Only standard elements are inserted. If the post does not meet standards, raises AttributeError. See http://openmicroblog.com for information about the standard elements.""" if not self.is_standard(): raise StatusNotStandardError('Status does not meet the Open Microblog Standard') if self.status_type == StatusType.REPLY: return E.item( # General Info E.guid(self.guid), E.pubdate(self.pubdate.strftime(DATE_STR_FORMAT)), E.description(self.description), E.language(self.language), E.reply(self.reply), # Replying E.in_reply_to_status_id(self.in_reply_to_status_id), E.in_reply_to_user_id(self.in_reply_to_user_id), E.in_reply_to_user_link(self.in_reply_to_user_link) ) elif self.status_type == StatusType.REPOST: return E.item( # General Info E.guid(self.guid), E.pubdate(self.pubdate.strftime(DATE_STR_FORMAT)), E.description(self.description), E.language(self.language), E.reply(self.reply), # Reposting E.reposted_status_id(self.reposted_status_id), E.reposted_status_pubdate(self.reposted_status_pubdate.strftime(DATE_STR_FORMAT)), E.reposted_status_user_id(self.reposted_status_user_id), E.reposted_status_user_link(self.reposted_status_user_link) ) else: return E.item( # General Info E.guid(self.guid), E.pubdate(self.pubdate.strftime(DATE_STR_FORMAT)), E.description(self.description), E.language(self.language), E.reply(self.reply) )