예제 #1
0
 def create_meeting(
     self,
     topic: str,
     *,
     start_time: str,
     duration_min: int,
     timezone: str = None,
     type_: int = 2,
     password: str = None,
     settings: schemas.ZoomMeetingSettings = None,
 ) -> schemas.ZoomMeeting:
     endpoint = f"/users/me/meetings"
     body = {
         "topic":
         topic,
         "type":
         type_,
         "start_time":
         start_time,
         "duration":
         duration_min,
         "timezone":
         timezone or self.timezone,
         "password":
         password or shortuuid.random(6),
         "settings":
         settings.dict() if settings else
         schemas.ZoomMeetingSettings.default_settings().dict(),
     }
     response = self._client.post(endpoint, body=body)
     return schemas.ZoomMeeting(**response.json())
예제 #2
0
 def save_prescription_image(self, image):
     save_path = os.path.join(settings.MEDIA_ROOT, self.PRESCRIPTIONS_DIR_NAME, str(self.pk))
     os.makedirs(save_path, exist_ok=True)
     image_extension = image.name[image.name.rindex('.'):]
     file_path = os.path.join(save_path, shortuuid.random(length=10) + image_extension)
     with open(file_path, 'wb+') as destination:
         for chunk in image.chunks():
             destination.write(chunk)
예제 #3
0
파일: room.py 프로젝트: barthap/ChatRooms
 def __init__(self, name: str, description: str = '', is_permament=False):
   self.id = shortuuid.random(length=8)
   self.name = name
   self.description = description
   self.is_permament=is_permament
   self.meta = {
     'created_at': int(datetime.now().timestamp())
   }
예제 #4
0
파일: tictac.py 프로젝트: m-kypr/TOE
def gid():
    import shortuuid
    while True:
        gameId = shortuuid.random(length=UUID_LENGTH).upper()
        if gameId not in [x[1] for x in GAME_IDS]:
            GAME_IDS.append([time.time(), gameId])
            PACKET_BUFFER[gameId] = []
            return gameId
예제 #5
0
파일: shrt.py 프로젝트: Daste745/shrt
def index():
    form = RegisterUrlForm(request.form)

    if request.method == "POST" and form.validate():
        if not (key := form.key.data):
            key = shortuuid.random(8)

        if used := Redirect.query.filter(Redirect.key == key).first():
            flash((f"is already in use", used.url, key), "error")
예제 #6
0
def handle_new_file(url, name, relative_path, extension, instance_name, account_key):
    # create id's for this file

    unique_id = uuid.uuid4().hex
    partition_key = shortuuid.random(length=3)
    short_id = partition_key + '-' + shortuuid.random(length=7)

    print "Unique ids: unique_id: {}, partition_key: {}, short_id: {}".format(unique_id, partition_key, short_id)

    # create orphan record in case the ingestion process breaks
    # the orphan record will be used to clean up any stray data in case we cannot
    # complete the process and get left in-between

    # TODO: lookup orphan message, clean up, and take protective action
    # we must treat the file as a generic file and mark it invalid
    # to avoid processing it over and over again

    create_orphan_record(url, unique_id, partition_key, short_id, instance_name, account_key)


    # TODO: manage rest of process based on extension
    # TODO: use identify -verbose <fn> to get info on file and validate
    # TODO: extract exif and xmp metadata

    tempFileName = download_blob(url, account_key)

    try:
        if extension == "jpg" or extension == "jpeg":
            handle_jpeg_image(url, unique_id, partition_key, short_id, tempFileName, name, extension, relative_path, instance_name, account_key)
        else:
            print "Don't recognize extension, handling as generic file"
            handle_generic_file(url, unique_id, partition_key, short_id, tempFileName, name, extension, relative_path, instance_name, account_key)
    except FileTypeValidationException as ftvex:
        # TODO: Mark file as invalid in table, alt treat as generic file type
        pass
    finally:
        if not debugMode and tempFileName is not None:
            os.remove(tempFileName)

    # we're done, clean up the orphan tracking record

    delete_orphan_record(partition_key, short_id, instance_name, account_key)
예제 #7
0
def broadcast_room_left(user: User, room: str):
  """
  Broadcasts to room that user has left 
  """
  msg = {
    'id': shortuuid.random(length=10),
    'type': MSG_TYPE_USER_LEFT,
    'user': user.to_dict(),
    'timestamp': now()
  }
  emit('chat_message', msg, to=room)
예제 #8
0
파일: models.py 프로젝트: dtm1976/shorturl
def generate_shorturl(suffix_length=8):
    """
    generating suffix of short url
    :param suffix_length:
    :return: full path reference
    """

    # for production
    # short_url = url_for('index', _external=True) + \
    #             shortuuid.random(length=suffix_length)
    short_url = PROTOCOL + SERVER + '/' + \
                shortuuid.random(length=suffix_length)
    return short_url
예제 #9
0
 def __init__(self):
     self.contacts = []
     people = service_configs.get_config("contacts")
     for person in people:
         self.contacts.append(
             Contact(
                 name=person['name'],
                 image=person.get('image', ''),
                 key=shortuuid.random(),
                 service_names={
                     service: names
                     for service, names in person['services'].items()
                 },
             ))
예제 #10
0
    def on_send_message(self, data):
        sid = request.sid
        sender = self.sessions[sid]

        content = data['content'] if 'content' in data else None
        url = data['url'] if 'url' in data else None

        # decorate message content with metadata
        data['id'] = shortuuid.random(length=10)
        data['sender'] = sender.to_dict()
        data['type'] = MSG_TYPE_DEFAULT
        data['timestamp'] = now()

        msg_value = content if content else 'url: ' + url
        log.debug(f'[{sender} -> {sender.current_room}]: {msg_value}')
        emit('chat_message', data, to=sender.current_room.id)
