示例#1
0
def edit(local):
    # id = request.args.get('local')
    type = search(local)
    print("LOCAL::::",local)

    if request.method == 'POST':
        option(request.form, local, "edit_id")
        return redirect('/' + local)

    if type=="sellers":
        # print("id:",id)
        head = ["id","pwd"]

        sql = "SELECT * FROM sellers WHERE local=\'{}\'".format(local)
        info = list(sqlQuery_(sql)[0])
        info = [info[3],info[1],info[5]]
        print("ready for edit:",info)
        return render_template("edit_p.html",info=info,head=head)
    elif type=="deliveries":
        return render_template("edit_d.html")
    elif type=="customers":
        head = ["id", "pwd"]
        sql = "SELECT * FROM customers WHERE local=\'{}\'".format(local)
        info = list(sqlQuery_(sql)[0])
        info = [info[3],info[1],info[5]] # [local, name, pwd]
        print("ready for edit:",info)
        return render_template("edit_p.html",info=info,head=head)
    else:
        print("error 02.")
        return render_template("/"+local+".html")
示例#2
0
def newOrder(local):
    if request.method == 'POST':
        option(request.form, local, "save_order")
        return redirect("/"+local)

    try:
        tmp = sqlQuery_("""SELECT cid,lat,lng FROM customers WHERE local=%s""",(local,))[0]
    except IndexError:
        return redirect('/')

    customer_info = []
    for t in tmp:
        customer_info.append(t)
    print("customer:",customer_info)
    dt = datetime.datetime.now()
    print("~~~~~~~:",dt.hour)
    if dt.hour==0:
        timeNow = 2400+dt.minute
    else:
        timeNow = dt.hour*100+dt.minute

    near_stores = sqlQuery_("""SELECT S.sid, (S.lat - C.lat)^2 + (S.lng - C.lng)^2 as distance, S.sname
        FROM stores S, customers C, store_schedules SS
        WHERE S.sid = SS.sid
            AND day_no = %s AND SS.holiday = false AND SS.opened <= %s AND SS.closed >= %s
            AND C.cid = %s
        ORDER BY distance ASC
        limit 100;""",(dt.weekday(),timeNow,timeNow,customer_info[0], ) )
    print(near_stores)

    return render_template("orderMenu.html",local=local,near_stores=near_stores)
示例#3
0
def portal(sid):
    if request.method == 'POST':
        option(request.form, sid)

    print("sid:",sid)
    conn = pg.connect(conn_str)
    cur = conn.cursor()

    if sid=="admin":
        sql = f"SELECT sid,password,sname,sex,major_id,tutor_id,grade FROM students;"
        students = sqlQuery_(sql)
        # students[0] = students[0].replace(' ','')
        ss = []
        for student in students:
            print(student)
            tmp = []
            for item in student:
                if item!= None and isinstance(item,int)==False:
                    tmp.append(item.replace(' ',''))
                else:
                    tmp.append(' ')
            ss.append(tmp)
        # print("00.",ss)
        # print("========================")

        sql = f"SELECT sid,phone,email FROM contacts;"
        cc = sqlQuery_(sql)
        print("cc:",cc)
        res = []
        for c in cc:
            tmp = []
            for item in c:
                if item != None:
                    tmp.append(item.replace(' ',''))
                else:
                    tmp.append(' ');
            res.append(tmp)
        # print("://",res)

        head1 = ["학번","비밀번호","이름","전공","학년","지도교수","성적","edit/delete"]
        head2= ["sid","phone","email","edit/delete"]
        context = [head1,head2]
        return render_template("portal_admin.html", con_data = res, context=context, students=ss)
    else:
        # EDIT LATER
        sql = f"SELECT sid,password,sname,sex,major_id,tutor_id,grade from students WHERE sid=\'{sid}\';"
        line = sqlQuery_(sql)
        print("04.",line)
        line = list(line[0])
        print("\n\nLINE"+line)
        line[0] = line[0].replace(' ','')
        print("line2:",line)

        sql = f"SELECT sid,phone,email FROM contacts WHERE sid=\'{sid}\';"
        cc = sqlQuery_(sql)
        head = ["학번","이름","전공","학년","지도교수"]
        return render_template("portal.html", stu_data = line, con_data = cc, head=head)
示例#4
0
def editPayment(local):
    if request.method=='POST':
        option(request.form, local, "updatePayment")

    sid = request.form.get('sid')
    print("I got sid!!",sid)

    q = sqlQuery_("""SELECT payment FROM customers WHERE local=%s""",(local,))
    payment_list = json.loads(q[0][0])
    # sid =
    return render_template("editPayment.html",local=local,sid=sid,payment_list=payment_list)
