コード例 #1
0
 def handle(self, *args, **options):
     date = tools.getDate()
     users = User.objects.all()
     for user in users:
         if DayData.objects.filter(user=user,date=date).count() > 0:
             dayData = DayData.objects.filter(user=user,date=date)[0]
             steps = dayData.steps
             steps_goal = dayData.steps_goal
             if steps >= steps_goal:
                 per = 100
             else:
                 per = int(steps * 100 / steps_goal)
             url = "%s/basic/redirect/profile?page=0"
             data = {
               "steps":{
                "value": str(dayData.steps),
                "color": "#ff0000",
                },
                "per":{
                 "value": str(per),
                 "color": "#007fff"
                },
                "remark":{
                 "value": u"点击查看详细信息",
                 "color": "#666666"
                }
             }
             wechat_tools.customSendTemplate(user.openId, wechat_tools.template_id["data"], "#000000", data, url)
コード例 #2
0
def sendInvite(user, id, friendId, type):
    url = "%s/match/redirect/profile?page=3&id=%d" % (wechat_tools.domain, id)
    match = Match.objects.get(id=id)
    if type == 0:
        identity = u"队友"
    else:
        identity = u"对手"
    data = {
        "friend": {
            "value": user.name,
            "color": "#ff0000",
        },
        "name": {
            "value": u"%s比赛" % match.name,
            "color": "#007fff",
        },
        "identity": {
            "value": identity,
            "color": "#ff0000",
        },
        "remark": {
            "value": u"详情请点击查看",
            "color": "#666666"
        }
    }
    wechat_tools.customSendTemplate(friendId,
                                    wechat_tools.template_id["invite"],
                                    "#000000", data, url)
コード例 #3
0
def sendInvite(user, id, friendId, type):
    url = "%s/match/redirect/profile?page=3&id=%d" % (wechat_tools.domain, id)
    match = Match.objects.get(id=id)
    if type == 0:
        identity = u"队友"
    else:
        identity = u"对手"
    data = {
      "friend":{
        "value": user.name,
        "color": "#ff0000",
      },
      "name":{
        "value": u"%s比赛" % match.name,
        "color": "#007fff",
      },
      "identity":{
        "value": identity,
        "color": "#ff0000",
      },
      "remark":{
        "value": u"详情请点击查看",
        "color": "#666666"
      }
    }
    wechat_tools.customSendTemplate(friendId, wechat_tools.template_id["invite"], "#000000", data, url)
コード例 #4
0
def LevelCheck(user, data):
    user.steps += tools.caloriesToStep(data.calories, user.height, user.weight)
    user.save()
    flag = False
    while user.steps > tools.levelGap[user.level]:
        user.level += 1
        flag = True
    if flag:
        url = "%s/basic/redirect/profile?page=3"
        data = {"level": {"value": str(user.level), "color": "#ff0000"}}
        wechat_tools.customSendTemplate(user.openId, wechat_tools.template_id["levelUp"], "#000000", data, url)
コード例 #5
0
def MatchCheck(user, match, progress):
    now = tools.getNow()
    url = "%s/match/redirect/profile?page=3&id=%d" % (wechat_tools.domain,
                                                      match.id)
    if now > match.endTime:
        match.finished = 1
        match.save()
        data = {
            "title": {
                "value": u"比赛结束",
                "color": "#ff0000"
            },
            "content": {
                "value": u"%s比赛已经截止,快来看看你们的战况吧!" % match.name,
                "color": "#007fff"
            },
            "remark": {
                "value": u"点击查看比赛详情",
                "color": "#666666"
            }
        }
        wechat_tools.customSendTemplate(user.openId,
                                        wechat_tools.template_id["msg"],
                                        "#000000", data, url)
    elif match.endTime - now < 7200:
        data = {
            "object": {
                "value": u"%s比赛" % match.name,
                "color": "#007fff"
            },
            "lastTime": {
                "value": tools.left_time(now, match.endTime),
                "color": "#ff0000"
            },
            "steps": {
                "value": str(progress.value),
                "color": "#007fff"
            },
            "remark": {
                "value": u"点击查看比赛详情",
                "color": "#666666"
            }
        }
        wechat_tools.customSendTemplate(user.openId,
                                        wechat_tools.template_id["progress"],
                                        "#000000", data, url)
