Exemplo n.º 1
0
def predict():

    data = {'Success': False}

    if request.files.get('image'):

        now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))

        image = request.files['image'].read()
        image = Image.open(io.BytesIO(image))
        image = image_transform(InputSize)(image).numpy()
        # 将数组以C语言存储顺序存储
        image = image.copy(order="C")
        # 生成图像ID
        k = str(uuid.uuid4())
        d = {"id": k, "image": base64_encode_image(image)}
        # print(d)
        db.rpush(ImageQueue, json.dumps(d))
        # 运行服务
        while True:
            # 获取输出结果
            output = db.get(k)
            # print(output)
            if output is not None:
                output = output.decode("utf-8")
                data["predictions"] = json.loads(output)
                db.delete(k)
                break
            time.sleep(ClientSleep)
        data["success"] = True
    return jsonify(data)
Exemplo n.º 2
0
def deleteReminder(id):
    try:
        deleteid=db.delete('reminder', where='reminderid=$id',vars=locals())
    except:
        t.rollback()
        raise
    else:
        t.commit()
        return deleteid
Exemplo n.º 3
0
 async def set_invite(self, ctx, link: str = None):
     if not link:
         await ctx.send(loc.get(ctx, mn, "config_invite").format(db.read("settings", 0, "invite")
                                                                 or inv_d + str(ctx.me.id)))
         return
     if link == "default":
         db.delete("settings", 0, "invite")
     elif link == "off":
         db.write("settings", 0, "invite", "off")
         await ctx.send(loc.get(ctx, mn, "config_invite_disabled"))
         return
     else:
         if not link.startswith("https://"):
             await ctx.send(loc.get(ctx, mn, "config_invite_invalid"))
             return
         db.write("settings", 0, "invite", link)
     await ctx.send(loc.get(ctx, mn, "config_invite_set").format(db.read("settings", 0, "invite")
                                                                 or inv_d + str(ctx.me.id)))
Exemplo n.º 4
0
def deleteEvent(id):
    try:
        deleteid = db.delete('event',
                             where='eventid=$eventid',
                             vars={'eventid': id})
    except:
        t.rollback()
        raise
    else:
        t.commit()
        return deleteid
 def delete_leisure(key):
     db.delete(UserLeisure.entry, key)
     return 'Data deleted.'
Exemplo n.º 6
0
 def delete_rating(key):
     db.delete(Rating.entry, key)
     return 'Data deleted.'
Exemplo n.º 7
0
 def delete_graffiti(key):
     db.delete(Graffiti.entry, key)
     return 'Data deleted.'
Exemplo n.º 8
0
             card_number = input("Card Number: ")
         username = card_number
         password = generate_random_string()
         birthday = date_input("Birthday (yyyy-mm-dd): ")
         try:
             User(name=name,
                  username=username,
                  password=hash256(password),
                  birthday=birthday,
                  card_number=card_number).save()
         except IntegrityError as e:
             print("Username or Card Number is duplicated")
     elif selection == 2:
         display_list(of=User)
     else:
         delete(what=User, by=User.id == int(input("User ID: ")))
 elif selection == 2:
     selection = crud_menu("book")
     clear_screen()
     if selection == 1:
         name = input("Name: ")
         authors = []
         while True:
             try:
                 author_id = int(input("Author ID: "))
                 authors.append(Author.find(by=Author.id == author_id))
                 more = input("Continue? (y/n) ")
                 while more != "y" and more != "n":
                     more = input("Continue? (y/n) ")
                 if more == "n":
                     break
    def delete(self, plan_name):
        args = parser.parse(CourseInPlanSchema, request)

        # Get the plan_id
        try:
            plan_id = _get_plan_id(plan_name, args["term"])
            if plan_id == -1:
                return (
                    {
                        "message": msg.not_found("Plan",
                                                 (plan_name, args["term"]))
                    },
                    404,
                )
        except:
            traceback.print_exc()
            return {"message": msg.internal_server("retrieve", "Plan")}, 500

        # Get the course
        try:
            course = db.find_by(CourseModel,
                                term=args["term"],
                                code=args["course_code"]).first()
        except:
            traceback.print_exc()
            return {"message": msg.internal_server("retrieve", "Course")}, 500

        # Return 404 if no course was found
        if not course:
            return (
                {
                    "message":
                    msg.not_found("Course",
                                  (args["term"], args["course_code"]))
                },
                404,
            )

        # Find the CourseInPlan
        try:
            course_in_plan = db.find_by(CourseInPlanModel,
                                        plan_id=plan_id,
                                        course_id=course._id).first()
        except:
            traceback.print_exc()
            return (
                {
                    "message": msg.not_found("CourseInPlan",
                                             (plan_id, course._id))
                },
                404,
            )

        # Delete it
        try:
            db.delete(course_in_plan)
        except:
            traceback.print_exc()
            return {
                "message": msg.internal_server("delete", "CourseInPlan")
            }, 500

        return {"message": msg.success("CourseInPlan", "deleted")}
