示例#1
0
    def generate(self):
        """Generate."""
        size = self.holder.eitems["total"]
        doc_pids = self.holder.pids("documents", "pid")

        objs = [{
            "pid":
            self.create_pid(),
            "document_pid":
            random.choice(doc_pids),
            "description":
            "{}".format(lorem.text()),
            "internal_notes":
            "{}".format(lorem.text()),
            "urls": [
                {
                    "value": "https://home.cern/science/physics/dark-matter",
                    "description": "Dark matter"
                },
                {
                    "value": "https://home.cern/science/physics/antimatter",
                    "description": "Anti matter"
                },
            ],
            "open_access":
            bool(random.getrandbits(1)),
        } for pid in range(1, size + 1)]

        self.holder.eitems["objs"] = objs
示例#2
0
    def generate(self):
        """Generate."""
        size = self.holder.documents['total']
        keyword_pids = self.holder.pids('keywords', "pid")
        series_objs = self.holder.series['objs']
        serial_pids = [
            series["pid"] for series in series_objs
            if series['mode_of_issuance'] == 'SERIAL'
        ]
        multipart_pids = [
            series["pid"] for series in series_objs
            if series['mode_of_issuance'] == 'MULTIPART_MONOGRAPH'
        ]

        def random_series():
            data = []
            if multipart_pids:
                for pid in random.sample(multipart_pids,
                                         randint(0,
                                                 len(multipart_pids) - 1)):
                    data.append(dict(pid=pid, volume=str(randint(1, 100))))
            if serial_pids:
                for pid in random.sample(serial_pids,
                                         randint(0,
                                                 len(serial_pids) - 1)):
                    data.append(dict(pid=pid, volume=str(randint(1, 100))))
            return data

        objs = [{
            "pid":
            str(pid),
            "title":
            "{}".format(lorem.sentence()),
            "authors": ["{}".format(lorem.sentence())],
            "abstracts": ["{}".format(lorem.text())],
            "document_types": [random.choice(self.DOCUMENT_TYPES)],
            "_access": {},
            "languages":
            random.sample(self.LANGUAGES, randint(1, len(self.LANGUAGES))),
            "publishers": ["{}".format(lorem.sentence())],
            "files": [
                "https://cds.cern.ch/record/2255762/"
                "files/CERN-Brochure-2017-002-Eng.pdf",
                "https://cds.cern.ch/record/2256277/"
                "files/CERN-Brochure-2016-005-Eng.pdf"
            ],
            "booklinks": [
                "https://home.cern/science/physics/dark-matter",
                "https://home.cern/science/physics/antimatter"
            ],
            "chapters": ["{}".format(lorem.sentence())],
            "information":
            "{}".format(lorem.text()),
            "keyword_pids":
            random.sample(keyword_pids, randint(0, 5)),
            "series_objs":
            random_series(),
        } for pid in range(1, size + 1)]

        self.holder.documents['objs'] = objs
示例#3
0
    def generate(self):
        """Generate."""
        size = self.holder.items['total']
        iloc_pids = self.holder.pids('internal_locations', "pid")
        doc_pids = self.holder.pids('documents', "pid")
        objs = [{
            "pid":
            str(pid),
            "document_pid":
            random.choice(doc_pids),
            "internal_location_pid":
            random.choice(iloc_pids),
            "legacy_id":
            "{}".format(randint(100000, 999999)),
            "legacy_library_id":
            "{}".format(randint(5, 50)),
            "barcode":
            "{}".format(randint(10000000, 99999999)),
            "shelf":
            "{}".format(lorem.sentence()),
            "description":
            "{}".format(lorem.text()),
            "_internal_notes":
            "{}".format(lorem.text()),
            "medium":
            random.choice(self.ITEM_MEDIUMS),
            "status":
            random.choice(self.ITEM_STATUSES),
            "circulation_restriction":
            random.choice(self.ITEM_CIRCULATION_RESTRICTIONS),
        } for pid in range(1, size + 1)]

        self.holder.items['objs'] = objs
示例#4
0
 def text_generator(self):
     while self.index < self.num_notes:
         text = lorem.text()
         text_len = self.distribution_values[self.index]
         while (len(text) < text_len):
             text = text + " " + lorem.text()
         yield text[0:text_len]
         self.index += 1