示例#5
0
def store(local):
    if request.method == 'POST':
        print("10")
        if request.form.get('tags'):
            option(request.form, local, "edit_tag")
        elif request.form.get('accept'):
            option(request.form, local, "order_accept")
        elif request.form.get('decline'):
            option(request.form, local, "order_decline")
        else:
            print("request!!!!")
            print("before:",request.form.get('before_menu'))
            print("after:",request.form.get('after_menu'))
            option(request.form, local, "edit_store")

    sid = request.args.get('sid') # sid : store num
    print("sid:",sid)
    print("local:",local)

    menues = sqlQuery_("""SELECT menu from menues WHERE sid=%s""",(sid,))
    menu_list = []
    for menu in menues: menu_list.append(menu[0])

    tags = sqlQuery_("""SELECT name from store_tags WHERE sid=%s""",(sid,))

    oids = sqlQuery_("SELECT order_id, status FROM orders WHERE sid = %s",(sid,))
    print(oids)
    # order_list = []
    # for id in oids: order_list.append(id[0])
    # print(order_list)

    if tags:
        res = []
        for t in tags: res.append(t[0])
        return render_template("manage.html",menu_list = menu_list, sid=sid, local=local, tag_list=res, order_list=oids)
    else:
        return render_template("manage.html",menu_list = menu_list, sid=sid, local=local, tag_list=[],order_list=oids)
示例#6
0
def portal(local):
    # if request.method == 'POST':
    #     option(request.form, local, "edit_id")
    if local == 'favicon.ico':
        return ''
    print("hi",local)

    conn = pg.connect(conn_str)
    cur = conn.cursor()

    type = search(local)
    print("type:",type)
    if type=="sellers":
        storeInfo = sqlQuery_("""SELECT * FROM stores WHERE seller_id=(SELECT seller_id FROM sellers S WHERE S.local=%s);""",(local,))
        personInfo = sqlQuery_("""SELECT * FROM sellers WHERE local=%s""",(local,))
        if len(personInfo)>=1:
            tmp = []
            for store in storeInfo:
                tmp.append(list(store))
            rows = [[stores_menu,sellers_menu],tmp,list(personInfo[0])]

        try:
            order_list = sqlQuery_("""SELECT order_id, status FROM orders WHERE sid = (SELECT sid FROM stores WHERE seller_id=(SELECT seller_id FROM sellers WHERE local=%s));""",(local,))[0]
        except IndexError:
            order_list = []
        print("~:",order_list)
        return render_template("portal_s.html", info=rows,order_list=order_list)

    elif type=="deliveries":
        rows = sqlQuery_("""SELECT * FROM deliveries WHERE local=%s""",(local,))[0]
        personInfo = sqlQuery_("""SELECT * FROM sellers WHERE local=%s""",(local,))
        # if len(personInfo)>=1:
        #     rows = [rows,personInfo]

        try:
            orderDelivering = sqlQuery_("""SELECT O.order_id, S.sname, M.menu, O.timestmp, O.status
                FROM orders O, stores S, menues M, basket B, deliveries D
                WHERE D.did = %s AND B.cnt >0
                    AND O.status = 'delivering'
                    AND B.menuid = M.menuid
                    AND O.order_id = B.order_id AND O.sid=S.sid
                    AND D.did=O.did
                ORDER BY O.timestmp DESC;""",(rows[0],))
        except IndexError:
            orderDelivering = []

        print(":::",orderDelivering)
        print("info::",rows)

        return render_template("portal_d.html", info=rows,orderDelivering=orderDelivering)

    elif type=="customers":
        if request.method == 'POST':
            option(request.form, local, "delivery_fin")
            return redirect("/"+local)

        print("customers")
        personInfo = sqlQuery_("SELECT * FROM customers WHERE local=%s",(local,))
        if len(personInfo)>=1:
            rows = [customers_menu,list(personInfo[0])]

        try:
            orderComplete = sqlQuery_("""SELECT O.order_id, S.sname, M.menu, O.payment, O.timestmp
                FROM orders O, stores S, menues M, basket B
                WHERE O.cid = %s AND B.cnt >0
                    AND O.order_id = B.order_id AND B.menuid = M.menuid
                    AND O.sid = S.sid
                    AND O.status = 'completed'
                ORDER BY O.timestmp DESC;""",(rows[1][0],))

        except IndexError:
            orderComplete = []

        print(".:",orderComplete)

        try:
            orderWaiting = sqlQuery_("""SELECT O.order_id, S.sname, M.menu, O.payment, O.timestmp, O.status
                FROM orders O, stores S, menues M, basket B
                WHERE O.cid = %s AND B.cnt >0
                    AND O.status = 'waiting'
                    AND B.menuid = M.menuid
                    AND O.order_id = B.order_id AND O.sid=S.sid
                ORDER BY O.timestmp DESC;""",(rows[1][0],))
        except IndexError:
            orderWaiting = []

        try:
            orderDelivering = sqlQuery_("""SELECT O.order_id, S.sname, M.menu, O.payment, O.timestmp, O.status, D.name
                FROM orders O, stores S, menues M, basket B, deliveries D
                WHERE O.cid = %s AND B.cnt >0
                    AND O.status = 'delivering'
                    AND B.menuid = M.menuid
                    AND O.order_id = B.order_id AND O.sid=S.sid
                    AND D.did=O.did
                ORDER BY O.timestmp DESC;""",(rows[1][0],))
        except IndexError:
            orderDelivering = []

        print("...:",orderWaiting)
        print("//",orderDelivering)

        return render_template("portal_c.html", info=rows,orderComplete=orderComplete,orderWaiting=orderWaiting,orderDelivering=orderDelivering)
    else:
        print("error 06")

    row = []
    return render_template("portal_"+type[0]+".html", info=rows)