コード例 #6
0
def LevelCheck(user, data):
    user.steps += tools.caloriesToStep(data.calories, user.height, user.weight)
    user.save()
    flag = False
    while user.steps > tools.levelGap[user.level]:
        user.level += 1
        flag = True
    if flag:
        url = "%s/basic/redirect/profile?page=3"
        data = {
            "level": {
                "value": str(user.level),
                "color": "#ff0000",
            }
        }
        wechat_tools.customSendTemplate(user.openId,
                                        wechat_tools.template_id["levelUp"],
                                        "#000000", data, url)
コード例 #7
0
def MatchCheck(user, match, progress):
    now = tools.getNow()
    url = "%s/match/redirect/profile?page=3&id=%d" % (wechat_tools.domain, match.id)
    if now > match.endTime:
        match.finished = 1
        match.save()
        data = {
            "title": {"value": u"比赛结束", "color": "#ff0000"},
            "content": {"value": u"%s比赛已经截止,快来看看你们的战况吧!" % match.name, "color": "#007fff"},
            "remark": {"value": u"点击查看比赛详情", "color": "#666666"},
        }
        wechat_tools.customSendTemplate(user.openId, wechat_tools.template_id["msg"], "#000000", data, url)
    elif match.endTime - now < 7200:
        data = {
            "object": {"value": u"%s比赛" % match.name, "color": "#007fff"},
            "lastTime": {"value": tools.left_time(now, match.endTime), "color": "#ff0000"},
            "steps": {"value": str(progress.value), "color": "#007fff"},
            "remark": {"value": u"点击查看比赛详情", "color": "#666666"},
        }
        wechat_tools.customSendTemplate(user.openId, wechat_tools.template_id["progress"], "#000000", data, url)
コード例 #8
0
def sendInvite(user, id, friendId):
    url = "%s/plan/redirect/profile?page=4&id=%d" % (wechat_tools.domain, id)
    plan = Plan.objects.get(id=id)
    data = {
      "friend":{
        "value": user.name,
        "color": "#ff0000",
      },
      "name":{
        "value": u"%s计划" % plan.name,
        "color": "#007fff",
      },
      "identity":{
        "value": u"伙伴",
        "color": "#ff0000",
      },
      "remark":{
        "value": u"详情请点击查看",
        "color": "#666666"
      }
    }
    wechat_tools.customSendTemplate(friendId, wechat_tools.template_id["invite"], "#000000", data, url)
コード例 #9
0
def sendInvite(user, id, friendId):
    url = "%s/plan/redirect/profile?page=4&id=%d" % (wechat_tools.domain, id)
    plan = Plan.objects.get(id=id)
    data = {
        "friend": {
            "value": user.name,
            "color": "#ff0000",
        },
        "name": {
            "value": u"%s计划" % plan.name,
            "color": "#007fff",
        },
        "identity": {
            "value": u"伙伴",
            "color": "#ff0000",
        },
        "remark": {
            "value": u"详情请点击查看",
            "color": "#666666"
        }
    }
    wechat_tools.customSendTemplate(friendId,
                                    wechat_tools.template_id["invite"],
                                    "#000000", data, url)