示例#5
0
 def generate_document(self, index, **kwargs):
     """Generate document data."""
     publication_year = kwargs.get("publication_year",
                                   str(randint(1700, 2020)))
     imprint = random.choice(self.IMPRINTS)
     obj = {
         "pid":
         self.create_pid(),
         "title":
         lorem.sentence(),
         "authors":
         random.sample(self.AUTHORS, randint(1, 3)),
         "abstract":
         "{}".format(lorem.text()),
         "document_type":
         random.choice(Document.DOCUMENT_TYPES),
         "created_by": {
             "type": "script",
             "value": "demo"
         },
         "languages": [
             lang["key"]
             for lang in random.sample(self.holder.languages, randint(1, 3))
         ],
         "table_of_content": ["{}".format(lorem.sentence())],
         "note":
         "{}".format(lorem.text()),
         "tags": [
             tag["key"] for tag in random.sample(
                 self.holder.tags, randint(1,
                                           len(self.holder.tags) - 1))
         ],
         "edition":
         str(index),
         "keywords": {
             "source": lorem.sentence(),
             "value": lorem.sentence()
         },
         "conference_info":
         self.CONFERENCE_INFO,
         "number_of_pages":
         str(random.randint(0, 300)),
         "imprint": {
             **imprint, "date": "{}-08-02".format(publication_year)
         },
         "publication_year":
         publication_year,
         "urls": [{
             "description": "{}".format(lorem.sentence()),
             "value": "http://random.url"
         }],
         "restricted":
         False,
     }
     obj.update(**kwargs)
     return obj
示例#6
0
def prepare_conversation_data(test_account_id, email, username, pswd,
                              threads_count):
    sample = {
        "host": "smtp.gmail.com",
        "port": 465,
        "username": test_account_id,
        "password": accs[test_account_id][1],
        "subject": text_model.make_sentence(),
        "to": email,
        "from": accs[test_account_id][0],
        "text": text()
    }
    msg_id = send_message(host=sample['host'],
                          port=sample['port'],
                          username=sample['username'],
                          password=sample['password'],
                          subject=sample['subject'],
                          msg_to=sample['to'],
                          msg_from=sample['from'],
                          msg_text=sample['text'])
    sample_reply = {
        "host": "smtp.office365.com",
        "username": username,
        "password": pswd,
        "subject": sample['subject'],
        "to": email,
        "from": accs[test_account_id][0],
        "text": text(),
        'In-Reply-To': msg_id
    }
    for _ in range(threads_count):
        sendReply(host=sample_reply['host'],
                  port=587,
                  username=sample_reply['username'],
                  password=sample_reply['password'],
                  subject=sample_reply['subject'],
                  msg_to=sample_reply['to'],
                  msg_from=sample_reply['from'],
                  msg_text=sample_reply['text'],
                  msg_id=sample_reply['In-Reply-To'])
        time.sleep(10)
        sendReply(host=sample['host'],
                  port=465,
                  username=sample['username'],
                  password=sample['password'],
                  subject=sample['subject'],
                  msg_to=sample['to'],
                  msg_from=sample['from'],
                  msg_text=sample['text'],
                  msg_id=sample_reply['In-Reply-To'])
示例#7
0
 def __init__(self, id: int, subdomain: str):
     self.id = id
     self.subdomain = subdomain
     self.text = lorem.text()
     self.links = set([])
     self.path = self.format_url(self.id)
     self.html = None
示例#8
0
    def on_event(self, event, extension):
        """ Handles event """
        items = []

        items.append(
            ExtensionResultItem(icon='images/icon.png',
                                name="Sentence",
                                highlightable=False,
                                on_enter=CopyToClipboardAction(
                                    lorem.sentence())))

        items.append(
            ExtensionResultItem(icon='images/icon.png',
                                name="Paragraph",
                                highlightable=False,
                                on_enter=CopyToClipboardAction(
                                    lorem.paragraph())))

        items.append(
            ExtensionResultItem(icon='images/icon.png',
                                name="Text",
                                highlightable=False,
                                on_enter=CopyToClipboardAction(lorem.text())))

        return RenderResultListAction(items)
def generate_profiles():
    """generate people profiles using faker, so that it looks like stolen identities"""
    print("generating profiles for " + current_dir + "...")
    with open('names.txt') as fp:
        for cnt, line in enumerate(fp):
            line = line.strip()
            dir = current_dir + "profiles/" + line[0] + "/"
            if not os.path.exists(dir):
                os.makedirs(dir)
            dir += line + "/"
            if not os.path.exists(dir):
                os.makedirs(dir)
            else:
                continue

            chance = random.randint(0, 1)
            if chance > 0:
                continue

            file = open(dir + lorem.sentence().replace(".", "") + ".txt", "w")
            file.write(lorem.text())
            file.close()

            for i in range(random.randint(0, 22)):
                with open(dir + "/%s-%s.bin" % (time.time(), i), "wb") as fout:
                    fout.write(os.urandom(random.randint(1, 2048)))
                    fout.close()
