def userWork(): query = {"limit": 10, "sort": [{"id": -1}], "offset": 0} ret = userService().query(uha.TUser(), json.dumps(query)) while (ret.offset < ret.total): for i in ret.result: generateUserData(i) query["offset"] += 10 ret = userService().query(uha.TUser(), json.dumps(query))
def run(self, args): if len(args) > 1: print(self.appName() + ": too many arguments") return 1 userService = None publishService = None try: query = IceGrid.QueryPrx.checkedCast( self.communicator().stringToProxy( "UhaIceGrid/Query")) userService = uha.UserServicePrx.checkedCast( query.findObjectByType("::uha::UserService")) publishService = uha.PublishServicePrx.checkedCast( query.findObjectByType("::uha::PublishService")) except Exception as e: print e print userService.query(uha.TUser(), '{"limit": 1}') print publishService.query(uha.TComment(), '{"limit": 1}') if not userService: print(self.appName() + ": couldn't find a `::uha::UserService' object.") return 1 return 0
def dispatchActivityStartWarnning(m): content = json.loads(m.content) mediaId = content.get("activityId") mediaInfo = mediaSerializer(objectToDict(getMediaById(mediaId))) userInfo = userSerializer( objectToDict(UserService().getById(uha.TUser(), content.get("userId")))) content = {} content["usersInfo"] = [userInfo] content["mediaInfo"] = mediaInfo m.content = json.dumps(content) offset = 0 total = 0 query = {"filter": {"activityId": mediaId}} while offset >= total: ret = PublishService().query(uha.TParticipantInfo(), json.dumps(query)) offset = ret.offset total = ret.total m.type = "user.activity.attention.start.warning" startTime = time.strftime( "%m月%d日%H时%M分", time.gmtime(mediaInfo["activityInfo"]["startTime"])) for r in ret.result: m.dispatchTo = r.userId m.alert = AlertTemplate.activity_warning.format( userName=userInfo["name"], activityName=mediaInfo["title"], startTime=startTime) cachedDispatchMessage(m)
def actionWork(): query = { "limit": 10, "filter": { "actionType": "govpage_publish_media" }, "sort": [{ "id": -1 }], "offset": 0 } ret = publishService().query(uha.TAction(), json.dumps(query)) while (ret.offset < ret.total): for i in ret.result: if i.pageId == 0: m = govpageService().getById(uha.TGovPageMedia(), i.targetId) if m: i.pageId = m.pageId i = publishService().updateById(i) print i query["offset"] += 10 ret = userService().query(uha.TUser(), json.dumps(query))
def dispatchMessage(dispatchMessage): if dispatchMessage.type in ["user.media.comment", "user.media.vote"]: content = json.loads(dispatchMessage.content) mediaId = content.get("targetId") mediaInfo = getMediaById(mediaId) userInfo = UserService().getById(uha.TUser(), content.get("userId")) content["mediaInfo"] = mediaSerializer(objectToDict(mediaInfo)) content["userInfo"] = userSerializer(objectToDict(userInfo)) dispatchMessage.content = json.dumps(content) dispatchMessage.dispatchTo = mediaInfo.promulgatorId if dispatchMessage.type == "user.media.comment": dispatchMessage.alert = "%s 评论了 %s" % (userInfo.name, mediaInfo.title) elif dispatchMessage.type == "user.media.vote": dispatchMessage.alert = "%s 赞了 %s" % (userInfo.name, mediaInfo.title) dispatchMessage = cachedDispatchMessage(dispatchMessage) elif isMatchType(dispatchMessage.type, ["user.activity"]): content = json.loads(dispatchMessage.content) mediaId = content.get("activityId") mediaInfo = getMediaById(mediaId) userInfo = UserService().getById(uha.TUser(), content.get("userId")) content["mediaInfo"] = mediaSerializer(objectToDict(mediaInfo)) content["userInfo"] = userSerializer(objectToDict(userInfo)) dispatchMessage.content = json.dumps(content) dispatchMessage.dispatchTo = mediaInfo.promulgatorId if dispatchMessage.type == "user.activity.join": dispatchMessage.alert = "%s 申请加入了 %s 活动" % (userInfo.name, mediaInfo.title) elif dispatchMessage.type == "user.activity.exit": dispatchMessage.alert = "%s 退出了 %s 活动" % (userInfo.name, mediaInfo.title) dispatchMessage = cachedDispatchMessage(dispatchMessage) dealWithActivityMessage(dispatchMessage) elif isMatchType(dispatchMessage.type, [ "govpage.report.media", "govpage.contribute", "govpage.confirm.contribute" ]): content = json.loads(dispatchMessage.content) mediaId = content.get("sourceMediaId") pageId = content.get("pageId") mediaInfo = getMediaById(mediaId) userInfo = UserService().getById(uha.TUser(), mediaInfo.promulgatorId) content["mediaInfo"] = mediaSerializer(objectToDict(mediaInfo)) content["userInfo"] = userSerializer(objectToDict(userInfo)) dispatchMessage.content = json.dumps(content) if dispatchMessage.type.find("govpage.contribute") == 0: dispatchMessage.alert = "%s 申请投稿 %s" % (userInfo.name, mediaInfo.title) elif dispatchMessage.type == "govpage.report.media": dispatchMessage.alert = "%s 举报了 %s" % (userInfo.name, mediaInfo.title) if isMatchType(dispatchMessage.type, ["govpage.confirm.contribute"]): dispatchMessage.dispatchTo = dispatchMessage.senderId dispatchMessage = cachedDispatchMessage(dispatchMessage) roles = ["admin", "creator"] ms = getGovpageMembersByRole(pageId, roles) logger.info(ms) for i in ms.result: dispatchMessage.dispatchTo = i.userId dispatchMessage = cachedDispatchMessage(dispatchMessage) logger.info(dispatchMessage) elif dispatchMessage.type in ["govpage.apply.join", "govpage.apply.admin"]: content = json.loads(dispatchMessage.content) pageId = content.get("pageId") pageInfo = GovpageService().getById(uha.TGovPage(), pageId) userInfo = UserService().getById(uha.TUser(), dispatchMessage.senderId) content["pageInfo"] = govPageSerializer(objectToDict(pageInfo)) content["userInfo"] = userSerializer(objectToDict(userInfo)) dispatchMessage.content = json.dumps(content) if dispatchMessage.type == "govpage.apply.join": dispatchMessage.alert = "%s 申请加入 %s" % (userInfo.name, pageInfo.name) elif dispatchMessage.type == "govpage.apply.admin": dispatchMessage.alert = "%s 申请加入 %s" % (userInfo.name, pageInfo.name) admins = getGovpageMembersByRole(pageId) for i in admins.result: dispatchMessage.dispatchTo = i.userId dispatchMessage = cachedDispatchMessage(dispatchMessage) else: dispatchMessage = cachedDispatchMessage(dispatchMessage) return dispatchMessage
def dealWithActivityMessage(dispatchMessage): content = json.loads(dispatchMessage.content) mediaId = content.get("activityId") mediaInfo = mediaSerializer(objectToDict(getMediaById(mediaId))) userInfo = userSerializer( objectToDict(UserService().getById(uha.TUser(), content.get("userId")))) content["mediaInfo"] = mediaInfo content["userInfo"] = userInfo dispatchMessage.content = json.dumps(content) dispatchMessage.dispatchTo = mediaInfo["promulgatorId"] dispatchMessage = cachedDispatchMessage(dispatchMessage) if dispatchMessage.type == "user.activity.join": filter = { "type": "user.activity.attention.join", "status": "new", "dispatchTo": mediaInfo["promulgatorId"] } m = NoticeService().getOneByFilter(uha.TDispatchMessage(), json.dumps(filter)) if m and json.loads(m.content).get("activityId"): m.alert = AlertTemplate.activity_join.format( userName=userInfo["name"], activityName=mediaInfo["title"]) content = json.loads(m.content) content["usersInfo"].append(userInfo) m.content = json.dumps(content) NoticeService().updateById(m) else: m = copy.deepcopy(dispatchMessage) content = {} content["usersInfo"] = [userInfo] content["mediaInfo"] = mediaInfo m.content = json.dumps(content) m.type = "user.activity.attention.join" m.alert = AlertTemplate.activity_join.format( userName=userInfo["name"], activityName=mediaInfo["title"]) cachedDispatchMessage(m) elif dispatchMessage.type == "user.activity.confirm.join": m = copy.deepcopy(dispatchMessage) content = {} content["usersInfo"] = [userInfo] content["mediaInfo"] = mediaInfo m.content = json.dumps(content) m.dispatchTo = userInfo["id"] m.alert = AlertTemplate.activity_confirm.format( userName=userInfo["name"], activityName=mediaInfo["title"]) m.type = "user.activity.attention.confirm.join" cachedDispatchMessage(m) elif dispatchMessage.type == "user.activity.reject.join": m = copy.deepcopy(dispatchMessage) content = {} content["usersInfo"] = [userInfo] content["mediaInfo"] = mediaInfo m.content = json.dumps(content) m.dispatchTo = userInfo["id"] m.alert = AlertTemplate.activity_reject.format( userName=userInfo["name"], activityName=mediaInfo["title"]) m.type = "user.activity.attention.reject.join" cachedDispatchMessage(m) elif "user.activity.start.warning" == dispatchMessage.type: m = copy.deepcopy(dispatchMessage) dispatchActivityStartWarnning(m) elif "user.activity.exit" == dispatchMessage.type: m = copy.deepcopy(dispatchMessage) content = {} content["usersInfo"] = [userInfo] content["mediaInfo"] = mediaInfo m.content = json.dumps(content) m.dispatchTo = userInfo["id"] m.alert = AlertTemplate.activity_exit.format( activityName=mediaInfo["title"]) m.type = "user.activity.attention.exit" cachedDispatchMessage(m)