コード例 #10
0
def friend_add(request):
    if os.environ.get("TEST", None):
        request.session["userId"] = request.GET["userId"]
    try:
        if not "userId" in request.session:
            return HttpResponse("error")
        if not "userId" in request.GET:
            return HttpResponse("error")
        if not request.GET["userId"] == request.session["userId"]:
            return HttpResponse("error")
        result = "success"
        userId = request.GET["userId"]
        user = User.objects.get(openId=userId)
        id = request.GET["target"]
        type = int(request.GET["type"])
        if type == 0:
            target = User.objects.get(openId=id)
            preFriend = PreFriend.objects.filter(user=target, target=user)
            if preFriend.count() > 0:
                user.friends.add(target)
                target.friends.add(user)
                preFriend.delete()
            else:
                url = "%s/basic/redirect/profile?page=4&id=%s" % (
                    wechat_tools.domain, userId)
                data = {
                    "title": {
                        "value": u"好友请求",
                        "color": "#000000",
                    },
                    "content": {
                        "value": u"%s想要加您为好友" % user.name,
                        "color": "#007fff",
                    },
                    "remark": {
                        "value": u"点击查看对方信息",
                        "color": "#666666"
                    }
                }
                wechat_tools.customSendTemplate(
                    id, wechat_tools.template_id["msg"], "#000000", data, url)
                tmp = PreFriend(user=user, target=target)
                tmp.save()
                result = "send"
        else:
            target = user.friend.filter(openId=id)
            user.friends.remove(target)
            target.friends.remove(user)
            url = "%s/basic/redirect/profile?page=4&id=%s" % (
                wechat_tools.domain, userId)
            data = {
                "title": {
                    "value": u"取消好友",
                    "color": "#000000",
                },
                "content": {
                    "value": u"%s取消了好友关系" % user.name,
                    "color": "#007fff",
                },
                "remark": {
                    "value": u"点击查看对方信息",
                    "color": "#666666"
                }
            }
            wechat_tools.customSendTemplate(id,
                                            wechat_tools.template_id["msg"],
                                            "#000000", data, url)
        return HttpResponse(result)
    except:
        return HttpResponse("error")