示例#10
0
 def random_serial(self, obj):
     """Randomize serial data."""
     for _ in range(randint(1, 3)):
         obj["identifiers"].append(
             dict(material=random.choice(["ONLINE", "PRINT"]),
                  scheme="ISSN",
                  value=self.random_issn()))
     obj["abbreviated_title"] = obj["title"].split()[0]
     obj["alternative_titles"] = [
         dict(value=obj["title"], type="SUBTITLE"),
         dict(value=obj["title"],
              type="TRANSLATED_TITLE",
              language="FR",
              source="CERN")
     ]
     obj["internal_notes"] = [
         dict(field="title", user="******", value="Internal test note.")
     ]
     obj["notes"] = lorem.text()
     obj["publisher"] = lorem.sentence().split()[0]
     obj["access_urls"] = [
         dict(open_access=True,
              description=lorem.sentence(),
              value="https://home.cern/") for _ in range(1, 3)
     ]
     obj["urls"] = [
         dict(description=lorem.sentence(), value="https://home.cern/")
         for _ in range(1, 3)
     ]
示例#11
0
def _generate_mails(cls, app_id):
    for _ in range(random.randint(10, 20)):
        cls.objects.create(
            subject=f"{app_id} {lorem.sentence()}"[:100],
            text=lorem.text(),
            comment=lorem.sentence(),
        )
示例#12
0
    def generate(self):
        """Generate."""
        size = self.holder.series["total"]
        objs = []
        self.generate_minimal(objs)
        for index in range(1, size + 1):
            moi = random.choice(self.MODE_OF_ISSUANCE)
            authors = random.sample(DocumentGenerator.AUTHORS,
                                    len(DocumentGenerator.AUTHORS))
            obj = {
                "pid":
                self.create_pid(),
                "mode_of_issuance":
                moi,
                "title":
                lorem.sentence(),
                "authors": [author["full_name"] for author in authors],
                "abstract":
                lorem.text(),
                "languages": [
                    lang["key"] for lang in random.sample(
                        self.holder.languages, randint(1, 3))
                ],
                "identifiers": [],
            }
            if moi == "SERIAL":
                self.random_serial(obj)
            elif moi == "MULTIPART_MONOGRAPH":
                self.random_multipart(obj, index)
            objs.append(obj)

        self.holder.series["objs"] = objs
示例#13
0
def size_limit():
    t = lorem.text()

    # this is ~ 12mb of text
    number_of_times = 9000

    str = ''
    for i in range(0, number_of_times):
        str += lorem.text()

    str_size = sys.getsizeof(str)
    print(bytes_to_mb(str_size))

    doc = {'key': str}

    client.insert_one(doc)
    print('inserted')
示例#14
0
 def handle(self, *args, **options):
     pages = []
     for i in range(0, 100):
         pages.append(
             Page(name=lorem.sentence(),
                  slug=uuid.uuid4(),
                  body=lorem.text()))
     Page.objects.bulk_create(pages)
示例#15
0
def create_project(index):
    session.add(
        Project(
            id=index,
            name=f"project{index}",
            display_name=f"Project {index}",
            short_description=sd_lorem.paragraph(),
            long_description=lorem.text(),
        ))
示例#16
0
def create_chapter(lenght):
    chapter = ''
    while True:
        if len(chapter) >= lenght:
            yield chapter[:lenght]
            chapter = ''
        else:
            chapter += lorem.text()
            lenght = random.randint(100, 1000)
示例#17
0
 def replace_file_content(path):
     # Replace the contents of text file
     text = lorem.text()
     file_path = ROOT_FILE_DIR + path
     if not os.path.isfile(file_path):
         abort(404, 'File does not exist.')
     else:
         with open(file_path, 'w') as text_file:
             print(text, file=text_file)
         return f'File contents at {file_path} changed.', 200
    def _uri(self, min_length, max_length):
        """Returns a random URL."""
        words = list(set(lorem.text().lower().replace('.', '').split()))

        scheme = random.choice(['http', 'https'])
        host = random.choice(words)
        tld = random.choice(['com', 'co.uk', 'gov.uk'])
        path = random.choice(words)

        return '{}://{}.{}/{}'.format(scheme, host, tld, path)