Exemplo n.º 10
0
 def delete_like(key, uid):
     db.delete(Like.entry + '/' + key, uid)
Exemplo n.º 11
0
    def admin(self, update, content):
        try:
            chat_id = update.message.chat_id
            message_id = update.message.message_id
            command = group_id = admin = channel_name = plan = expire = None
            if content.args:
                self.updater.bot.send_chat_action(
                    chat_id=chat_id, action=telegram.ChatAction.TYPING)
                command = content.args[0]
                if command == "add":
                    group_id, admin, channel_name, plan, expire = content.args[
                        1:]
                    if not db.find('channel', name=channel_name):
                        channel = db.Channel(
                            name=channel_name,
                            admin=int(admin),
                            group_id=int(group_id),
                            plan=int(plan),
                            expire=timedelta(days=int(expire)))
                        db.add(channel)
                        self.updater.bot.send_message(
                            chat_id=chat_id,
                            reply_to_message_id=message_id,
                            text="ثبت شد \n\n{}".format(channel.__str__()))
                elif command == "ren":
                    channel_name, expire = content.args[1:]
                    if db.find("channel", name=channel_name):
                        channel = db.find("channel", name=channel_name)
                        channel.expire += timedelta(days=int(expire))
                        db.update(channel)
                        self.updater.bot.send_message(
                            chat_id=chat_id,
                            reply_to_message_id=message_id,
                            text="ثبت شد \n\n{}".format(channel.__str__()))
                elif command == "plan":
                    channel_name, plan = content.args[1:]
                    channel = db.find("channel", name=channel_name)
                    channel.plan = int(plan)
                    db.update(channel)
                    self.updater.bot.send_message(
                        chat_id=chat_id,
                        reply_to_message_id=message_id,
                        text="ثبت شد \n\n{}".format(channel.__str__()))
                elif command == "del":
                    channel_name = content.args[1]
                    channel = db.find("channel", name=channel_name)
                    if channel:
                        db.delete(channel)
                elif command == "edit":
                    channel_name, n_channel_name = content.args[1:]
                    channel = db.find("channel", name=channel_name)
                    if channel:
                        channel.name = n_channel_name
                        db.update(channel)
                        self.updater.bot.send_message(
                            chat_id=chat_id,
                            reply_to_message_id=message_id,
                            text="ثبت شد \n\n{}".format(channel.__str__()))
                elif command == "lst":
                    channels = db.find('channel')
                    text = "channel          expire_date\n"
                    for ch in channels:
                        expire = JalaliDatetime().from_date(ch.expire)
                        now = JalaliDatetime().now()
                        diff = expire - now
                        if diff.days < 7:
                            text += "{} {} 🔴\n\n".format(
                                ch.name, expire.strftime("%A %d %B"))
                        else:
                            text += "{} {} ⚪️\n\n".format(
                                ch.name, expire.strftime("%A %d %B"))

                    self.updater.bot.send_message(chat_id=cna, text=text)
                elif command == "det":
                    channel_name, = content.args[1:]
                    channel = db.find("channel", name=channel_name)
                    if isinstance(channel, db.Channel):
                        self.updater.bot.send_message(
                            chat_id=chat_id,
                            reply_to_message_id=message_id,
                            text=strings.status(channel,
                                                util.remain(channel),
                                                button=False))
                elif command == "db":
                    # db
                    self.updater.bot.send_document(chat_id=cna,
                                                   document=open(
                                                       "bot_db.db", "rb"),
                                                   timeout=time_out)
                else:
                    self.updater.bot.send_message(
                        chat_id=chat_id,
                        reply_to_message_id=message_id,
                        text="command {} not found".format(content.args[0]))

            else:
                self.updater.bot.send_message(chat_id=chat_id,
                                              text=strings.admin_hint)
        except Exception as E:
            logging.error("admin: {}".format(E))