コード例 #11
0
def clickEvent(msg):
    reply = TextReply(content=u"I am 菜单拉取事件", message=msg)
    user = User.objects.get(openId=msg.source)
    id = user.id
    data = tools.client.user.get(msg.source)
    #更新用户姓名、头像
    user.name = data["nickname"]
    if "headimgurl" in data:
        user.image = data["headimgurl"]
    else:
        user.image = ""
    user.save()
    date = basic_tools.getDate()
    datetime = basic_tools.getDateTime()
    now = basic_tools.getNow()
    if msg.key == "V1001_DATA_TODAY":  #今日战况
        data = DayData.objects.filter(user=user, date=date)
        if len(data) == 0:
            data = DayData(user=user, date=date)
            basic_tools.updateDayData(data, user)
            data.save()
        else:
            data = data[0]
        steps = data.steps
        dayPlan = user.dayPlan
        if steps < dayPlan:
            per = steps * 100 / dayPlan
        else:
            per = 100
        if per <= 25:
            remark = u"前路漫漫,要加油噢!"
        elif per >= 40 and per <= 60:
            remark = u"成功的路已经走了一半,继续努力!"
        elif per == 100:
            remark = u"已经完成预定计划了!你真棒!"
        elif per >= 90:
            remark = u"就快要成功了!加油加油!"
        else:
            remark = ""
        url = "%s/basic/redirect/profile?page=0" % tools.domain
        data = {
            "steps": {
                "value": str(steps),
                "color": "#ff0000",
            },
            "per": {
                "value": str(per),
                "color": "#007fff",
            },
            "remark": {
                "value": remark,
                "color": "#666666"
            }
        }
        tools.customSendTemplate(msg.source, tools.template_id["data"],
                                 "#000000", data, url)
        reply = ""
    elif msg.key == "V1001_DATA_BIND":  #绑定手环
        url = "%s/basic/bind?openId=%s" % (tools.domain, msg.source)
        data = {"content": {"value": u"请点击进入绑定", "color": "#ff5656"}}
        tools.customSendTemplate(msg.source, tools.template_id["msg"],
                                 "#000000", data, url)
        reply = ""
    elif msg.key == "V1001_DATA_HELP":  #帮助
        reply = TextReply(content=tools.help_text, message=msg)
    elif msg.key == "V1001_DATA_PROFILE":  #个人主页
        dayPlan = user.dayPlan
        sleepPlan = user.sleepPlan
        if dayPlan == 0 or sleepPlan == 0:
            remark = u"您的计划设置不完整,请点击进入设置"
        else:
            remark = user.comment
            if remark == "":
                remark = u"点击查看个人信息"
        url = "%s/basic/redirect/profile?page=3" % tools.domain
        data = {
            "dayPlan": {
                "value": str(dayPlan),
                "color": "#ff0000"
            },
            "sleepPlan": {
                "value": str(sleepPlan),
                "color": "#007fff"
            },
            "remark": {
                "value": remark,
                "color": "#666666"
            }
        }
        tools.customSendTemplate(msg.source, tools.template_id["profile"],
                                 "#000000", data, url)
        reply = ""
    elif msg.key == "V1001_PLAN_MAKE":  #制定计划
        articles = []
        articles.append({
            "title": u"制定计划",
            "description": u"快来制定你自己的运动计划吧!",
            "image": "%s/static/img/plan_make.jpg" % tools.domain,
            "url": "%s/plan/redirect/profile?page=0" % tools.domain
        })
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_PLAN_OWN":  #我的计划
        articles = []
        articles.append({
            "title": u"查看我的",
            "description": u"来看看你都有什么运动计划吧",
            "image": "%s/static/img/plan_own.jpg" % tools.domain,
            "url": "%s/plan/redirect/profile?page=3" % tools.domain
        })
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_PLAN_SQUARE":  #计划广场
        articles = []
        articles.append({
            "title": u"计划广场",
            "description": u"新鲜出炉的运动计划",
            "image": "%s/static/img/plan_square.jpg" % tools.domain,
            "url": "%s/plan/redirect/profile?page=2" % tools.domain
        })
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_PLAN_RANK":  #计划排行榜
        articles = []
        articles.append({
            "title": u"计划排行榜",
            "description": u"想知道什么计划更受欢迎么",
            "image": "%s/static/img/plan_rank.jpg" % tools.domain,
            "url": "%s/plan/redirect/profile?page=1" % tools.domain
        })
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_MATCH_MAKE":  #创建比赛
        articles = []
        articles.append({
            "title":
            u"创建比赛",
            "description":
            u"开始一场新的比赛吧!",
            "image":
            "%s/static/img/match_make.jpg" % tools.domain,
            "url":
            "%s/match/redirect/profile?page=0" % tools.domain
        })
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_MATCH_CHECK":  #我的比赛进度查看
        closest_match = match_tools.closest_match(user, now)
        if not closest_match:  #没有未结束的比赛
            data = {
                "title": {
                    "value": u"比赛进度提醒",
                    "color": "#000000"
                },
                "content": {
                    "value": u"没有未结束的比赛",
                    "color": "#ff0000"
                },
                "remark": {
                    "value": u"来亲自发起一场比赛吧!",
                    "color": "#666666"
                }
            }
            url = "%s/match/redirect/profile?page=0" % tools.domain
            tools.customSendTemplate(msg.source, tools.template_id["msg"],
                                     "#000000", data, url)
        else:  #返回最近的比赛的进度
            left_time = basic_tools.left_time(now, closest_match.endTime)
            steps = match_tools.getProgress(closest_match, user)
            data = {
                "object": {
                    "value": u"%s 比赛" % closest_match.title,
                    "color": "#007fff"
                },
                "lastTime": {
                    "value": left_time,
                    "color": "#ff0000"
                },
                "steps": {
                    "value": str(steps),
                    "color": "#007fff"
                },
                "remark": {
                    "value": u"请继续努力!",
                    "color": "#666666"
                }
            }
            url = "%s/match/redirect/profile?page=1" % tools.domain
            tools.customSendTemplate(msg.source, tools.template_id["progress"],
                                     "#000000", data, url)
        reply = ""
    elif msg.key == "V1001_MATCH_SQUARE":  #比赛广场
        articles = []
        articles.append({
            "title":
            u"比赛广场",
            "description":
            u"新鲜出炉的比赛",
            "image":
            "%s/static/img/match_square.jpg" % tools.domain,
            "url":
            "%s/match/redirect/profile?page=2" % tools.domain
        })
        reply = ArticlesReply(articles=articles, message=msg)
    return HttpResponse(reply)