示例#19
0
    def generate(self):
        """Generate."""
        size = self.holder.libraries["total"]
        objs = [{
            "pid": self.create_pid(),
            "name": lorem.sentence(),
            "notes": "{}".format(lorem.text()),
        } for pid in range(1, size + 1)]

        self.holder.libraries["objs"] = objs
示例#20
0
 def save(self, *args, **kwargs):
     if not self.name:
         self.name = lorem.sentence()[:-1]
     if not self.annotation:
         self.annotation = lorem.sentence() * randint(1, 3)
     if not self.text:
         self.text = lorem.text() * randint(2, 5)
     if not self.image:
         self.image = '../media/images/you_course.png'
     super().save(*args, **kwargs)
示例#21
0
    def generate(self):
        """Generate."""
        size = self.holder.documents["total"]
        tag_pids = self.holder.pids("tags", "pid")

        objs = [{
            "pid":
            str(pid),
            "title":
            lorem.sentence(),
            "authors":
            random.sample(self.AUTHORS, randint(1, 3)),
            "abstract":
            "{}".format(lorem.text()),
            "document_type":
            random.choice(self.DOCUMENT_TYPES),
            "_access": {},
            "languages":
            random.sample(self.LANGUAGES, randint(1, 3)),
            "table_of_content": ["{}".format(lorem.sentence())],
            "note":
            "{}".format(lorem.text()),
            "tag_pids":
            random.sample(tag_pids, randint(0, 5)),
            "edition":
            str(pid),
            "keywords": {
                "source": lorem.sentence(),
                "value": lorem.sentence()
            },
            "conference_info":
            self.CONFERENCE_INFO,
            "number_of_pages":
            str(random.randint(0, 300)),
            "imprints": [self.IMPRINTS[randint(0, 1)]],
            "urls": [{
                "description": "{}".format(lorem.sentence()),
                "value": "{}".format(lorem.sentence()),
            }],
        } for pid in range(1, size + 1)]

        self.holder.documents["objs"] = objs
示例#22
0
    def __init__(self, *args):
        QVBoxLayout.__init__(self, *args)
        self.text = QLabelSelect(lorem.text())
        self.text.setWordWrap(True)
        self.text.setTextInteractionFlags(Qt.TextSelectableByMouse)

        self.scrollArea = QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setWidget(self.text)
        self.scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.addWidget(self.scrollArea)
示例#23
0
def create_post(N):
    fake = Faker()
    for i in range(N):
        numb_text = random.randint(1, 4)
        pic = random.randint(1, 10)
        post = Post.objects.create(title=f'This is new title for Post № {i}',
                                   slug=gen_slug(f'Slug field for Post № {i}'),
                                   content=lorem.text() * numb_text,
                                   author=User.objects.order_by("?").first())
        post.image = ImageFile(
            open(f'{os.getcwd()}/populate_data/{pic}.jpg', 'rb'))
        post.save()
示例#24
0
def get_documents_items(internal_locations, n_docs, n_items):
    """Return random document and items."""
    documents = [{
        Document.pid_field: "{}".format(i),
        "title": "{}".format(lorem.sentence()),
        "authors": "{}".format(lorem.sentence()),
        "abstracts": ["{}".format(lorem.text())],
    } for i in range(1, n_docs)]
    len_docs = len(documents) - 1
    LEN_ITEM_CIRCULATION_RESTRICTIONS = len(ITEM_CIRCULATION_RESTRICTIONS) - 1
    LEN_ITEM_MEDIUMS = len(ITEM_MEDIUMS) - 1
    LEN_ITEM_STATUSES = len(ITEM_STATUSES) - 1

    items = []
    for i in range(1, n_items):
        doc = documents[randint(0, len_docs)]
        restr = ITEM_CIRCULATION_RESTRICTIONS[randint(
            0, LEN_ITEM_CIRCULATION_RESTRICTIONS)]

        item = {
            Document.pid_field: "{}".format(doc[Document.pid_field]),
            Item.pid_field: "{}".format(i),
            "legacy_id": "{}".format(randint(100000, 999999)),
            "legacy_library_id": "{}".format(randint(5, 50)),
            "barcode": "{}".format(randint(10000000, 99999999)),
            "shelf": "{}".format(lorem.sentence()),
            "description": "{}".format(lorem.text()),
            "medium": "{}".format(ITEM_MEDIUMS[randint(0, LEN_ITEM_MEDIUMS)]),
            "status": "{}".format(ITEM_STATUSES[randint(0,
                                                        LEN_ITEM_STATUSES)]),
        }

        ITEM_DOCUMENT_MAPPING["{}".format(i)] = doc[Document.pid_field]

        if restr:
            item["circulation_restriction"] = "{}".format(restr)

        items.append(item)

    return documents, items