示例#7
0
    def get_live(self, room_id):
        """
        api: https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?
        Params:
            room_id=910819
            &protocol=0%2C1
            &format=0%2C2
            &codec=0
            &qn=10000
            &platform=web
            &ptype=16
        """
        api = 'https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo'
        params = {
            'room_id': room_id,
            'protocol': '0,1,2',
            # 'format': '0,1,2',
            'format': '0,1',
            'codec': '0',
            'qn': '10000',
            'platform': 'web',
            'ptype': '16'
        }
        headers = dict(HEADERS)
        headers.update({'Referer': self.url})

        resp = self.request_get(api, params=params, headers=headers)
        resp_json = resp.json()
        data = resp_json['data']
        ctx.upload(
            room_id=room_id,
            live_status=data['live_status'],
            live_time=data['live_time'],
        )

        self.live_room(room_id)

        # 直播状态
        if data['live_status'] == 0:
            # 未开播
            raise ValueError('直播未开。')
        elif data['live_status'] == 1:
            # 已开播
            pass
        playurl_info = data['playurl_info']
        playurl = playurl_info['playurl']
        # streams = playurl['stream']

        options = []
        for stream in playurl['stream']:
            for format in stream['format']:
                format_name = format['format_name']
                for codec in format['codec']:
                    current_qn = codec['current_qn']
                    qn_desc = [
                        qn['desc'] for qn in playurl['g_qn_desc']
                        if qn['qn'] == current_qn
                    ][0]
                    desc = {
                        'format': format_name,
                        'quality': qn_desc,
                        'qn': current_qn,
                    }

                    uris = []
                    for url_info in codec['url_info']:
                        urlpath = codec['base_url'] + url_info['extra']
                        url = urljoin(url_info['host'], urlpath)
                        uris.append(url)

                    options.append(
                        option(stream_download(uris.pop(), headers=headers),
                               descriptions=desc))

        return optional(options)
示例#8
0
    def api_playurl(self, request_params):
        """ api: https://api.bilibili.com/x/player/playurl
        这一接口获得的视频资源属于
        """
        options = []
        headers = dict(HEADERS)
        headers['Referer'] = self.url
        r = dict(dash_params)
        r.update(request_params)
        api_res = self.api_get('https://api.bilibili.com/x/player/playurl?', r)
        data = api_res['data']
        # dash
        dash = data.get('dash')

        if dash:
            # audio 选项
            audio = optional([
                download(uri=audio['base_url'], headers=headers)
                for audio in dash['audio']
            ])
            # v
            time_length = data['timelength'] / 1000
            for v in dash['video']:
                video_dl = download(uri=v['base_url'], headers=headers)
                item_req = ffmpeg.concat_av([video_dl, audio])

                frame_rate = v['frame_rate'].split('/')
                if len(frame_rate) > 1:
                    frame_rate = int(frame_rate[0]) / int(frame_rate[1])
                else:
                    frame_rate = frame_rate[0]
                size = None
                video_desc = {
                    'length': time_length,
                    'size': size,
                    'quality': v['id'],
                    'width': v['width'],
                    'height': v['height'],
                    'frame_rate': frame_rate,
                    'mime_type': v['mime_type'],
                }

                # 发送成功解析到视频的消息,并带上资源信息
                ctx.success(
                    'quality: %s\nresolution: %s x %s\nsize: %s\nurl: %s' %
                    (v['id'], v['width'], v['height'], size, v['base_url']))
                options.append(option(item_req, descriptions=video_desc))
        # durl
        r = dict(durl_params)
        r.update(request_params)
        api_res = self.api_get('https://api.bilibili.com/x/player/playurl?', r)
        durl = api_res.get('data', {}).get('durl')
        if durl:
            for v in durl:
                video_dl = download(uri=v['url'], headers=headers)
                item_req = video_dl
                # 不需要合并操作使用none 方法, 或着接提交下载请求
                ctx.success(
                    'quality: %s\nresolution: %s x %s\nsize: %s\nurl: %s' %
                    (request_params['qn'], 'unknown', 'unknown', v['size'],
                     v['url']))
                options.append(option(item_req, descriptions=v))

        return options