コード例 #12
0
def PlanCheck(user, plan, progress, oldValue):
    now = tools.getNow()
    url = "%s/plan/redirect/profile?page=4&id=%d" % (wechat_tools.domain, plan.id)
    if now > plan.endTime:
        plan.finished = 1
        plan.save()
        if plan.goal > 0 and progress.value >= plan.goal:
            content = u"恭喜您完成了计划"
        elif plan.goal > 0:
            content = u"很遗憾您没能完成计划"
        else:
            content = u"不知道您完成得怎么样呢"
        data = {
            "title": {"value": u"计划截止", "color": "#ff0000"},
            "content": {"value": u"%s计划已经截止,%s" % (plan.name, content), "color": "#007fff"},
            "remark": {"value": u"点击查看计划详情", "color": "#666666"},
        }
        wechat_tools.customSendTemplate(user.openId, wechat_tools.template_id["msg"], "#000000", data, url)
        return
    old_per = per = 0
    if plan.goal > 0:
        per = int(progress.value * 100 / plan.goal)
        old_per = int(oldValue * 100 / plan.goal)
    if per > 100:
        per = 100
    if per == 100:
        plan.finished = 1
        plan.save()
        data = {
            "title": {"value": u"计划完成", "color": "#ff0000"},
            "content": {"value": u"恭喜您提前完成了%s计划已经完成" % plan.name, "color": "#007fff"},
            "remark": {"value": u"点击查看计划详情", "color": "#666666"},
        }
        wechat_tools.customSendTemplate(user.openId, wechat_tools.template_id["msg"], "#000000", data, url)
    elif plan.endTime - now < 7200:
        if per < 90:
            remark = u"请抓紧时间!"
        else:
            remark = u"别错过了ddl噢"
        data = {
            "object": {"value": u"%s计划" % plan.name, "color": "#007fff"},
            "lastTime": {"value": tools.left_time(now, plan.endTime), "color": "#ff0000"},
            "steps": {"value": str(progress.value), "color": "#007fff"},
            "content": {"value": u"您已完成了%d\%" % per, "color": "#ff0000"},
            "remark": {"value": remark, "color": "#666666"},
        }
        wechat_tools.customSendTemplate(user.openId, wechat_tools.template_id["progress"], "#000000", data, url)
    elif (per > 80 and old_per < 80) or (per > 50 and old_per < 50) or (per > 20 and old_per < 20):
        if per > 80:
            remark = u"请继续努力"
        elif per > 50:
            remark = u"长路漫漫,还有一半"
        else:
            remark = u"好的开始是成功的一半"
        data = {
            "object": {"value": u"%s计划" % plan.name, "color": "#007fff"},
            "lastTime": {"value": tools.left_time(now, plan.endTime), "color": "#ff0000"},
            "steps": {"value": str(progress.value), "color": "#007fff"},
            "content": {"value": u"您已完成了%d\%" % per, "color": "#ff0000"},
            "remark": {"value": remark, "color": "#666666"},
        }
        wechat_tools.customSendTemplate(user.openId, wechat_tools.template_id["progress"], "#000000", data, url)
