def get_content_item_template(self): config = self.get_unconfigured_config() controller = ActionController(config) sentiment_property = config["content_properties"]["added"][0] encoded_property = controller._search_encode_property(sentiment_property) return ( "" "{{if typeof (" + encoded_property + ") !== 'undefined'}}" " {{if " + encoded_property + ".length > 0 && " + encoded_property + "[0] != '_none' }}" " <li class='action_values tags'>" " <label><img src='" + config["image_small"] + "' style='position:relative;top:5px;left:-2px;width:16px;height:16px;'/> Tags:</label> " " <span style='font-weight:bold;'>" " {{each(index, element) " + encoded_property + "}}" " {{if element != '_none' && index < 5}}" " <a class='action_inline_filter' data-facet_name='" + encoded_property + "' data-facet_value='${element}'>${element}</a>" " {{/if}} " " {{if index == 6}}...{{/if}}" " {{/each}}" " </span>" " </li>" " {{/if}}" "{{/if}}" )
def parse_actions(self): if not self.actions: return '' return_parts = [] for raw_action in self.actions: ac = ActionController(raw_action) filters = ac.get_filters() basic_filters = [f for f in filters if f['type'] in ('string', 'location_string')] return_parts.append('&'.join(['facet.field=%s&f.%s.facet.mincount=1' % (ac._search_encode_property(f), ac._search_encode_property(f)) for f in basic_filters])) return_string = '&'.join(return_parts) return return_string
def get_content_item_template(self): config = self.get_unconfigured_config() controller = ActionController(config) sentiment_property = config['content_properties']['added'][0] return ""\ "{{if " + controller._search_encode_property(sentiment_property) + "}}"\ " <li class='action_values tags'>"\ " <label><img src='" + config['image_small'] + "' style='position:relative;top:5px;left:-2px;width:16px;height:16px;'/> Tags:</label> "\ " <span style='font-weight:bold;'>"\ " {{each(index, element) " + controller._search_encode_property(sentiment_property) + "}}"\ " {{if element != '_none' && index < 5}}${element}{{/if}} {{if index == 6}}...{{/if}}"\ " {{/each}}"\ " </span>"\ " </li>"\ "{{/if}}"
def get_content_item_template(self): config = self.get_unconfigured_config() controller = ActionController(config) influence_property = config['content_properties']['added'][0] encoded_property = controller._search_encode_property(influence_property) return ""\ "{{if typeof(" + encoded_property + ") !== 'undefined' && " + encoded_property + " != '_none'}}"\ " <li class='action_values influence'>"\ " <label><img src='" + config['image_small'] + "' style='position:relative;top:5px;left:-2px;width:16px;height:16px;'/> Influence:</label> "\ " <span style='font-weight:bold;'>"\ " <a class='action_inline_filter' data-facet_name='" + encoded_property + "' data-facet_value='${" + encoded_property + "}'>"\ " ${" + encoded_property + "}"\ " </a>"\ " </span>"\ " </li>"\ "{{/if}}"
def apply_actions_to_content_without_historical_check(content, actions): Logger.Info('%s - apply_actions_to_content_without_historical_check - stated' % __name__) Logger.Debug('%s - apply_actions_to_content_without_historical_check - stated with content:%s and action:%s' % (__name__, content, actions)) return_content = content[:] for action in actions: ac = ActionController(action) content_requiring_action = content content_with_action_applied = ac.run_action(content_requiring_action) for item in content_with_action_applied: already_exists = False for return_item in return_content: if return_item['id'] == item['id']: for key in item.keys(): return_item[key] = item[key] already_exists = True if not already_exists: return_content.append(item) Logger.Info('%s - apply_actions_to_content_without_historical_check - finished' % __name__) return return_content
def get_content_item_template(self): config = self.get_unconfigured_config() controller = ActionController(config) followers = config["content_properties"]["added"][0] sentiment = config["content_properties"]["added"][1] return ( "" "{{if " + controller._search_encode_property(followers) + "}}" " <li class='action_values'>" " <label><img src='http://a0.twimg.com/profile_images/1865030972/Draftfcb-Logo-Small-V2_normal.jpg' style='position:relative;top:5px;left:-2px;width:16px;height:16px;'/> Followers:</label> " " <span style='font-weight:bold;'>${" + controller._search_encode_property(followers) + "}</span>" " </li>" "{{/if}}" "{{if " + controller._search_encode_property(sentiment) + "}}" " <li class='action_values'>" " <label><img src='http://a0.twimg.com/profile_images/1865030972/Draftfcb-Logo-Small-V2_normal.jpg' style='position:relative;top:5px;left:-2px;width:16px;height:16px;'/> Draft FCB Sentiment:</label> " " <span style='font-weight:bold;'>${" + controller._search_encode_property(sentiment) + "}</span>" " </li>" "{{/if}}" "" )
solr_data = 'q=*&wt=json&rows=%i&fq=%s' % (len(content_id_query_parts), '%20OR%20'.join(content_id_query_parts)) try: request = urllib2.Request(solr_url, data=solr_data) response = urllib2.urlopen(request) response = json.loads(response.read()) except Exception, e: Logger.Error('%s - apply_actions_to_content_with_historical_check - error:%s' % (__name__, e)) Logger.Info('%s - apply_actions_to_content_with_historical_check - finished' % __name__) return content content_from_solr = response['response']['docs'] content_ids_from_solr = [item['id'] for item in content_from_solr] content_ids_not_in_solr = [item['id'] for item in content if item['id'] not in content_ids_from_solr] content_not_in_solr = [item for item in content if item['id'] in content_ids_not_in_solr] return_content = content[:] for action in actions: ac = ActionController(action) content_id_in_solr_requiring_action = ac.extract_ids_of_content_without_action_applied(content_from_solr) content_in_solr_requiring_action = [item for item in content_from_solr if item['id'] in content_id_in_solr_requiring_action] content_requiring_action = content_not_in_solr + content_in_solr_requiring_action content_with_action_applied = ac.run_action(content_requiring_action) for item in content_with_action_applied: already_exists = False for return_item in return_content: if return_item['id'] == item['id']: for key in item.keys(): return_item[key] = item[key] already_exists = True if not already_exists: return_content.append(item) Logger.Info('%s - apply_actions_to_content_with_historical_check - finished' % __name__) return return_content
def get_content_item_template(self): config = self.get_unconfigured_config() controller = ActionController(config) storyid = config['content_properties']['added'][0] language = config['content_properties']['added'][1] numberofwords = config['content_properties']['added'][2] numberofchars = config['content_properties']['added'][3] locations = config['content_properties']['added'][4] subjects = config['content_properties']['added'][5] industries = config['content_properties']['added'][6] companies = config['content_properties']['added'][7] people = config['content_properties']['added'][8] return "" \ "<li class='action_values' style='padding-top:5px'><label>Language Code:</label> <b>${" + controller._search_encode_property(language) + "}</b></li> " \ "<li class='action_values'><label>Character Count:</label> <b>${" + controller._search_encode_property(numberofchars) + "}</b></li> " \ "{{if " + controller._search_encode_property(locations) + "}}"\ " <li class='action_values'>"\ " <label>locations:</label> "\ " <span style='font-weight:bold;'>"\ " {{each(index, element) " + controller._search_encode_property(locations) + "}}"\ " {{if element != '_none' && index < 5}}${element}{{/if}} {{if index == 6}}...{{/if}}"\ " {{/each}}"\ " </span>"\ " </li>"\ "{{/if}}"\ "{{if " + controller._search_encode_property(subjects) + "}}"\ " <li class='action_values'>"\ " <label>subjects:</label> "\ " <span style='font-weight:bold;'>"\ " {{each(index, element) " + controller._search_encode_property(subjects) + "}}"\ " {{if element != '_none' && index < 5}}${element}{{/if}} {{if index == 6}}...{{/if}}"\ " {{/each}}"\ " </span>"\ " </li>"\ "{{/if}}"\ "{{if " + controller._search_encode_property(industries) + "}}"\ " <li class='action_values'>"\ " <label>industries:</label> "\ " <span style='font-weight:bold;'>"\ " {{each(index, element) " + controller._search_encode_property(industries) + "}}"\ " {{if element != '_none' && index < 5}}${element}{{/if}} {{if index == 6}}...{{/if}}"\ " {{/each}}"\ " </span>"\ " </li>"\ "{{/if}}"\ "{{if " + controller._search_encode_property(companies) + "}}"\ " <li class='action_values'>"\ " <label>companies:</label> "\ " <span style='font-weight:bold;'>"\ " {{each(index, element) " + controller._search_encode_property(companies) + "}}"\ " {{if element != '_none' && index < 5}}${element}{{/if}} {{if index == 6}}...{{/if}}"\ " {{/each}}"\ " </span>"\ " </li>"\ "{{/if}}"\ "{{if " + controller._search_encode_property(people) + "}}"\ " <li class='action_values'>"\ " <label>people:</label> "\ " <span style='font-weight:bold;'>"\ " {{each(index, element) " + controller._search_encode_property(people) + "}}"\ " {{if element != '_none' && index < 5}}${element}{{/if}} {{if index == 6}}...{{/if}}"\ " {{/each}}"\ " </span>"\ " </li>"\ "{{/if}}"