Exemplo n.º 1
0
    def post(self):
        results_template = the_jinja_env.get_template('templates/results.html')
        meme_line1 = self.request.get("user-first-ln")
        meme_line2 = self.request.get("user-second-ln")
        meme_choice = self.request.get("meme-type")
        username = self.request.get("username")
        date = self.request.get("my_date")
        print(meme_line1, type(meme_line1) )
        print(meme_line2, type(meme_line2) )
        print(meme_choice, type(meme_choice) )

        my_meme = meme.Meme( top_line = meme_line1,
        bottom_line = meme_line2,
        date_str = date,
        author = username,
        image_id = meme_choice)

        user_info = { "line1" :  meme_line1,
        "line2": meme_line2,
        "img_url": my_meme.get_meme_url(),
        "username": username,
        "date_created": date
        }



        my_meme.put()

        self.response.write(results_template.render(user_info))  # the response
Exemplo n.º 2
0
def gen_meme_more_signs(num: int):
    if mini_db_str == '' or phrase == '':
        col2.text(
            'Controlla di aver inserito le frasi del mini db e la frase memosa'
        )
        return None
    mini_db = mini_db_str.split('\n')
    meme = m.Meme(img, start=dict_col[colors][0], end=dict_col[colors][1])
    if len(mini_db) != 12 / num:
        col2.text('Controlla il numero di frasi ({0}) che hai inserito'.format(
            len(mini_db)))
        col2.text(''.join(mini_db))
    else:
        np.random.shuffle(mini_db)
        try:
            os.mkdir('meme')
        except Exception:
            pass
        signs_shuffle = list(articoli_segni.keys())
        random.shuffle(signs_shuffle)
        for i, j in zip(range(0, len(signs_shuffle), num), mini_db):
            frase = phrase.format(
                sign_1=signs_shuffle[i],
                sign_2=signs_shuffle[i + 1] if num >= 2 else 'null',
                sign_3=signs_shuffle[i + 2] if num >= 3 else 'null',
                sign_4=signs_shuffle[i + 3] if num >= 4 else 'null',
                sign_5=signs_shuffle[i + 4] if num >= 5 else 'null',
                sign_6=signs_shuffle[i + 5] if num == 6 else 'null',
                meme=j)
            meme.applyTextBox(frase, signs_shuffle[i])
        for i in articoli_segni.keys():
            try:
                col2.image(f'meme/{i}.png', use_column_width='always')
            except FileNotFoundError:
                pass
Exemplo n.º 3
0
def gen_meme_one_sing():
    if mini_db_str == '' or phrase == '':
        col2.text(
            'Controlla di aver inserito le frasi del mini db e la frase memosa'
        )
        return None
    mini_db = mini_db_str.split('\n')
    meme = m.Meme(img, start=dict_col[colors][0], end=dict_col[colors][1])
    if len(mini_db) == 1:
        mini_db = [mini_db[0] for _ in range(12)]
    if len(mini_db) != 12:
        col2.text('Controlla il numero di frasi ({0}) che hai inserito'.format(
            len(mini_db)))
        col2.text(''.join(mini_db))
    else:
        np.random.shuffle(mini_db)
        try:
            os.mkdir('meme')
        except Exception:
            pass
        for i, j in zip(articoli_segni.keys(), mini_db):
            frase = phrase.format(sign=i,
                                  il_segno=articoli_segni[i][0],
                                  del_segno=articoli_segni[i][1],
                                  meme=j)
            meme.applyTextBox(frase, i)
        for i in articoli_segni.keys():
            col2.image(f'meme/{i}.png', use_column_width='always')
Exemplo n.º 4
0
def main():
    bot.add_command('bg', botguard.BotGuard())
    # bot.add_command('echo', general.Echo())
    bot.add_command('hello', general.Hello())
    bot.add_command('help', general.Help())
    bot.add_command('meme', meme.Meme())
    bot.add_handler(botguard.handler)
    bot.add_handler(press_f.handler)
    bot.start()
Exemplo n.º 5
0
def initialize():
    global n, memes, memes2, main_graph, pos

    meme.Meme.id = 0
    n = 4  # Number of original memes.

    memes = [meme.Meme() for i in range(n)]
    memes2 = memes

    main_graph = nx.Graph()
    pos = nx.spring_layout(main_graph)
Exemplo n.º 6
0
def update():
    global n, memes, memes2, main_graph, pos

    m = choice(memes)  # stochastic updating.

    if random() < 0.05:  # 5% chance that an original memes joins the system.
        memes2.append(meme.Meme())

    if not m.alive:  # skips running methods if the chosen meme is dead.
        return

    m.getOlder()
    m.die()
    child = m.reproduce()

    if child:
        memes2.append(child)

    memes, memes2 = memes2, memes
Exemplo n.º 7
0
 def post(self):
     """A handler for save the meme."""
     image = self.render_meme()
     new_meme = meme.Meme()
     user = users.get_current_user()
     if user:
         new_meme.owner = user
     output = StringIO.StringIO()
     thumbnail_output = StringIO.StringIO()
     image.save(output, "JPEG")
     image.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS)
     image.save(thumbnail_output, "JPEG")
     new_meme.image = output.getvalue()
     new_meme.thumbnail = thumbnail_output.getvalue()
     output.close()
     thumbnail_output.close()
     new_meme.put()
     # step-3
     # It is important to delete the cache here for recent query.
     # Otherwise, the 'Recent' page will keep serving an old list.
     memcache.delete(MEMCACHE_RECENT_KEY)
     self.redirect("/meme/{}".format(new_meme.key.id()), abort=True)
Exemplo n.º 8
0
import meme
"""
This is just here to test generic words and random scores.
Didn't update _Major_Dic because rescore was the last thing I got working
"""

if __name__ == '__main__':
    one = meme.Meme(text=["001", "010", "100"], score=[-1.0, 3.0])
    two = meme.Meme(text=["110", "101", "011"], score=[1.0, 2.0])
    three = meme.Meme(text=["000", "111", "ass"], score=[3.0, 1.0])
    listo = [two, three, one]
    listo.sort(reverse=False)
    print(listo)
    print(one.text, ", ", two.text, ", ", three.text)
    listo = one.breed(two)
    print("one and two:")
    for mime in listo:
        print(mime.__str__() + ":", mime.score)
    #print("one and three:", one.breed(three))
    #print("two and three:", two.breed(three))