コード例 #13
0
def clickEvent(msg):
    reply = TextReply(content=u"I am 菜单拉取事件", message=msg)
    user = User.objects.get(openId=msg.source)
    id = user.id
    data = tools.client.user.get(msg.source)
    #更新用户姓名、头像
    user.name = data["nickname"]
    if "headimgurl" in data:
        user.image = data["headimgurl"]
    else:
        user.image = ""
    user.save()
    date = basic_tools.getDate()
    datetime = basic_tools.getDateTime()
    now = basic_tools.getNow()
    if msg.key == "V1001_DATA_TODAY": #今日战况
        data = DayData.objects.filter(user=user,date=date)
        if len(data) == 0:
            data = DayData(user=user,date=date)
            basic_tools.updateDayData(data, user)
            data.save()
        else:
            data = data[0]
        steps = data.steps
        dayPlan = user.dayPlan
        if steps < dayPlan:
           per = steps * 100 / dayPlan
        else:
           per = 100
        if per <= 25:
           remark = u"前路漫漫,要加油噢!"
        elif per >= 40 and per <= 60:
           remark = u"成功的路已经走了一半,继续努力!"
        elif per == 100:
           remark = u"已经完成预定计划了!你真棒!"
        elif per >= 90:
           remark = u"就快要成功了!加油加油!"
        else:
           remark = ""
        url = "%s/basic/redirect/profile?page=0" % tools.domain
        data = {
          "steps":{
            "value": str(steps),
            "color": "#ff0000",
          },
          "per":{
            "value": str(per),
            "color": "#007fff",
          },
          "remark":{
            "value": remark,
            "color": "#666666"
          }
        }
        tools.customSendTemplate(msg.source, tools.template_id["data"], "#000000", data, url)
        reply = ""
    elif msg.key == "V1001_DATA_BIND": #绑定手环
        url = "%s/basic/bind?openId=%s" % (tools.domain, msg.source)
        data = {
          "content":{
            "value": u"请点击进入绑定",
            "color": "#ff5656"
          }
        }
        tools.customSendTemplate(msg.source, tools.template_id["msg"], "#000000", data, url) 
        reply = ""
    elif msg.key == "V1001_DATA_HELP": #帮助
        reply = TextReply(content=tools.help_text, message=msg)
    elif msg.key == "V1001_DATA_PROFILE": #个人主页
        dayPlan = user.dayPlan
        sleepPlan = user.sleepPlan
        if dayPlan == 0 or sleepPlan == 0:
            remark = u"您的计划设置不完整,请点击进入设置"
        else:
            remark = user.comment
            if remark == "":
                remark = u"点击查看个人信息"
        url = "%s/basic/redirect/profile?page=3" % tools.domain
        data = {
            "dayPlan":{
              "value": str(dayPlan),
              "color": "#ff0000"
            },
            "sleepPlan":{
              "value": str(sleepPlan),
              "color": "#007fff"
            },
            "remark":{
              "value": remark,
              "color": "#666666"
            }
        }
        tools.customSendTemplate(msg.source, tools.template_id["profile"], "#000000", data, url)
        reply = ""
    elif msg.key == "V1001_PLAN_MAKE":  #制定计划
        articles = []
        articles.append({"title":u"制定计划","description":u"快来制定你自己的运动计划吧!","image":"%s/static/img/plan_make.jpg" % tools.domain,"url":"%s/plan/redirect/profile?page=0" % tools.domain})
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_PLAN_OWN":   #我的计划
        articles = []
        articles.append({"title":u"查看我的","description":u"来看看你都有什么运动计划吧","image":"%s/static/img/plan_own.jpg" % tools.domain,"url":"%s/plan/redirect/profile?page=3" % tools.domain})
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_PLAN_SQUARE":    #计划广场
        articles = []
        articles.append({"title":u"计划广场","description":u"新鲜出炉的运动计划","image":"%s/static/img/plan_square.jpg" % tools.domain,"url":"%s/plan/redirect/profile?page=2" % tools.domain})
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_PLAN_RANK":  #计划排行榜
        articles = []
        articles.append({"title":u"计划排行榜","description":u"想知道什么计划更受欢迎么","image":"%s/static/img/plan_rank.jpg" % tools.domain,"url":"%s/plan/redirect/profile?page=1" % tools.domain})
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_MATCH_MAKE": #创建比赛
        articles = []
        articles.append({"title":u"创建比赛","description":u"开始一场新的比赛吧!","image":"%s/static/img/match_make.jpg" % tools.domain,"url":"%s/match/redirect/profile?page=0" % tools.domain})
        reply = ArticlesReply(articles=articles, message=msg)
    elif msg.key == "V1001_MATCH_CHECK":    #我的比赛进度查看
        closest_match = match_tools.closest_match(user, now)
        if not closest_match:   #没有未结束的比赛
            data = {
                "title":{
                    "value": u"比赛进度提醒",
                    "color": "#000000"
                },
                "content":{
                    "value": u"没有未结束的比赛",
                    "color": "#ff0000"
                },
                "remark":{
                    "value": u"来亲自发起一场比赛吧!",
                    "color": "#666666"
                }
            }
            url = "%s/match/redirect/profile?page=0" % tools.domain
            tools.customSendTemplate(msg.source, tools.template_id["msg"], "#000000", data, url)
        else:   #返回最近的比赛的进度
            left_time = basic_tools.left_time(now, closest_match.endTime)
            steps = match_tools.getProgress(closest_match, user)
            data = {
                "object":{
                    "value": u"%s 比赛" % closest_match.title,
                    "color": "#007fff"
                },
                "lastTime":{
                    "value": left_time,
                    "color": "#ff0000"
                },
                "steps":{
                    "value": str(steps),
                    "color": "#007fff"
                },
                "remark":{
                    "value": u"请继续努力!",
                    "color": "#666666"
                }
            }
            url = "%s/match/redirect/profile?page=1" % tools.domain
            tools.customSendTemplate(msg.source, tools.template_id["progress"], "#000000", data, url)
        reply = ""
    elif msg.key == "V1001_MATCH_SQUARE": #比赛广场
        articles = []
        articles.append({"title":u"比赛广场","description":u"新鲜出炉的比赛","image":"%s/static/img/match_square.jpg" % tools.domain,"url":"%s/match/redirect/profile?page=2" % tools.domain})
        reply = ArticlesReply(articles=articles, message=msg)
    return HttpResponse(reply)
