示例#1
0
def redirect_song_export_express(creator_id, start_time, end_time):
    """
    [HTTPRequest]SONG导出运单信息
    :param creator: 下单者id,商户id
    :param start_time: 起始时间
    :param end_time: 终止时间
    """
    url = settings.BL_DAS_API_PREFIX + "/express/export/song"
    url = url_concat(
        url, {
            "shop_id": creator_id,
            "start_time": TimeZone.datetime_to_str(start_time),
            "end_time": TimeZone.datetime_to_str(end_time)
        })
    return HTTPRequest(url, method="GET", **timeouts)
示例#2
0
 def schedule(self, scheduled_time):
     """
     定时发送
     :param scheduled_time:
     :return: schedule token for cancelling
     """
     json_data = {
         "type": conf.MQ_TYPE_SCHEDULE,
         "scheduled_time": TimeZone.datetime_to_str(scheduled_time),
         "data": self
     }
     return self._send(json.dumps(json_data))
示例#3
0
def modify_sj_time(expr_cursor):
    i = 0
    for doc in expr_cursor:
        i += 1
        times = []
        _times = []
        for k, t in list(doc['times'].items()):
            if k != 'sj_time':
                times.append(t)

        times = sorted(times)
        for t in times:
            _times.append(TimeZone.datetime_to_str(t, pattern='%H:%M'))

        sj_time = min(times)
        result = mc.update_one({'_id': doc['_id']},
                               {'$set': {
                                   'times.sj_time': sj_time
                               }})
        print(('%s, %s, min%s => [%s], %s, %s' %
               (i, doc['number'], _times,
                TimeZone.datetime_to_str(sj_time, pattern='%H:%M'),
                result.matched_count, result.modified_count)))
示例#4
0
def api_deliveryman_sign_in():
    """
    派件系人员签到
    :param man_id: 根据 id 查出 name, tel, avatar
    :param loc: {name, addr, lng, lat}
    :param device: {mac_id, ...}
    :return: 失败返回400和message
    """
    params = ctx.request.input()
    # ==> 根据id拿基本信息
    man = Man.objects(id=params.man_id).first()
    # ==> 检查今日签到次数
    now = TimeZone.local_now()
    start_time, _end_time = TimeZone.day_range(value=now)
    start_time = TimeZone.datetime_to_str(start_time)
    sign_in_count = SignIn.objects(**{
        'man_id': params.man_id,
        'create_time__gte': start_time
    }).count()
    if sign_in_count >= 50:
        logging.warn("Man[%s][%s] try to sign in over 10 times." %
                     (params.man_id, man.name))
        raise ValueError("一天最多签到10次")
    # ==> 记录这次签到
    name = man.name if man.name else ''
    avatar = man.avatar if man.avatar else ''
    SignIn(man_id=params.man_id,
           name=name,
           tel=man.tel,
           avatar=avatar,
           loc=params.loc,
           device=params.device,
           create_time=now).save(force_insert=True)
    return {
        'create_time': TimeZone.datetime_to_str(now,
                                                pattern='%Y-%m-%dT%H:%M:%S')
    }
示例#5
0
 def format_response(self):
     return {
         "cli": self.channel_leancloud_id,
         "name": self.name,
         "description": self.description,
         "icon": get_image_url(self.icon),
         "sticky": self.sticky,
         "top": self.top,
         "talkable": self.talkable,
         "disabled": self.disabled,
         "manager": self.manager,
         "answerer": self.answerer,
         "subscriber_condition": self.subscriber_condition,
         "create_time": TimeZone.datetime_to_str(self.create_time)
     }
