def _set_code(self, force=False): if force or not self.code: shortuuid.set_alphabet("23456789ABCDEFGHJKLMNPQRSTUVWXYZ") code = shortuuid.uuid()[:6] while Location.objects.filter(code=code).count() > 0: code = shortuuid.uuid()[:6] self.code = code
def __init__(self, **kwargs): # logger.debug(u"new Item {kwargs}".format( # kwargs=kwargs)) if "tiid" in kwargs: self.tiid = kwargs["tiid"] else: shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') self.tiid = shortuuid.uuid()[0:24] now = datetime.datetime.utcnow() if "created" in kwargs: self.created = kwargs["created"] else: self.created = now if "last_modified" in kwargs: self.last_modified = kwargs["last_modified"] else: self.last_modified = now if "last_update_run" in kwargs: self.last_update_run = kwargs["last_update_run"] else: self.last_update_run = now super(Item, self).__init__(**kwargs)
def _generate_stripe_id(self, force=False): if force or not self.stripe_id: shortuuid.set_alphabet("23456789ABCDEFGHJKLMNPQRSTUVWXYZ") stripe_id = slugify(self.name) + shortuuid.uuid()[:6] while Plan.objects.filter(stripe_id=stripe_id).count() > 0: stripe_id = slugify(self.name) + "-" + shortuuid.uuid()[:6] return stripe_id
def issue(self, **kwargs): """ Issue a token for sending. :param kwargs: :return: """ shrtn.set_alphabet(settings.SURL_ALPHABET) while True: # the surl must be unique and the likelihood of clash is low, so try again try: self.surl = shrtn.ShortUUID().random( length=settings.TOKEN_SURL_LENGTH) self.save() except IntegrityError: continue else: break self.creator = kwargs["creator"] self.creator_ip = kwargs.get("creator_ip", None) self.novel = kwargs["novel"] self.recipient = kwargs["recipient"] self.is_purchased = kwargs.get("is_purchased", False) self.charge = kwargs.get("charge", None) self.price = kwargs.get("price", Decimal("0.00")) # if purchased, and the creator and recipient are the same, then the person is buying this themselves # (i.e.) not a gift - and the book is being automatically sent... if kwargs["creator"] and kwargs.get( "is_purchased", False) and kwargs["creator"].email == kwargs["recipient"]: self.is_valid = False self.redeemer = kwargs["creator"] self.redeemer_ip = kwargs.get("creator_ip", None) self.redeemed_on = pytz.UTC.localize(datetime.now()) self.save()
def copy(self, **kwargs): """ Provide a deep copy of itself for use in branches https://docs.djangoproject.com/en/1.7/topics/db/queries/#copying-model-instances If new related objects created (other than default), inherit this class. !!!! This is going to need review based on the unique surl attributes. !!!!! !!!! This is NOT tested. !!!!! """ shrtn.set_alphabet(settings.SURL_ALPHABET) while True: # the surl must be unique and the likelihood of clash is low, so try again try: self.surl = shrtn.ShortUUID().random( length=settings.SURL_LENGTH) self.pk = None self.id = None self.save() except IntegrityError: continue else: break self.creator = kwargs.get("creator", self.creator) self.creator_ip = kwargs.get("creator_ip", self.creator_ip) self.save() return self
def save(self, *args, **kwargs): if self._state.adding: shortuuid.set_alphabet( '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ) self.secret = shortuuid.uuid()[:15] super(Session, self).save(*args, **kwargs)
def generate_uid(data: dict) -> str: shortuuid.set_alphabet("23456789abcdefghijkmnopqrstuvwxyz") uid = '' try: uid = slugify(data['blocks'][0]['data']['text'], max_length=64) except: pass return uid + ('-' if uid else '') + shortuuid.uuid()
def __init__(self, **kwargs): if not "refset_id" in kwargs: shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') self.refset_id = shortuuid.uuid()[0:24] if not "created" in kwargs: self.created = datetime.datetime.utcnow() super(ReferenceSetList, self).__init__(**kwargs)
def get_unique_name(name): shortuuid.set_alphabet( "0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") shortuuid.ShortUUID().random(length=16) uid = uuid.uuid5(uuid.NAMESPACE_DNS, name) enc = shortuuid.encode(uid) return enc
def get_short_uuid(length=10): ''' 获取短UUID :return: ''' shortuuid.set_alphabet('1234567890abcdefghijklmnopqrstuvwxyz') if length > 22: # max length is 22 raise ValueError(u'最大长度22') return shortuuid.encode(uuid.uuid1())[:length]
def generate_identifier(self): shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') while True: uuid = shortuuid.uuid()[:8] if not Product.objects.filter(identifier=uuid).exists(): break return uuid
def generate_identifier(self): shortuuid.set_alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890') while True: uuid = shortuuid.uuid()[:8] if not Order.objects.filter(identifier=uuid).exists(): break return uuid
def make(): now = datetime.datetime.utcnow().isoformat() shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') item = {} item["_id"] = shortuuid.uuid()[0:24] item["aliases"] = {} item["biblio"] = {} item["last_modified"] = now item["created"] = now item["type"] = "item" return item
def make(): now = datetime.datetime.utcnow().isoformat() # if the alphabet below changes, need to update couch queue lookups shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') item = {} item["_id"] = shortuuid.uuid()[0:24] item["aliases"] = {} item["biblio"] = {} item["last_modified"] = now item["created"] = now item["type"] = "item" return item
def make(): now = datetime.datetime.now().isoformat() # if the alphabet below changes, need to update couch queue lookups shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') item = {} item["_id"] = shortuuid.uuid()[0:24] item["aliases"] = {} item["biblio"] = {} item["last_modified"] = now item["created"] = now item["type"] = "item" return item
def forwards_func(apps, schema_editor): # We get the model from the versioned app registry; # if we directly import it, it'll be the wrong version Product = apps.get_model('wagtailcommerce_products', 'Product') db_alias = schema_editor.connection.alias for product in Product.objects.using(db_alias).all(): shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') while True: uuid = shortuuid.uuid()[:8] if not Product.objects.filter(identifier=uuid).exists(): break product.identifier = uuid product.save()
def __init__(self, **kwargs): if "tiid" in kwargs: self.tiid = kwargs["tiid"] else: shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') self.tiid = shortuuid.uuid()[0:24] now = datetime.datetime.utcnow() if "created" not in kwargs: self.created = now if "last_modified" not in kwargs: self.last_modified = now if "last_update_run" not in kwargs: self.last_update_run = now super(Product, self).__init__(**kwargs)
def create_app(create_tables: bool = False) -> Flask: """ Create the application and its dependencies. """ shortuuid.set_alphabet(string.ascii_lowercase + string.digits) app = Flask(__name__) configure_app(app) setup_cache(app) setup_app_logging(app) serve_static(app) serve_services(app, cache) setup_db(app, create_all=create_tables) setup_basic_security(app) setup_experiment_execution_schedulers(app) return app
def set(self, **kwargs): shrtn.set_alphabet(settings.SURL_ALPHABET) while True: # the surl must be unique and the likelihood of clash is low, so try again try: self.surl = shrtn.ShortUUID().random(length=settings.SURL_LENGTH) self.save() except IntegrityError: continue else: break self.is_live_from = kwargs.get("is_live_from", pytz.UTC.localize(datetime.now())) self.is_live_to = kwargs.get("is_live_to",None) self.price = kwargs.get("price", "0.00") self.next_wiqi = kwargs.get("next", None) self.previous_wiqi = kwargs.get("previous", None) self.save()
def make(collection_id=None): shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz1234567890') key = shortuuid.uuid()[0:10] if collection_id is None: collection_id = _make_id() now = datetime.datetime.utcnow().isoformat() collection = {} collection["_id"] = collection_id collection["created"] = now collection["last_modified"] = now collection["type"] = "collection" collection["owner"] = None collection["key"] = key # using the hash was needless complexity... return collection, key
def save(self, *args, **kwargs): if not self.uid: uuid = None while not uuid: shortuuid.set_alphabet(SHORTUUID_ALPHABETS_FOR_ID) uuid = shortuuid.uuid()[:10] try: UserAccount.objects.get(uid=uuid) except UserAccount.DoesNotExist: pass else: uuid = None self.uid = uuid models.Model.save(self, *args, **kwargs)
def set(self, **kwargs): shrtn.set_alphabet(settings.SURL_ALPHABET) while True: # the surl must be unique and the likelihood of clash is low, so try again try: self.surl = shrtn.ShortUUID().random( length=settings.SURL_LENGTH) self.save() except IntegrityError: continue else: break self.title = BeautifulSoup(kwargs.get("title", "")[:250]).get_text().strip() self.creator = kwargs["creator"] self.creator_ip = kwargs.get("creator_ip", None) self.licensing = kwargs.get("licensing", "(c)") self.save()
def set(self, **kwargs): shrtn.set_alphabet(settings.SURL_ALPHABET) while True: # the surl must be unique and the likelihood of clash is low, so try again try: self.surl = shrtn.ShortUUID().random( length=settings.SURL_LENGTH) self.save() except IntegrityError: continue else: break self.is_live_from = kwargs.get("is_live_from", pytz.UTC.localize(datetime.now())) self.is_live_to = kwargs.get("is_live_to", None) self.is_private = kwargs.get("is_private", False) self.next_wiqi = kwargs.get("next", None) self.previous_wiqi = kwargs.get("previous", None) self.save()
def set(self, **kwargs): shrtn.set_alphabet(settings.SURL_ALPHABET) while True: # the surl must be unique and the likelihood of clash is low, so try again try: self.surl = shrtn.ShortUUID().random(length=settings.SURL_LENGTH) self.save() except IntegrityError: continue else: break self.title = kwargs["title"] self.creator = kwargs["creator"] self.creator_ip =kwargs.get("creator_ip",None) self.licence = kwargs.get("licence","All Rights Reserved") self.citation = kwargs.get("citation", "") #self.original_creator = kwargs["original_creator"] self.reverted_from = kwargs.get("reverted_from", None) self.wiqi = kwargs["wiqi"] self.save()
def claim_invitation(self, invitation, user, is_default=False): # TODO Create Organization organization = Organization.objects.create( name = invitation.organization_name, slug = invitation.organization_slug, address = invitation.organization_address, country = invitation.organization_country, tel = invitation.organization_tel, contract_type = invitation.organization_contract_type, contract_month_remain = invitation.organization_contract_month_remain, created_by = user, email = invitation.organization_email, ) # TODO Create UserOrganization try: user_organization = UserOrganization.objects.get(user=user, organization=organization) except UserOrganization.DoesNotExist: user_organization = UserOrganization.objects.create(user=user, organization=organization, is_default=is_default) user_organization.is_admin = True user_organization.save() shortuuid.set_alphabet('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ') temp_uuid = shortuuid.uuid()[0:10] while OrganizationInvoice.objects.filter(invoice_code=temp_uuid).exists(): temp_uuid = shortuuid.uuid()[0:10] price = 6.00 if organization.contract_type == Organization.YEARLY_CONTRACT else 7.50 OrganizationInvoice.objects.create( organization = organization, invoice_code = temp_uuid, price = price, total = price, start_date = organization.created.date(), end_date = organization.created.date() + relativedelta(months=+1, days=-1), ) invitation.delete() return user_organization
def set(self, **kwargs): shrtn.set_alphabet(settings.SURL_ALPHABET) while True: # the surl must be unique and the likelihood of clash is low, so try again try: self.surl = shrtn.ShortUUID().random( length=settings.SURL_LENGTH) self.save() except IntegrityError: continue else: break self.title = kwargs["title"] self.creator = kwargs["creator"] self.creator_ip = kwargs.get("creator_ip", None) self.license = kwargs.get("license", "All Rights Reserved") self.citation = kwargs.get("citation", "") #self.original_creator = kwargs["original_creator"] self.reverted_from = kwargs.get("reverted_from", None) self.wiqi = kwargs["wiqi"] self.save()
def create_new_videos_template(videos): template = loader.get_template('email-new-videos.html') content = template.render({ 'videos': videos, 'WEBSITE_URL': settings.WEBSITE_URL[:-1] }) url = 'https://us16.api.mailchimp.com/3.0/templates/' shortuuid.set_alphabet("abcdefghijklmnopqrstuvwxyz0123456789") template_name = 'new-videos-' + str( date.today()) + '-' + shortuuid.uuid()[:4] json_data = {'name': template_name, 'html': content} json_data = json.dumps(json_data) json_data = json_data.encode('utf8') r = requests.post(url, auth=('ILoveBlowjobs', settings.MAILCHIMP_API_KEY), data=json_data) if r.status_code / 100 != 2: mail_admins(subject='problem creating template for auto email', message=str(r.status_code) + " " + str(r.content)) return None r_content = json.loads(r.content) return r_content['id']
def _upload_result(result: TrainOutput, metadata: dict, plugin_metadata: dict): """ Wraps upload procedure into single function for use with cli_spinner. Generates a UUID for the model and uploads all artifacts. Args: result (TrainOutput): TrainOutput object, to be uploaded metadata (dict): metadata associated with this run, to be uploaded plugin_metadata (dict): plugin metadata, used to access architecture of run for naming uploading model Returns: str: uuid assigned to result on upload """ shortuuid.set_alphabet('23456789abcdefghijkmnopqrstuvwxyz') uuid = shortuuid.uuid() model_name = f'{plugin_metadata["architecture"]}_{uuid}.pb' upload_file_to_s3('models', result.model_path, alternate_name=model_name) upload_dict_to_s3_as_json(f'models/metadata_{uuid}', metadata) if result.extra_files != []: for fp in result.extra_files: upload_file_to_s3(f'extras/{uuid}', fp) return uuid
def copy(self, **kwargs): """ Provide a deep copy of itself for use in branches https://docs.djangoproject.com/en/1.7/topics/db/queries/#copying-model-instances If new related objects created (other than default), inherit this class. !!!! This is going to need review based on the unique surl attributes. !!!!! !!!! This is NOT tested. !!!!! """ shrtn.set_alphabet(settings.SURL_ALPHABET) while True: # the surl must be unique and the likelihood of clash is low, so try again try: self.surl = shrtn.ShortUUID().random(length=settings.SURL_LENGTH) self.pk = None self.id = None self.save() except IntegrityError: continue else: break self.creator = kwargs.get("creator", self.creator) self.creator_ip = kwargs.get("creator_ip", self.creator_ip) self.save() return self
def to_representation(self, value): shortuuid.set_alphabet('23456789abcdefghjkmnpqrstuvwxyz') return shortuuid.encode(value.uuid)
def organization_notify_from_paypal(request): print request print 'notify--------------------------' invoice_code = request.POST.get('invoice') invoice = get_object_or_404(OrganizationInvoice, invoice_code=invoice_code) payment_date = request.POST.get('payment_date').rsplit(' ', 1)[0] payment_date = datetime.datetime.strptime(payment_date, '%H:%M:%S %b %d, %Y') OrganizationPaypalPayment.objects.create( invoice = invoice, transaction_id = request.POST.get('txn_id'), amt = request.POST.get('mc_gross'), payment_status = request.POST.get('payment_status'), pending_reason = request.POST.get('pending_reason'), protection_eligibility = request.POST.get('protection_eligibility'), payment_date = payment_date, payer_id = request.POST.get('payer_id'), verify_sign = request.POST.get('verify_sign'), ipn_track_id = request.POST.get('ipn_track_id'), ) x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: ip = x_forwarded_for.split(',')[0] else: ip = request.META.get('REMOTE_ADDR') if request.POST.get('payment_status') == 'Completed' and \ ip == '173.0.82.126' and \ float(request.POST.get('mc_gross', '0')) == invoice.total: if invoice.payment_status != 'PAID': invoice.payment_status = 'PAID' invoice.save() # REDUCE MONTLY REMAIN price_rate = invoice.price organization = invoice.organization if organization.contract_type == Organization.YEARLY_CONTRACT: organization.contract_month_remain -= 1 if organization.contract_month_remain == 1: organization.contract_type = Organization.MONTHLY_CONTRACT price_rate = 7.50 organization.save() # TODO: CREATE NEW INVOICE FOR NEXT MONTH shortuuid.set_alphabet('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ') temp_uuid = shortuuid.uuid()[0:10] while OrganizationInvoice.objects.filter(invoice_code=temp_uuid).exists(): temp_uuid = shortuuid.uuid()[0:10] new_user_count = UserOrganization.objects.filter(organization=organization, is_active=True).count() + UserOrganization.objects.filter(organization=organization, is_active=False, modified__gt=invoice.end_date).count() OrganizationInvoice.objects.create( organization = invoice.organization, invoice_code = temp_uuid, price = price_rate, total = new_user_count * price_rate, start_date = invoice.end_date + relativedelta(days=+1), end_date = invoice.end_date + relativedelta(months=+1), current_people = invoice.new_people, new_people = new_user_count, ) # TODO: SEND RECIEPT EMAIL html_email_body = render_to_string('organization/emails/payment_receipt.html', { 'organization': invoice.organization, 'settings': settings, 'invoice': invoice, }) text_email_body = strip_tags(html_email_body) subject = 'Receipt for %s on Openreader from %s to %s' % (invoice.organization.name, format_abbr_date(invoice.start_date), format_abbr_date(invoice.end_date)) send_to_emails = list(UserOrganization.objects.filter(organization=invoice.organization, is_admin=True).values_list('user__email', flat=True)) if organization.email not in send_to_emails: send_to_emails.append(organization.email) msg = EmailMultiAlternatives( subject, text_email_body, settings.EMAIL_ADDRESS_NO_REPLY, send_to_emails ) msg.attach_alternative(html_email_body, "text/html") try: msg.send() print True except: import sys print sys.exc_info() elif ip == '173.0.82.126': pass # TODO: SAVE ATTEMPT FOR RECURRING SYSTEM # invoice.attempt = invoice.attempt + 1 # invoice.save() # TODO: CHECK LIMIT ATTEMP == 5 return HttpResponse('success')
def assignUniqueID(self): shortuuid.set_alphabet("0123456789") return shortuuid.random(length=10)
#!/usr/bin/python # coding=UTF-8 # # BitCurator Access Webtools (Disk Image Access for the Web) # Copyright (C) 2014 - 2016 # All rights reserved. # # This code is distributed under the terms of the GNU General Public # License, Version 3. See the text file "COPYING" for further details # about the terms of this license. # """Short UUID and SQLAlchemy combined to offer keys for DB tables.""" import shortuuid shortuuid.set_alphabet("ABCDE0123456789") def _new_id(): full = shortuuid.uuid() return full[:10] def unique_id(select_by_id_method): """Generate a new unique id that's truncated to 10 characters.""" id_check = False while id_check is False: generated_id = _new_id() dupe_check = select_by_id_method(generated_id) id_check = dupe_check is None return generated_id
#!/usr/bin/env python # encoding: utf-8 # from app.utils.util import get_time from sqlalchemy.ext.hybrid import hybrid_property from . import db from app.extensions import bcrypt, auth_token from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, SignatureExpired, BadSignature from flask import current_app from app.extensions import auth_basic from flask import g import shortuuid # 使用特定的字符生成uuid shortuuid.set_alphabet("0123456789") tag_article_association_table = db.Table( 'tag_article_association', db.Column('tag_id', db.Integer, db.ForeignKey('article.id')), db.Column('article_id', db.ForeignKey('tag.id'))) class About(db.Model): __tablename__ = "about" id = db.Column(db.Integer, primary_key=True) content = db.Column(db.Text) class Article(db.Model): __tablename__ = "article" id = db.Column(db.Integer, primary_key=True)
# -*- coding: utf-8 -*- import time from datetime import datetime import shortuuid shortuuid.set_alphabet( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890') def gen_id(): return shortuuid.uuid() def dt2ts(dt): return int(time.mktime(dt.timetuple())) def ts2dt(ts): return datetime.fromtimestamp(ts) def now(): return dt2ts(datetime.now()) def parse_value(s): ss = s.split('.') ss[1] += '0' * (8 - len(ss[1])) return int(ss[0]) * 100000000 + int(ss[1])
def generate_pairing_code(): shortuuid.set_alphabet("0123456789ABCDEF") return shortuuid.random(length=6)
def generate(ds_name, tags_list): start_time = time.time() #poses = utils.random_rotations(20) #lightAngle = utils.random_rotations(5) positions = utils.cartesian([0], [1, 2], [3, 4, 5]) #backgrounds = utils.random_rotations(5) offsets = utils.cartesian([0.3, 0.6], [0.5]) poses = [ Euler((math.radians(-45.0), math.radians(-60.0), math.radians(-10)), 'XYZ'), Euler((math.radians(10), math.radians(-50), math.radians(0)), 'XYZ'), Euler((math.radians(-40), math.radians(-30), math.radians(40)), 'XYZ'), Euler((math.radians(-45), math.radians(-30), math.radians(-40)), 'XYZ'), Euler((math.radians(-45), math.radians(-60), math.radians(155)), 'XYZ'), Euler((math.radians(60), math.radians(-20), math.radians(-50)), 'XYZ'), Euler((math.radians(180), math.radians(-60), math.radians(-10)), 'XYZ'), ] backgrounds = [ Euler((math.radians(0), math.radians(0), math.radians(0)), 'XYZ'), Euler((math.radians(60), math.radians(0), math.radians(-40)), 'XYZ'), Euler((math.radians(0), math.radians(-70), math.radians(0)), 'XYZ'), Euler((math.radians(-60), math.radians(-50), math.radians(40)), 'XYZ'), Euler((math.radians(0), math.radians(-50), math.radians(50)), 'XYZ'), Euler((math.radians(0), math.radians(-45), math.radians(0)), 'XYZ'), Euler((math.radians(0), math.radians(0), math.radians(80)), 'XYZ'), Euler((math.radians(100), math.radians(100), math.radians(100)), 'XYZ'), ] poses_extend = [] for pose in poses: poses_extend.append(pose) for _ in range(7): for i in range(0, 3): new_pose = pose.copy() rand = random.randint(-40, 40) while abs(rand) < 10: rand = random.randint(-40, 40) new_pose[i] += math.radians(rand) poses_extend.append(new_pose) seq = ssi.Sequence.exhaustive( background=backgrounds, pose=poses_extend, distance=[30, 35, 40], #position = positions #lighting = lightAngle, offset=offsets) #check if folder exists in render, if not, create folder try: os.mkdir("render/" + ds_name) except Exception: pass data_storage_path = os.getcwd() + "/render/" + ds_name #setting file output stuff output_node = bpy.data.scenes["Render"].node_tree.nodes["File Output"] output_node.base_path = data_storage_path #set black background #bpy.context.scene.world.color = (0,0,0) #remove all animation for obj in bpy.context.scene.objects: obj.animation_data_clear() image_num = 0 shortuuid.set_alphabet('12345678abcdefghijklmnopqrstwxyz') for i, frame in enumerate(seq): frame.setup(bpy.data.objects["Cygnus_Real"], bpy.data.objects["Camera_Real"], bpy.data.objects["Sun"]) frame.setup(bpy.data.objects["Cygnus_MaskID"], bpy.data.objects["Camera_MaskID"], bpy.data.objects["Sun"]) frame.setup(bpy.data.objects["Truth_Data"], bpy.data.objects["Camera_Truth"], bpy.data.objects["Sun"]) bpy.context.scene.frame_set(0) #create name for the current image (unique to that image) name = shortuuid.uuid() output_node.file_slots[0].path = "image_" + str(name) + "#" output_node.file_slots[1].path = "mask_" + str(name) + "#" output_node.file_slots[2].path = "truth_" + str(name) + "#" createCSV(name, ds_name) image_num = i + 1 # render bpy.ops.render.render(scene="Render") #add centroid truth data to json files frame.truth_centroids, deleted = get_xy(name, ds_name) #Tag the pictures frame.tags = tags_list # add metadata to frame frame.sequence_name = ds_name # dump data to json if not deleted: with open( os.path.join(output_node.base_path, "meta_" + str(name) + "0.json"), "w") as f: f.write(frame.dumps()) print("===========================================" + "\r") time_taken = time.time() - start_time print("------Time Taken: %s seconds----------" % (time_taken) + "\r") print("Number of images generated: " + str(image_num) + "\r") print("Total number of files: " + str(image_num * 5) + "\r") print("Average time per image: " + str(time_taken / image_num)) print("Data stored at: " + data_storage_path) bpy.ops.wm.quit_blender()
#!/usr/bin/python # -*- coding: utf-8 -*- """ Created on Tue August 6 09:45:08 2019 @author: Sina Ahmadi ([email protected]) """ import codecs import string import json import os import sys import shortuuid shortuuid.set_alphabet(string.digits) class template: def __init__( self, configuration ): #source_language, target_language, source_script="", target_script=""): self.source_language = configuration["source_language"] self.source_language_code = configuration["source_language_code"] self.source_script = configuration["source_language_script"] self.source_lang_script = self.source_language if configuration["source_language_script"] and configuration[ "source_language_code"]: self.source_lang_script = configuration[ "source_language_code"] + "-" + configuration[ "source_language_script"] self.source_language_url = configuration["source_language_url"] self.target_language = configuration["target_language"]
import random import string import shortuuid shortuuid.set_alphabet(string.ascii_uppercase + string.digits) def get_random_string(length): # 0123456789ABCDEFGHJKLMNPQRSTUVWXYZ return ''.join([random.choice(string.ascii_uppercase + string.digits) for n in range(length)]) def get_uuid(length): return shortuuid.uuid()[:length] def format_url(url): return url
def generate_trade_id_func(): shortuuid.set_alphabet('ANME0123456789') trade_id = shortuuid.uuid()[0:8] return trade_id
from app import Config from app.models import Image import boto3 import os import shutil import shortuuid shortuuid.set_alphabet('abcdefghijklmnopqrstuvwxyz') class ImageService(object): @staticmethod def _generate_upload_filename(filename): filename = filename.lower() name, extension = os.path.splitext(filename) while Image.where('name', '=', filename).count() == 1: uid = shortuuid.uuid()[0:7] filename = "{}-{}.{}".format(name, uid, extension) return filename def __init__(self, bucket_name): self.bucket_name = bucket_name self._client = Config.aws_session().client('s3') self.s3 = Config.aws_session().resource('s3') self.bucket = self.s3.Bucket(self.bucket_name) def upload_image(self, filename, stream): upload_filename = self._generate_upload_filename(filename)
from scrapy import Spider, Request from scrapy.http import FormRequest from scrapy.spiders import Rule, CrawlSpider from scrapy.linkextractors import LinkExtractor from bs4 import BeautifulSoup from BrotherWatching.items import BrotherwatchingItem from HTMLParser import HTMLParser import shortuuid import json import time import re import datetime import uuid from urllib import urlencode shortuuid.set_alphabet('0123456789'.encode('utf-8')) def rid(item): '''考虑到数据量并不大,去重操作在数据库完成,即: 对每个评论生成md5值,并进行压缩作为rid列。插入时发生键冲突则忽略''' uid = uuid.uuid3(uuid.NAMESPACE_X500, (item['body'] if item['body']else '0' + item['author'] + item['review_url'] + item[ 'review_time']).encode('utf-8')) return shortuuid.encode(uid)[:18] def timestamp(): # 给jquery请求使用 return str('%d' % (time.time() * 1000))
def filter(self, qs, value): if value: shortuuid.set_alphabet('23456789abcdefghjkmnpqrstuvwxyz') value = shortuuid.decode(value) return super(ObjectIDFilter, self).filter(qs, value)