def get_args(): parser = ArgumentParser() parser.add_argument( '-a', '--admin', type=int, default=None, help='Give user specified with -u admin privileges: 0' + ' - none, 1 - read-only, 2 - read-write') parser.add_argument('-l', '--list', action='store_true', help='List users') parser.add_argument('-u', '--username', help='Username of user to act on') parser.add_argument('-i', '--user-id', type=int, help='ID of user') parser.add_argument('--approve', action='store_true', help='Approve story access') parser.add_argument('--remove', action='store_true', help='Remove story access') parser.add_argument('-s', '--story', action='store_true', help='Generate lorem ipsum story') parser.add_argument('-c', '--chapters', type=int, default=5, help='Number of chapters to generate') parser.add_argument('-t', '--title', default=lipsum.generate_words(1), help='Story title') return parser.parse_args()
def createPosts(postsPerUser=5): users = User.query.all() for user in users: for i in range(postsPerUser): bodyLen = random.randint(4, 81) bodyText = lipsum.generate_words(bodyLen) p = Post(user_id=user.id, body=bodyText) db.session.add(p) db.session.commit()
def createComments(commentsPerUser=5): users = User.query.all() posts = Post.query.all() for user in users: for i in range(commentsPerUser): bodylen = random.randint(0, 23) body = lipsum.generate_words(bodylen) post = random.choice(posts) user.create_comment(post, body) db.session.commit()
def get_entry(self): entry = {} entry['title'] = lipsum.generate_words(randint(1, 8)).title().replace( "'", "\\'") entry['uri'] = self.generate_uri(entry['title']) entry['content'] = lipsum.generate_sentences(randint(4, 12)).replace( "'", "\\'") entry['year'] = str(randint(2008, 2018)) entry['month'] = str(randint(1, 12)) entry['day'] = str(randint(1, 28)) return entry
def generate_qar_data(n, d): # Generate questions, answers and ratings output = [] for i in range(1, n + 1): question = { 'model' : 'cheapiesgr.question', 'pk' : i, 'fields' : { 'question_text' : lipsum.generate_words(20), 'registration' : i } } answer = { 'model' : 'cheapiesgr.answer', 'pk' : i, 'fields' : { 'answer_text' : lipsum.generate_words(20), 'question' : i } } rating = { 'model' : 'cheapiesgr.rating', 'pk' : i, 'fields' : { 'rate_explanation' : lipsum.generate_words(20), 'registration' : i, 'volunteer' : i, 'stars' : random.randint(1, 5), 'validity_of_this_rate' : random.randint(1, 5) } } output.extend([question, answer, rating]) return output
def add_to_db(self): """ Add story and chapters to database :rtype: bool """ wuxia_db = Database() story = add_story_to_db(wuxia_db, title=self.title, author=lipsum.generate_words(1)) if not story: print('Story {} could not be added to database using {}.'.format( self.title, self.filepath)) return False else: add_chapters_to_db(wuxia_db, self.filepath, story['id'], 'div.chapter', 'div.chapter > h2.chapter-heading') return True
def create_content(db, id, name): password = '******' c = db.cursor() username = '******' % (name.lower()[0], name.lower()[name.index(' ') + 1:]) email = '*****@*****.**' % ( (name.lower()[0], name.lower()[name.index(' ') + 1:])) c.execute( 'INSERT INTO USERS (userid, username, password, email, confirmed) VALUES (?,?,?,?, ?)', (id, username, password, email, 1)) date = datetime.datetime.now() - datetime.timedelta(28) for i in range(random.randrange(4, 8)): content = lipsum.generate_paragraphs(random.randrange(2, 6)) title = lipsum.generate_words(8) date = date + datetime.timedelta(random.randrange(1, 3), minutes=random.randrange(1, 120), hours=random.randrange(0, 6)) c.execute( 'INSERT INTO posts (creator,date,title,content) VALUES (?,?,?,?)', (id, date.timestamp(), title, content))
def makePt(cols=5, n=1, z=1): return { 'puid': tf.getUUID(), 'name': re.sub(r'[,\.\?!]', r'', lipsum.generate_words(2)), 'notes': [makeNotes(n, z) for x in range(cols)] }
import random SCHEMA_REGISTRY_URL = 'http://172.17.0.5:8081' BOOTSTRAP_SERVERS = '172.17.0.4' AVSC_DIR = os.path.dirname(os.path.realpath(__file__)) KEY_SCHEMA = avro.load(os.path.join(AVSC_DIR, 'primitive_string.avsc')) VALUE_SCHEMA = avro.load(os.path.join(AVSC_DIR, 'basic_schema.avsc')) TOPIC = 'avrotopic' KEY = "mykey" avroProducer = AvroProducer({'bootstrap.servers': BOOTSTRAP_SERVERS, 'schema.registry.url': SCHEMA_REGISTRY_URL}, default_key_schema=KEY_SCHEMA, default_value_schema=VALUE_SCHEMA) for i in xrange(100): value = {"name": generate_words(count=1), "surname": generate_words(count=2), "number": random.randint(0, 100)} print str(value) avroProducer.produce(topic=TOPIC, value=value, key=KEY) avroProducer.flush()
def createUsers(): names = [ 'Abigail', 'Alice', 'Amber', 'Amelia', 'Amy', 'Ava', 'Brooke', 'Caitlin', 'Charlotte', 'Chloe', 'Daisy', 'Elizabeth', 'Ella', 'Ellie', 'Emily', 'Emma', 'Erin', 'Eva', 'Evie', 'Freya', 'Grace', 'Hannah', 'Holly', 'Imogen', 'Isabel', 'Isabella', 'Isabelle', 'Isla', 'Jasmine', 'Jessica', 'Katie', 'Keira', 'Leah', 'Lilly', 'Lily', 'Lola', 'Lucy', 'Matilda', 'Megan', 'Mia', 'Millie', 'Molly', 'Olivia', 'Phoebe', 'Poppy', 'Ruby', 'Scarlett', 'Sophia', 'Sophie', 'Summer', 'Adam', 'Alex', 'Alexander', 'Alfie', 'Archie', 'Benjamin', 'Callum', 'Cameron', 'Charlie', 'Connor', 'Daniel', 'Dylan', 'Edward', 'Ethan', 'Finley', 'George', 'Harrison', 'Harry', 'Harvey', 'Henry', 'Isaac', 'Jack', 'Jacob', 'Jake', 'James', 'Jayden', 'Joseph', 'Joshua', 'Leo', 'Lewis', 'Liam', 'Logan', 'Lucas', 'Luke', 'Matthew', 'Max', 'Mohammed', 'Muhammad', 'Nathan', 'Noah', 'Oliver', 'Oscar', 'Owen', 'Rhys', 'Riley', 'Ryan', 'Samuel', 'Thomas', 'Tyler', 'William', ] for name in names: u = User() if User.query.filter_by(username=name).first(): u.username = name + str(random.randint(0, 99)) else: u.username = name u.email = u.username.lower() + '@luther.edu' u.avatar = random.choice(['helmet.png', 'axe.png', 'ship.png']) u.set_password('password') aboutlen = random.randint(0, 23) aboutme = lipsum.generate_words(aboutlen) u.about_me = aboutme db.session.add(u) db.session.commit()
def build_sample_db(fast=False): """Populate a db with some example entries.""" # Set a seed to avoid flakiness random.seed(42) # Prevent sending email _send = mail.send mail.send = lambda msg: None db.drop_all() db.create_all() with app.app_context(): lhcb = Experiment(name='LHCb') belle = Experiment(name='Belle') belle_2 = Experiment(name='Belle 2') db.session.add(lhcb) db.session.add(belle) db.session.add(belle_2) db.session.commit() user_role = Role(name='user') super_user_role = Role(name='superuser') db.session.add(user_role) db.session.add(super_user_role) db.session.commit() test_admin = user_datastore.create_user( name='Admin', email='admin', password=encrypt_password('admin'), roles=[user_role, super_user_role], experiment=lhcb ) test_user_lhcb = user_datastore.create_user( name='User', email='userlhcb', password=encrypt_password('user'), roles=[user_role], experiment=lhcb ) test_user_belle = user_datastore.create_user( name='User', email='userbelle', password=encrypt_password('user'), roles=[user_role], experiment=belle ) test_user_belle2 = user_datastore.create_user( name='User', email='userbelle2', password=encrypt_password('user'), roles=[user_role], experiment=belle_2 ) first_names = [ 'Harry', 'Amelia', 'Oliver', 'Jack', 'Isabella', 'Charlie', 'Sophie', 'Mia', 'Jacob', 'Thomas', 'Emily', 'Lily', 'Ava', 'Isla', 'Alfie', 'Olivia', 'Jessica', 'Riley', 'William', 'James', 'Geoffrey', 'Lisa', 'Benjamin', 'Stacey', 'Lucy' ] contacts = [] for i in range(9 if fast else len(first_names)): tmp_experiment = [lhcb, belle, belle_2][i % 3] tmp_email = f'chrisburr73+{first_names[i].lower()}.{tmp_experiment.name}@gmail.com' contacts.append(Contact(email=tmp_email, experiment=tmp_experiment)) db.session.add(contacts[-1]) db.session.commit() lhcb_charm = Category(name='Charm', experiment=lhcb, contacts=contacts[:1]) belle_charm = Category(name='Charm', experiment=belle, contacts=contacts[1:2]) db.session.add(lhcb_charm) db.session.add(belle_charm) db.session.commit() conferences = [] for year in range(2018 if fast else 2000, 2020): conf_time = datetime.now() - timedelta(days=random.randrange(50, 500)) llwi = Conference(name='LLWI '+str(year), venue='Canada', start_date=conf_time) db.session.add(llwi) conf_time = datetime.now() - timedelta(days=random.randrange(50, 500)) morriond = Conference(name='Moriond '+str(year), venue='La Thuile', start_date=conf_time, url=f'http://moriond.in2p3.fr/QCD/{year}/') db.session.add(morriond) conferences.extend([llwi, morriond]) db.session.commit() for conference in conferences: charm_prod = Talk( title='Charm hadron production cross-sections at √s = 13 TeV using 300pb⁻¹', duration=f'{random.randrange(10, 90)}" (+ questions)', speaker=f'chrisburr73+{".".join(random.sample(first_names, 2))}@gmail.com', experiment=lhcb, interesting_to=[belle, belle_2], conference=conference, abstract=lipsum.generate_sentences(10) ) db.session.add(charm_prod) db.session.commit() make_submissions(first_names, conference, charm_prod) talk = Talk( title=lipsum.generate_words(10), duration=f'{random.randrange(10, 90)}"', speaker=f'chrisburr73+{".".join(random.sample(first_names, 2))}@gmail.com', experiment=belle, interesting_to=[lhcb], conference=conference, abstract=lipsum.generate_paragraphs(2) ) db.session.add(talk) db.session.commit() make_submissions(first_names, conference, talk) talk = Talk( title=lipsum.generate_words(10), duration=f'{random.randrange(10, 90)}"', speaker=f'chrisburr73+{".".join(random.sample(first_names, 2))}@gmail.com', experiment=belle_2, interesting_to=[belle], conference=conference, abstract=lipsum.generate_paragraphs(2) ) db.session.add(talk) db.session.commit() make_submissions(first_names, conference, talk) db.session.commit() # Restore mail sending functionality mail.send = _send
ID_START = 9001 ID_STOP = 9026 # Loop to create files # for talk_number in range(ID_START, ID_STOP + 1): for talk_number in TALK_IDS: filename = str(talk_number) + '.yaml' title_words = random.randint(4, 12) abstract_sentences = random.randint(2, 6) details_paras = random.randint(4, 10) # Creating the tag list tag_list = [] tag_list.append(random.choice(tag_mandatory)) random_tags = random.sample(tag_optional, random.randint(0, 2)) tag_list += random_tags context = { 'name': names.get_full_name(), 'title': lipsum.generate_words(title_words), 'abstract': lipsum.generate_sentences(abstract_sentences), 'details': lipsum.generate_paragraphs(details_paras), 'talk_tags': tag_list, } with open(Path(current_folder, filename), 'w') as text_file: text_file.write(template.render(context)) print('Auto-filled [{}]'.format(filename)) print('task completed')
def create_temp_file(): with open(filename, 'x+') as tmp: tmp.write(lipsum.generate_words(200))
SCHEMA_REGISTRY_URL = 'http://172.17.0.5:8081' BOOTSTRAP_SERVERS = '172.17.0.4' AVSC_DIR = os.path.dirname(os.path.realpath(__file__)) KEY_SCHEMA = avro.load(os.path.join(AVSC_DIR, 'primitive_string.avsc')) VALUE_SCHEMA = avro.load(os.path.join(AVSC_DIR, 'basic_schema.avsc')) TOPIC = 'avrotopic' KEY = "mykey" avroProducer = AvroProducer( { 'bootstrap.servers': BOOTSTRAP_SERVERS, 'schema.registry.url': SCHEMA_REGISTRY_URL }, default_key_schema=KEY_SCHEMA, default_value_schema=VALUE_SCHEMA) for i in xrange(100): value = { "name": generate_words(count=1), "surname": generate_words(count=2), "number": random.randint(0, 100) } print str(value) avroProducer.produce(topic=TOPIC, value=value, key=KEY) avroProducer.flush()