示例#6
0
def api_retrieve_man_info(what):
    what = str(what).upper().strip()
    request = ctx.request.input()
    # 如果传入what,by不是允许的值,直接报错
    if what not in WHATS:
        raise ValueError("WHAT[%s] should be in WHATS%s." %
                         (what, list(WHATS.keys())))
    params = set([str(k).lower().strip() for k in request])
    bys = set(BYS.keys())
    by = params.intersection(bys)
    if not by:
        raise ValueError("BY%s should be in BYS%s." %
                         (list(params), list(bys)))
    by_key = next(iter(by))
    by_val = request[by_key]
    if by_key == 'id' and by_val and len(by_val) != 24:
        raise ValueError('find man with id=%s, id should be of length 24.' %
                         by_val)
    # 判断是要什么类型的返回
    if what == WHATS.BASIC:
        excludes = ('accounts', 'create_time', 'my_man')
        man = Man.objects(**{by_key: by_val}).exclude(*excludes).first()
        if not man:
            raise ValueError("Can't find man with[%s]=[%s]." %
                             (by_key, by_val))
        packed = ManLogic.pack_man(man, excludes=excludes)
        ret_cnt = ('familiars', 'pick_up_locations')
        for k in ret_cnt:
            if k in packed:
                packed[k] = len(packed[k]) if packed[k] else 0
        return packed
    elif what == WHATS.ACCOUNT_LIST:
        man = Man.objects(**{by_key: by_val}).only('accounts').first()
        return man.accounts
    elif what == WHATS.FAMILIAR_LIST:
        man = Man.objects(**{by_key: by_val}).only('familiars').first()
        return man.familiars
    elif what == WHATS.STATUS:
        man = Man.objects(**{by_key: by_val}).only('status').first()
        return man.status
    elif what == WHATS.MAN_LIST:
        man = Man.objects(**{by_key: by_val}).only('my_man').first()
        if man and man.my_man:
            only = ('status', 'id', 'name', 'tel', 'avatar')
            my_man = {m['id']: m['bind_time'] for m in man.my_man}
            mans = Man.objects(id__in=list(my_man.keys())).only(*only)
            ret = []
            for m in mans:
                packed_man = ManLogic.pack_man(m, only=only)
                packed_man['bind_time'] = my_man[str(m.pk)]
                ret.append(packed_man)
            return ret
        else:
            return []
    elif what == WHATS.CODE:
        # 取header里面的app-name, 没给的话就给man
        app_name = ctx.request.header('app-name', 'man')
        man_id = by_val
        code = shortuuid.ShortUUID().random(length=8)
        # role是区域经理app端header里面的app-name
        key = key_man_code.format(role=app_name, content=code)
        # 存放: 二维码(360秒): get <app-name>:code:fe11ad907e2fa779ed2f363ef589d3f9 => 56f1028b2d50c07c80914393
        redis_client.setex(key, man_id, 360)
        logging.info('Setting Code [%s] => [%s].' % (key, man_id))
        return key
    elif what == WHATS.PICKUP_LIST:
        man = Man.objects(**{by_key: by_val}).only('pick_up_locations').first()
        return man.pick_up_locations
    elif what == WHATS.SIGN_IN_COUNT:
        # 获取人员名字
        man = Man.objects(id=by_val).only('name').first()
        name = man.name if man.name else ''
        # 获取今天凌晨以后的签到记录次数
        now = TimeZone.local_now()
        start_time, _end_time = TimeZone.day_range(value=now)
        start_time = TimeZone.datetime_to_str(start_time)
        sign_in_count = SignIn.objects(**{
            by_key: by_val,
            'create_time__gte': start_time
        }).count()
        return dict(name=name,
                    sign_in_count=sign_in_count,
                    server_time=TimeZone.datetime_to_str(
                        now, pattern='%Y-%m-%dT%H:%M:%S'))
示例#7
0
                          data=urllib.parse.urlencode(params),
                          headers=headers,
                          timeout=5)
    except Exception as e:
        print((traceback.format_exc()))
        return False, {'error': str(e)}
    response = r.json()

    if "response_params" in response:
        return True, {}
    else:
        return False, response


if __name__ == '__main__':
    from tools_lib.common_util.archived.gtz import TimeZone

    msg = {
        "source": "deliver",
        "type": "force_deliver_notice",
        "content": {
            "title": "测试",
            "body": "同志们好,首长好",
            "create_time": TimeZone.datetime_to_str(TimeZone.utc_now()),
        }
    }

    print((baidu_push_v3('3737072413124982526',
                         msg,
                         device_type=PLATFORM_ANDROID)))
示例#8
0
文件: app.py 项目: cash2one/Logistics
 def get(self):
     now = TimeZone.utc_now()
     self.write_response(content=TimeZone.datetime_to_str(now))