コード例 #14
0
def PlanCheck(user, plan, progress, oldValue):
    now = tools.getNow()
    url = "%s/plan/redirect/profile?page=4&id=%d" % (wechat_tools.domain,
                                                     plan.id)
    if now > plan.endTime:
        plan.finished = 1
        plan.save()
        if plan.goal > 0 and progress.value >= plan.goal:
            content = u"恭喜您完成了计划"
        elif plan.goal > 0:
            content = u"很遗憾您没能完成计划"
        else:
            content = u"不知道您完成得怎么样呢"
        data = {
            "title": {
                "value": u"计划截止",
                "color": "#ff0000"
            },
            "content": {
                "value": u"%s计划已经截止,%s" % (plan.name, content),
                "color": "#007fff"
            },
            "remark": {
                "value": u"点击查看计划详情",
                "color": "#666666"
            }
        }
        wechat_tools.customSendTemplate(user.openId,
                                        wechat_tools.template_id["msg"],
                                        "#000000", data, url)
        return
    old_per = per = 0
    if plan.goal > 0:
        per = int(progress.value * 100 / plan.goal)
        old_per = int(oldValue * 100 / plan.goal)
    if per > 100:
        per = 100
    if per == 100:
        plan.finished = 1
        plan.save()
        data = {
            "title": {
                "value": u"计划完成",
                "color": "#ff0000"
            },
            "content": {
                "value": u"恭喜您提前完成了%s计划已经完成" % plan.name,
                "color": "#007fff"
            },
            "remark": {
                "value": u"点击查看计划详情",
                "color": "#666666"
            }
        }
        wechat_tools.customSendTemplate(user.openId,
                                        wechat_tools.template_id["msg"],
                                        "#000000", data, url)
    elif plan.endTime - now < 7200:
        if per < 90:
            remark = u"请抓紧时间!"
        else:
            remark = u"别错过了ddl噢"
        data = {
            "object": {
                "value": u"%s计划" % plan.name,
                "color": "#007fff"
            },
            "lastTime": {
                "value": tools.left_time(now, plan.endTime),
                "color": "#ff0000"
            },
            "steps": {
                "value": str(progress.value),
                "color": "#007fff"
            },
            "content": {
                "value": u"您已完成了%d\%" % per,
                "color": "#ff0000"
            },
            "remark": {
                "value": remark,
                "color": "#666666"
            }
        }
        wechat_tools.customSendTemplate(user.openId,
                                        wechat_tools.template_id["progress"],
                                        "#000000", data, url)
    elif (per > 80 and old_per < 80) or (per > 50 and old_per < 50) or (
            per > 20 and old_per < 20):
        if per > 80:
            remark = u"请继续努力"
        elif per > 50:
            remark = u"长路漫漫,还有一半"
        else:
            remark = u"好的开始是成功的一半"
        data = {
            "object": {
                "value": u"%s计划" % plan.name,
                "color": "#007fff"
            },
            "lastTime": {
                "value": tools.left_time(now, plan.endTime),
                "color": "#ff0000"
            },
            "steps": {
                "value": str(progress.value),
                "color": "#007fff"
            },
            "content": {
                "value": u"您已完成了%d\%" % per,
                "color": "#ff0000"
            },
            "remark": {
                "value": remark,
                "color": "#666666"
            }
        }
        wechat_tools.customSendTemplate(user.openId,
                                        wechat_tools.template_id["progress"],
                                        "#000000", data, url)
