21 log = logging.getLogger(APP_CONSTS.LOGGER_NAME)
22 log.setLevel(logging.DEBUG)
25 ch = logging.StreamHandler()
26 ch.setLevel(logging.DEBUG)
29 formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
32 ch.setFormatter(formatter)
42 configFileName =
'../ini/postprocessor_task_log-rt.ini' 47 logging.config.fileConfig(configFileName)
57 if __name__ ==
'__main__':
61 configName =
'../ini/postprocessor_task.ini' 62 headerFileName =
'../ini/crawler-task_headers.txt' 65 postProcessingApplicationClass.configParser = ConfigParser.ConfigParser()
66 postProcessingApplicationClass.configParser.optionxform = str
67 readOk = postProcessingApplicationClass.configParser.read(configName)
68 logger.debug(
"Read config: %s", str(readOk))
73 url =
'https://www.theguardian.com/us-news/2016/jan/05/obama-gun-control-executive-action-background-checks-licenses-gun-shows-mental-health-funding' 74 urlObj =
URL(siteId, url)
76 processedContent = [{
"title":
"Tearful Obama tightens gun control and tells inactive Congress: 'We can't wait'",
79 processedContents = [base64.b64encode(json.dumps(processedContent))]
82 batchItem =
BatchItem(siteId=siteId, urlId=urlObj.urlMd5, urlObj=urlObj, urlContentResponse=urlContentResponse)
85 batchItem.properties = {
"SOCIAL_RATE":
"{\"retries\":3, \"retries_delay\":5, \"retries_type\":1, \"interval\":10,\"lang\":\"en\", \"sentiment\":1, \"debug\":1, \"timeout\":400, \"social_list\":{\"fb\":[\"https:\/\/www.facebook.com\",\"window.IFRAME_QUERY_URL=\\\"https:\/\/www.facebook.com\/search\/top\/?q=%25QUERY_STRING%25\\\";window.IFRAME_CSCROLL_COUNT=100;window.IFRAME_MAX_TIME=350;window.IFRAME_SFIELD='title';\",{\"name\":\"tests\", \"sets\":[{\"name\":\"set1\", \"items\":[\"1\", \"%MACRO_DATA%\", \"http:\/\/127.0.0.1\/social.js\", \"!5:76:return window.IFRAME_DATA_READY;\", \"return window.MACRO_COLLECT;\"], \"repeat\":1, \"delay\":0}], \"result_type\":0, \"result_content_type\":\"text\/json\"}],\"tw\":[\"https:\/\/www.twitter.com\",\"window.IFRAME_QUERY_URL=\\\"https:\/\/twitter.com\/search?f=tweets&vertical=default&q=%25QUERY_STRING%25&src=typd\\\",window.IFRAME_CSCROLL_COUNT=100;window.IFRAME_MAX_TIME=350;window.IFRAME_SFIELD='source_url';\",{\"name\":\"tests\", \"sets\":[{\"name\":\"set1\", \"items\":[\"1\", \"%MACRO_DATA%\", \"http:\/\/127.0.0.1\/social.js\", \"!5:76:return window.IFRAME_DATA_READY;\", \"return window.MACRO_COLLECT;\"], \"repeat\":1, \"delay\":0}], \"result_type\":0, \"result_content_type\":\"text\/json\"}]} }"}
86 batch =
Batch(77777, [batchItem])
88 logger.debug(
"Input batch: %s",
varDump(batch))
89 socialModule =
SocialModule(postProcessingApplicationClass.getConfigOption, postProcessingApplicationClass.logger)
91 batch = socialModule.processBatch(batch)
92 logger.debug(
"Output batch: %s",
varDump(batch))
def varDump(obj, stringify=True, strTypeMaxLen=256, strTypeCutSuffix='...', stringifyType=1, ignoreErrors=False, objectsHash=None, depth=0, indent=2, ensure_ascii=False, maxDepth=10)