예제 #11
0
    def Save(self, data):
        model = Control()
        model.Id = data['Id']
        model.Name = data['Name']

        tasksToBeDeleted = set(model.Tasks.all())
        taskList = data['Tasks']
        for taskDict in taskList:
            task = self.__taskRepo.Save(taskDict)
            model.Tasks.add(task.Id)
            if task in tasksToBeDeleted:
                tasksToBeDeleted.remove(task)
        self.DisassociteTask(model, tasksToBeDeleted)

        conditionsToBeDeleted = set(model.Conditions.all())
        conditionList = data['Conditions']
        for conditionDict in conditionList:
            condition = self.__conditionRepo.Save(conditionDict)
            model.Conditions.add(condition.Id)
            if condition in conditionsToBeDeleted:
                conditionsToBeDeleted.remove(condition)
        self.DisassociteCondition(model, conditionsToBeDeleted)

        control = self.Get(model.Id)
        status = self.Status(model, control)

        if status is ModelStatus.New:
            model.Id = shortuuid.random(10)
            model.save()
            print(u"{0} is Created".format(model))

        elif status is ModelStatus.Modified:
            model.save()
            print(u"{0} is Updated".format(model))

        return model
예제 #12
0
파일: user.py 프로젝트: barthap/ChatRooms
 def __init__(self, name: str, session_id: str = None):
     self.id = shortuuid.random(length=8)
     self.name = name
     self.session_id = session_id
     self.current_room: Room = None
     self.meta = {'created_at': int(datetime.now().timestamp())}
예제 #13
0
 def assignUniqueID(self):
     shortuuid.set_alphabet("0123456789")
     return shortuuid.random(length=10)
예제 #14
0
def random_string(length=10):
    return shortuuid.random(length)
예제 #15
0
import service_configs
import shortuuid


@attr.s()
class Contact(object):
    name = attr.ib()
    service_names = attr.ib()
    key = attr.ib()
    image = attr.ib(default='')

    def to_dict(self):
        return {'name': self.name, 'image': self.image, 'key': self.key}


UNKNOWN = Contact(name="Unknown", service_names={}, key=shortuuid.random())


class ContactProvider():
    def __init__(self):
        self.contacts = []
        people = service_configs.get_config("contacts")
        for person in people:
            self.contacts.append(
                Contact(
                    name=person['name'],
                    image=person.get('image', ''),
                    key=shortuuid.random(),
                    service_names={
                        service: names
                        for service, names in person['services'].items()
예제 #16
0
파일: views.py 프로젝트: Eyu-Tes/pharmaline
def get_user_session_cookie(request):
    try:
        user_session = request.COOKIES['user_session']
    except KeyError:
        user_session = shortuuid.random(length=30)
    return user_session
예제 #17
0
    async def post(request: Request):
        """
        上传app, format[安装包-package: file, 更新说明(默认为空)-msg: str]
        :param request:
        :return:
        """
        file = request.files.get('package')
        update_msg = request.form.get('msg') or ''
        if not file:
            log.warning('not upload file')
            raise BadRequest('not find file')

        session = Session()
        while 1:
            # 安装包id
            fid = uuid('{}-{}'.format(id(Request), time.time()), 16)
            if not session.query(AppVersionModel).filter_by(id=fid).count():
                break
        file_name = '{}.{}'.format(fid, file.name[file.name.rfind('.') + 1:])
        file_path = '{}/{}'.format(Config.app_dir, file_name)

        # 保存安装包
        async with aiofiles.open(file_path, 'wb+') as f:
            await f.write(file.body)
            log.debug('save upload success: {}'.format(file_path))

        package = await PackageParse.parse(file_path)
        if not package:
            os.remove(file_path)
            raise BadRequest('the file is not support')

        app_query = session.query(AppModel).filter_by(
            package_name=package.package_name, type=package.app_type)
        if app_query.count():  # 已存在
            app = app_query.one()
        else:  # 不存在
            # 生成短链
            while 1:
                short_chain = random(8)
                if not session.query(AppModel).filter_by(
                        short_chain_uri_=short_chain).count():
                    break

            app_uuid = uuid(
                '+_{}-{}_+'.format(package.app_type, package.package_name), 16)
            icon_name = '{}.{}'.format(
                app_uuid, package.icon_path[package.icon_path.rfind('.') + 1:])
            app = AppModel(type=package.app_type,
                           short_chain_uri_=short_chain,
                           detail='',
                           name=package.app_name,
                           package_name=package.package_name,
                           icon_='{}/{}'.format(Config.icon_dir, icon_name),
                           icon_uri_='{}/{}'.format(Config.static_icon,
                                                    icon_name))
            session.add(app)
            session.commit()

        # 保存图标
        await package.save_icon(app.icon_)

        file_byte = os.path.getsize(file_path)
        file_size = Byte.pretty(file_byte)

        app_version = AppVersionModel(
            id=fid,
            version_name=package.version_name,
            version_code=package.version_code,
            update_msg=update_msg,
            size=file_size,
            package_='{}/{}'.format(Config.app_dir, file_name),
            package_uri_='{}/{}'.format(Config.static_app, file_name),
            app_id=app.id)
        session.add(app_version)
        session.commit()

        return JsonResult.ok().response_json()
예제 #18
0
def generate_pairing_code():
    shortuuid.set_alphabet("0123456789ABCDEF")
    return shortuuid.random(length=6)
예제 #19
0
def generate_pairing_code():
    shortuuid.set_alphabet("0123456789ABCDEF")
    return shortuuid.random(length=6)