def completeTask(task): try: req = {'uid': 'NET_0', 'task': task} errorCode, rsp = HttpHelper.post(DISPATCHER_URL + "/webapi/complete2", req) if rsp != None and 'errorCode' in rsp and rsp['errorCode'] == 'OK': print("complete task ok, task=" + json.dumps(task)) else: print("complete task error, rsp=" + json.dumps(rsp)) except Exception as err: print(err)
def createPost(pd): url = HTQ_ROOT_URL + "/wp-content/plugins/post-api/insert_post.php?token=P@ssw0rd&dummy=" + str(random.random()) req = { 'ID': 0, 'author': 1, 'title': pd['title'], 'excerpt': pd['description'], 'content': pd['contenthtml'], 'categories': [CAT_ID], 'tags': [], } errorCode, rsp = HttpHelper.post(url, req) if errorCode == 'OK' and 'errorCode' in rsp and rsp['errorCode'] == 'OK': print(rsp['ID']) return rsp['ID'] else: return None
def importAllArticle(MONGO_HOST, MONGO_DATABASE_NAME, IMPORT_URL): try: articleCollection = MongoHelper(MONGO_HOST, 27017, MONGO_DATABASE_NAME, 'pages') total = 0 while True: articleList = articleCollection.nextPage(10) if len(articleList) == 0: break total += len(articleList) print("total=" + str(total)) newArticleList = [] for article in articleList: if article['state'] != "pass": continue #print (str(article['_id'])) doc = { 'id': article['md5'], 'title': article['title'], 'excerpt': article['excerpt'], 'content': "", 'author': article['domain'], 'domain': article['domain'], 'categories': article['categories'], 'tags': article['tags'], 'url': article['url'], 'status': article['status'], 'key': article['key'], } newArticleList.append(doc) errorCode, rsp = HttpHelper.post(IMPORT_URL, newArticleList) if errorCode == "OK" and rsp != None and 'isOk' in rsp and rsp[ 'isOk'] == True: print("import article ok") else: print("import article error") newArticleList.clear() article['state'] = "sended" articleCollection.updateOne(article) except Exception as err: print(err) finally: print("exit")
def getTask(): try: req = {'uid': 'NET_0', 'whiteList': ['default.robot']} errorCode, rsp = HttpHelper.post(DISPATCHER_URL + "/webapi/task2", req) if rsp != None and 'errorCode' in rsp and rsp[ 'errorCode'] == 'OK' and 'taskList' in rsp and rsp[ 'taskList'] != None: task = rsp['taskList'][0] print("get task ok, task=" + json.dumps(task)) return ['OK', task] else: print("get task error, rsp=" + json.dumps(rsp)) return [rsp['errorCode'], None] except Exception as err: print(err) return ['UNKNOWN', None]
def sendPage(task, html): if html != None and len(html) > 1024: req = { 'task': task, 'redirectUrl': task['url'], 'page': { 'content': None, 'encoding': 'UTF8', 'html': html, }, } errorCode, rsp = HttpHelper.post(DATACENTER_URL + "/webapi/page2", req) if rsp != None and 'errorCode' in rsp and rsp['errorCode'] == 'OK': print("sendPage OK: url: {0}".format(DATACENTER_URL + "/webapi/page2")) return True else: print("sendPage ERROR: url: {0}".format(DATACENTER_URL + "/webapi/page2")) return False