示例#1
0
    def get(self):

        formato_fecha = "%Y-%m-%d"
        times = time.strftime(formato_fecha)
        producto = [x.json() for x in ProductModel.find_all()]
        fechas = [x['fecha_vencimiento'] for x in producto]

        variable = [x for x in fechas]
        ss = datetime.strptime(variable[0], formato_fecha)
        sd = datetime.strptime(times, formato_fecha)
        aa = ss - sd
        print("ssss: {}".format(aa.days))
        listaaa = []
        for s in fechas:
            aa = datetime.strptime(s, formato_fecha) - datetime.strptime(
                times, formato_fecha)
            aaa = [t for t in s if aa.days < 20]
            hh = "".join(aaa)
            if hh:
                data = ProductModel.find_by_date(hh)
                #print("kenyyy: {}".format(data.json()))
                print("aaaa: {}".format(data))
                listaaa.append(data.json())
                #return {"Productos por vencer": data.json()}

            #for n in aaa:
            #    print("xdddd: {}".format(n))
            #print("fechasssss:  {}".format(aa.days))
            #if aa.days < 20:
            #    print("it is True")
            #    aaa = [s for s in fechas if aa.days < 20]
            #    print("asdasd: {}".format(aaa))
        # else:
        #    print("you are nob")
        return {'productos': listaaa}
示例#2
0
 def get(self):
     times = time.strftime("%Y-%m-%d")
     producto = [x.json() for x in ProductModel.find_all()]
     #ss = producto[0]a
     #productoend = [prduct['fecha_vencimiento'] for prduct in producto]
     aa = [produs['fecha_vencimiento']
           for produs in producto]  #if str(produs)==str(times)]
     #print("ssssssssssssssssss: {} and {}---------- {}".format(times, ss, aa))
     #if times == productoend:
     varialbe = [x for x in aa if x <= times]
     #query = ProductModel.find_by_date(str(varialbe))
     #ss = [y.json() for y in ProductModel.find_by_date(times)]
     a = []
     for i in varialbe:
         #print("ttt: {}".format(i))
         #ss = [y.json() for y in ProductModel.find_by_date(i)]
         tt = ProductModel.find_by_date(i)
         a.append(tt.json())
     return {"productos": a}