示例#25
0
    def generate(self):
        """Generate."""
        size = self.holder.items["total"]
        iloc_pids = self.holder.pids("internal_locations", "pid")
        doc_pids = self.holder.pids("documents", "pid")
        shelf_lorem = TextLorem(wsep='-',
                                srange=(2, 3),
                                words='Ax Bs Cw 8080'.split())
        objs = [{
            "pid":
            self.create_pid(),
            "document_pid":
            random.choice(doc_pids),
            "internal_location_pid":
            random.choice(iloc_pids),
            "legacy_id":
            "{}".format(randint(100000, 999999)),
            "legacy_library_id":
            "{}".format(randint(5, 50)),
            "barcode":
            "{}".format(randint(10000000, 99999999)),
            "shelf":
            "{}".format(shelf_lorem.sentence()),
            "description":
            "{}".format(lorem.text()),
            "internal_notes":
            "{}".format(lorem.text()),
            "medium":
            random.choice(Item.MEDIUMS),
            "status":
            random.choice(
                random.choices(population=Item.STATUSES,
                               weights=[0.7, 0.1, 0.1, 0.1, 0.05],
                               k=10)),
            "circulation_restriction":
            random.choice(Item.CIRCULATION_RESTRICTIONS),
        } for pid in range(1, size + 1)]

        self.holder.items["objs"] = objs
示例#26
0
def view_homework_submission(request, submission_id):
    launch_params = OrderedDict()
    for k in sorted(request.POST.dict().keys()):
        launch_params[k] = request.POST[k]

    content = lorem.text()

    return render(
        request, 'inspector/view_submission.html', {
            'launch_params': launch_params,
            'submission_id': submission_id,
            'content': content
        })
示例#27
0
async def ipsum(ctx, options: str = "s"):
    """
    Random lorem ipsum words, because why not.
    """

    if options.startswith('s'):
        await ctx.send(lorem.sentence())
    elif options.startswith('p'):
        await ctx.send(lorem.paragraph())
    elif options.startswith('t'):
        await ctx.send(lorem.text())
    else:
        await ctx.send("I don't recog- I mean, Lorem ipsum dolor sit amet.")
示例#28
0
    def on_event(self, event, extension): 
        data = event.get_data()
        text = ""

        if(data['type'] == TYPE_PARAGRAPH):
            text = lorem.paragraph()
        
        if(data['type'] == TYPE_SENTENCE):
            text = lorem.sentence()
        
        if(data['type'] == TYPE_TEXT):
            text = lorem.text()

        return CopyToClipboardAction(text).run()
示例#29
0
    def generate(self):
        """Generate."""
        size = self.holder.eitems['total']
        doc_pids = self.holder.pids('documents', "pid")

        objs = [{
            "pid":
            str(pid),
            "document_pid":
            random.choice(doc_pids),
            "description":
            "{}".format(lorem.text()),
            "internal_notes":
            "{}".format(lorem.text()),
            "urls": [
                "https://home.cern/science/physics/dark-matter",
                "https://home.cern/science/physics/antimatter"
            ],
            "open_access":
            bool(random.getrandbits(1))
        } for pid in range(1, size + 1)]

        self.holder.eitems['objs'] = objs
示例#30
0
def lorem_gen(nbytes):
    state = 0
    while True:
        if state == 0:
            buffer = lorem.text().encode("utf-8")
            i = 0
            state += 1
        if state == 1:
            if i == len(buffer) - 1:
                state = 0
            yield buffer[i]
            i += 1
            nbytes -= 1
        if nbytes == 0:
            break
示例#31
0
def random_structure(path, top_ceiling, levels):
    # create root
    folder = Folder(path, [])
    # create x subfolders and create x files
    rand = random_value(top_ceiling)

    for i in range(0, rand):
        rand_type = random.randint(0, 1)
        if (rand_type == 1 and levels > 0):
            item = random_structure("Folder " + str(i), top_ceiling, levels-1)
        else:
            text = lorem.text()
            title = random.choice(text.split())
            item = File(title + str(i) + ".txt", text)

        folder.content.append(item)

    return folder