コード例 #15
0
def friend_add(request):
    if os.environ.get("TEST", None):
        request.session["userId"] = request.GET["userId"]
    try:
        if not "userId" in request.session:
            return HttpResponse("error")
        if not "userId" in request.GET:
            return HttpResponse("error")
        if not request.GET["userId"] == request.session["userId"]:
            return HttpResponse("error")
        result = "success"
        userId = request.GET["userId"]
        user = User.objects.get(openId=userId)
        id = request.GET["target"]
        type = int(request.GET["type"])
        if type == 0:
            target = User.objects.get(openId=id)
            preFriend = PreFriend.objects.filter(user=target,target=user)
            if preFriend.count() > 0:
                user.friends.add(target)
                target.friends.add(user)
                preFriend.delete()
            else:
                url = "%s/basic/redirect/profile?page=4&id=%s" % (wechat_tools.domain, userId)
                data = {
                  "title":{
                   "value":u"好友请求",
                   "color":"#000000",
                  },
                  "content":{
                   "value":u"%s想要加您为好友" % user.name,
                   "color":"#007fff",
                  },
                  "remark":{
                   "value":u"点击查看对方信息",
                   "color":"#666666"
                  }
                }
                wechat_tools.customSendTemplate(id, wechat_tools.template_id["msg"], "#000000", data, url)
                tmp = PreFriend(user=user,target=target)
                tmp.save()
                result = "send"
        else:
            target = user.friend.filter(openId=id)
            user.friends.remove(target)
            target.friends.remove(user)
            url = "%s/basic/redirect/profile?page=4&id=%s" % (wechat_tools.domain, userId)
            data = {
              "title":{
               "value":u"取消好友",
               "color":"#000000",
              },
              "content":{
               "value":u"%s取消了好友关系" % user.name,
               "color":"#007fff",
              },
              "remark":{
               "value":u"点击查看对方信息",
               "color":"#666666"
              }
            }
            wechat_tools.customSendTemplate(id, wechat_tools.template_id["msg"], "#000000", data, url)
        return HttpResponse(result)
    except:
        return HttpResponse("error")