Example #1
0
	def make_a_comment(self, story, msg=''):
		url = self._get_meneame_url()+'story.php?id='+str(story)
		if len(msg) == 0:
			msg = chomsky(4, 72)[0:500]
		self._br.open(url)
		self._br.select_form(nr=1)
		self._br['comment_content'] = msg
		self._br.submit()
Example #2
0
def test_setup(**kwargs):
    from django.contrib.auth.models import User
    from models import Thread, Post, Category
    from random import choice
    import chomsky

    if not settings.DEBUG:
        return

    if Thread.objects.all().count() > 0:
        # return, since there seem to already be threads in the database.
        return

    # ask for permission to create the test
    msg = """
    You've installed SNAPboard with DEBUG=True, do you want to populate
    the board with random users/threads/posts to test-drive the application?
    (yes/no):
    """
    populate = raw_input(msg).strip()
    while not (populate == "yes" or populate == "no"):
        populate = raw_input("\nPlease type 'yes' or 'no': ").strip()
    if populate == "no":
        return

    # create 10 random users

    users = ("john", "sally", "susan", "amanda", "bob", "tully", "fran")
    for u in users:
        user = User.objects.get_or_create(username=u)
        # user.is_staff = True

    cats = ("Random Topics", "Good Deals", "Skiing in the Vermont Area", "The Best Restaurants")
    for c in cats:
        cat = Category.objects.get_or_create(label=c)

    # create up to 30 posts
    tc = range(1, 50)
    for i in range(0, 35):
        print "thread ", i, "created"
        cat = choice(Category.objects.all())
        subj = choice(chomsky.objects.split("\n"))
        thread = Thread(subject=subj, category=cat)
        thread.save()

        for j in range(0, choice(tc)):
            text = "\n\n".join([chomsky.chomsky() for x in range(0, choice(range(2, 5)))])
            # create a post
            post = Post(
                user=choice(User.objects.all()),
                thread=thread,
                text=text,
                ip=".".join([str(choice(range(1, 255))) for x in (1, 2, 3, 4)]),
            )
            # allows setting of arbitrary ip
            post.management_save()
Example #3
0
	def _generate_content(self, title, tags, bodytext, category):
		d = {
			'title'	   : title,
			'tags' 	   : tags,
			'bodytext' : bodytext,
			'category' : category
		}
		if len(title) 	 == 0:
			d['title'] = chomsky(1, 72)[0:120]
		if len(tags) 	 == 0:
			d['tags']  = self._random_tag()
		if len(bodytext) == 0:
			d['bodytext'] = chomsky(4, 72)[0:500]

		categories = [17, 25, 7, 18, 20, 44, 24, 38, 64, 41, 22, 
			62, 36, 61, 29, 60, 15, 16, 9, 45, 6, 35, 27, 12, 32, 
			28, 5, 10, 13, 40, 8, 4, 23, 39, 43, 42, 37, 11, 1]
		rand = random.randrange(len(categories)-1)
		if category == -1:
			d['category'] = str(categories[rand]) #Hay 60 categorías

		return d
Example #4
0
def cocke_younger_kasami(term, nonterm, prod, string):
    result = chomsky(term, nonterm, prod)
    term = result[0]
    nonterm = result[1]
    prod = result[2]
    recog_matrix = []
    for i in range(0, len(string)):
        recog_matrix.append([[]] * len(string))
    print recog_matrix
    k = 0
    for i in range(0, len(string)):
        recog_matrix[0][i] = string[i]
    for i in range(0, len(string)):
        recog_matrix[1][i] = find_prod(term, prod, string[i])
    print recog_matrix
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    content = message.content.lower()
    if content == 'countdown':
        msg = countdown(inaug_epoch_2025)
        print(f'Message from {message.author}, countdown={msg}')
        await message.channel.send(msg)
    elif content == 'swatch':
        msg = swatch()
        print(f'Message from {message.author}, swatch={msg}')
        await message.channel.send(msg)
    elif content == 'chomsky':
        msg = chomsky()
        print(f'Message from {message.author}, chomsky={msg}')
        await message.channel.send(msg)
    elif content == 'conspiracy':
        msg = conspiracy()
        print(f'Message from {message.author}, conspiracy={msg}')
        await message.channel.send(msg)
    elif content == 'well actually':
        msg = well_actually()
        print(f'Message from {message.author}, well_actually={msg}')
        await message.channel.send(msg)
    elif content == 'walt vaccine':
        m1 = countdown(vaccine_jab1)
        m2 = countdown(vaccine_jab1_week)
        m3 = countdown(vaccine_jab2)
        m4 = countdown(vaccine_jab2_week)
        m5 = countdown(vaccine_jab3)
        msg = f'**First jab:** {m1}\n**14 days after first jab:** {m2}\n**Second jab:** {m3}\n**14 days after second jab:** {m4}\n**Third jab:** {m5}'
        print(f'Message from {message.author}, walt vaccine={msg}')
        await message.channel.send(msg)
    elif content.startswith('covid pa graph'):
        county = content.split()[-1].title()
        fname = os.path.join('/home/waltman/perl/projects/covid19/graphs',
                             county + "_cases.png")
        if os.path.exists(fname):
            print(f'Message from {message.author}, sending {fname}')
            await message.channel.send(file=discord.File(fname))
        else:
            msg = f'Sorry, no graph for {county}'
            print(f"Message from {message.author}, {fname} doesn't exist")
            await message.channel.send(msg)
Example #6
0
def main(file, string):
    grammar = read_grammar(file)
    grammar = chomsky(grammar)

    cyk(grammar, string)