memelol

In [ ]:
import requests
import nltk
import getpass
import random
import PIL
from PIL import ImageDraw, ImageFont
import shutil
from IPython.display import Image
from IPython.core.display import HTML 
In [638]:
myusr = getpass.getuser()
In [639]:
mepat = ('/home/{}/memetemp/'.format(myusr))
In [641]:
reqmempop = requests.get('http://version1.api.memegenerator.net/Generators_Select_ByPopular?pageIndex=0&pageSize=24')
In [ ]:
genres = reqmempop.json()
In [642]:
for ger in genres['result']:
    #print(ger)
    response = requests.get(ger['imageUrl'], stream=True)
    namimg = ger['urlName']
    #print(len(namimg))
    #print(namimg)
    with open('{}{}.jpg'.format(mepat, namimg), 'wb') as out_file:
        shutil.copyfileobj(response.raw, out_file)
        del response
        
    meing = PIL.Image.open('{}{}.jpg'.format(mepat, namimg))
    #meing
    medraw = ImageDraw.Draw(meing)
    #font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 32)
    #font = ImageFont.truetype("/home/wcm/Downloads/fashi954.ttf", 12)
    fontwo = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf', 48)

    medraw.text((10, 10), namimg, (255,0,0), font=fontwo)
    
    meing.save('{}{}.jpg'.format(mepat, namimg))

    
{'generatorID': 2, 'urlName': 'Y-U-No', 'imageID': 166088, 'displayName': 'Y U No', 'imageUrl': 'https://cdn.meme.am/cache/images/folder88/400x/166088.jpg', 'totalVotesScore': 9290, 'ranking': 1, 'instancesCount': 2253169}
6
Y-U-No
{'generatorID': 305, 'urlName': 'Futurama-Fry', 'imageID': 84688, 'displayName': 'Futurama Fry', 'imageUrl': 'https://cdn.meme.am/cache/images/folder688/400x/84688.jpg', 'totalVotesScore': 6388, 'ranking': 2, 'instancesCount': 1580698}
12
Futurama-Fry
{'generatorID': 74, 'urlName': 'The-Most-Interesting-Man-In-The-World', 'imageID': 2485, 'displayName': 'The Most Interesting Man In The World', 'imageUrl': 'https://cdn.meme.am/cache/images/folder485/400x/2485.jpg', 'totalVotesScore': 4957, 'ranking': 3, 'instancesCount': 1849842}
37
The-Most-Interesting-Man-In-The-World
{'generatorID': 17, 'urlName': 'Philosoraptor', 'imageID': 984, 'displayName': 'Philosoraptor', 'imageUrl': 'https://cdn.meme.am/cache/images/folder984/400x/984.jpg', 'totalVotesScore': 9548, 'ranking': 4, 'instancesCount': 791492}
13
Philosoraptor
{'generatorID': 542616, 'urlName': 'Willy-Wonka', 'imageID': 2729805, 'displayName': 'Willy Wonka', 'imageUrl': 'https://cdn.meme.am/cache/images/folder805/400x/2729805.jpg', 'totalVotesScore': 2931, 'ranking': 5, 'instancesCount': 1916828}
11
Willy-Wonka
{'generatorID': 121, 'urlName': 'Success-Kid', 'imageID': 1031, 'displayName': 'Success Kid', 'imageUrl': 'https://cdn.meme.am/cache/images/folder31/400x/1031.jpg', 'totalVotesScore': 4559, 'ranking': 6, 'instancesCount': 1336096}
11
Success-Kid
{'generatorID': 689854, 'urlName': 'One-Does-Not-Simply', 'imageID': 3291562, 'displayName': 'One Does Not Simply', 'imageUrl': 'https://cdn.meme.am/cache/images/folder562/400x/3291562.jpg', 'totalVotesScore': 2594, 'ranking': 7, 'instancesCount': 1325073}
19
One-Does-Not-Simply
{'generatorID': 740857, 'urlName': 'Bad-Luck-Brian', 'imageID': 3459374, 'displayName': 'Bad Luck Brian', 'imageUrl': 'https://cdn.meme.am/cache/images/folder374/400x/3459374.jpg', 'totalVotesScore': 2832, 'ranking': 8, 'instancesCount': 1150300}
14
Bad-Luck-Brian
{'generatorID': 534, 'urlName': 'Good-Guy-Greg', 'imageID': 699717, 'displayName': 'Good Guy Greg', 'imageUrl': 'https://cdn.meme.am/cache/images/folder717/400x/699717.jpg', 'totalVotesScore': 5607, 'ranking': 9, 'instancesCount': 352389}
13
Good-Guy-Greg
{'generatorID': 1771888, 'urlName': 'Grumpy-Cat', 'imageID': 6541210, 'displayName': 'Grumpy Cat ', 'imageUrl': 'https://cdn.meme.am/cache/images/folder210/400x/6541210.jpg', 'totalVotesScore': 4042, 'ranking': 10, 'instancesCount': 607615}
10
Grumpy-Cat
{'generatorID': 340895, 'urlName': 'First-World-Problems', 'imageID': 2055789, 'displayName': 'First World Problems', 'imageUrl': 'https://cdn.meme.am/cache/images/folder789/400x/2055789.jpg', 'totalVotesScore': 2068, 'ranking': 11, 'instancesCount': 957399}
20
First-World-Problems
{'generatorID': 116, 'urlName': 'Forever-Alone', 'imageID': 142442, 'displayName': 'Forever Alone', 'imageUrl': 'https://cdn.meme.am/cache/images/folder442/400x/142442.jpg', 'totalVotesScore': 3436, 'ranking': 12, 'instancesCount': 402987}
13
Forever-Alone
{'generatorID': 45, 'urlName': 'Insanity-Wolf', 'imageID': 20, 'displayName': 'Insanity Wolf', 'imageUrl': 'https://cdn.meme.am/cache/images/folder20/400x/20.jpg', 'totalVotesScore': 3181, 'ranking': 14, 'instancesCount': 303556}
13
Insanity-Wolf
{'generatorID': 54, 'urlName': 'Joseph-Ducreux', 'imageID': 42, 'displayName': 'Joseph Ducreux', 'imageUrl': 'https://cdn.meme.am/cache/images/folder42/400x/42.jpg', 'totalVotesScore': 3077, 'ranking': 15, 'instancesCount': 283043}
14
Joseph-Ducreux
{'generatorID': 68, 'urlName': 'Trollface', 'imageID': 269, 'displayName': 'Trollface', 'imageUrl': 'https://cdn.meme.am/cache/images/folder269/400x/269.jpg', 'totalVotesScore': 3275, 'ranking': 16, 'instancesCount': 242017}
9
Trollface
{'generatorID': 29, 'urlName': 'Socially-Awkward-Penguin', 'imageID': 983, 'displayName': 'Socially Awkward Penguin', 'imageUrl': 'https://cdn.meme.am/cache/images/folder983/400x/983.jpg', 'totalVotesScore': 3226, 'ranking': 17, 'instancesCount': 226801}
24
Socially-Awkward-Penguin
{'generatorID': 318374, 'urlName': 'Conspiracy-Keanu', 'imageID': 1986282, 'displayName': 'Conspiracy Keanu', 'imageUrl': 'https://cdn.meme.am/cache/images/folder282/400x/1986282.jpg', 'totalVotesScore': 2716, 'ranking': 18, 'instancesCount': 319411}
16
Conspiracy-Keanu
{'generatorID': 142, 'urlName': 'Scumbag-Steve', 'imageID': 366130, 'displayName': 'Scumbag Steve', 'imageUrl': 'https://cdn.meme.am/cache/images/folder130/400x/366130.jpg', 'totalVotesScore': 2088, 'ranking': 19, 'instancesCount': 429183}
13
Scumbag-Steve
{'generatorID': 235, 'urlName': 'Pedobear', 'imageID': 564288, 'displayName': 'Pedobear', 'imageUrl': 'https://cdn.meme.am/cache/images/folder288/400x/564288.jpg', 'totalVotesScore': 2216, 'ranking': 20, 'instancesCount': 249089}
8
Pedobear
{'generatorID': 79, 'urlName': 'Yo-Dawg', 'imageID': 108785, 'displayName': 'Yo Dawg', 'imageUrl': 'https://cdn.meme.am/cache/images/folder785/400x/108785.jpg', 'totalVotesScore': 1926, 'ranking': 21, 'instancesCount': 304385}
7
Yo-Dawg
{'generatorID': 543246, 'urlName': 'Winter-Is-Coming', 'imageID': 2732092, 'displayName': 'Winter is Coming', 'imageUrl': 'https://cdn.meme.am/cache/images/folder92/400x/2732092.jpg', 'totalVotesScore': 18, 'ranking': 23, 'instancesCount': 594865}
16
Winter-Is-Coming
{'generatorID': 318065, 'urlName': 'All-The-Things', 'imageID': 1985197, 'displayName': 'All the things', 'imageUrl': 'https://cdn.meme.am/cache/images/folder197/400x/1985197.jpg', 'totalVotesScore': 1513, 'ranking': 24, 'instancesCount': 293696}
14
All-The-Things
{'generatorID': 3, 'urlName': 'Foul-Bachelor-Frog', 'imageID': 203, 'displayName': 'Foul Bachelor Frog', 'imageUrl': 'https://cdn.meme.am/cache/images/folder203/400x/203.jpg', 'totalVotesScore': 2241, 'ranking': 25, 'instancesCount': 144943}
18
Foul-Bachelor-Frog
{'generatorID': 839, 'urlName': 'Annoying-Facebook-Girl', 'imageID': 876097, 'displayName': 'Annoying Facebook Girl', 'imageUrl': 'https://cdn.meme.am/cache/images/folder97/400x/876097.jpg', 'totalVotesScore': 1770, 'ranking': 26, 'instancesCount': 228797}
22
Annoying-Facebook-Girl
In [1036]:
selpo = ('http://version1.api.memegenerator.net/Instances_Select_ByPopular?')
In [1037]:
#reqinst = requests.get('{}languageCode=en&pageIndex=0&pageSize=1&urlName={}'.format(selpogenres['result'][gere]['displayName']))
In [1122]:
disnam = list()
In [1123]:
ranpa = '/home/{}/meme/'.format(myusr)
In [1124]:
ranres = random.choice(genres['result'])
In [1125]:
ranres['imageUrl']
Out[1125]:
'https://cdn.meme.am/cache/images/folder374/400x/3459374.jpg'
In [1126]:
ranres['urlName']
Out[1126]:
'Bad-Luck-Brian'
In [1127]:
disnm = ranres['displayName']
In [1267]:
response = requests.get(ranres['imageUrl'], stream=True)
with open('{}{}.jpg'.format(ranpa, disnm), 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)
    del response
In [1268]:
meeim = PIL.Image.open('{}{}.jpg'.format(ranpa, disnm))
In [1269]:
Image('{}{}.jpg'.format(ranpa, disnm))
Out[1269]:
In [1270]:
#meetest = PIL.Image.new("RGBA", (640,640), (255,255,255))
medraw = ImageDraw.Draw(meeim)
#font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 32)
#font = ImageFont.truetype("/home/wcm/Downloads/fashi954.ttf", 12)
fontwo = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf', 32)

medraw.text((10, 10), disnm, (0,0,0), font=fontwo)
In [1271]:
meeim.save('/home/wcm/Downloads/success.jpg')
In [1272]:
Image('/home/wcm/Downloads/success.jpg')
Out[1272]:
In [1273]:
for gere in range(0,24):
    #print(genres['result'][gere]['displayName'])
    disnam.append(genres['result'][gere]['displayName'])
    #print(reqinst.json())
    #reins = (reqinst.json())
    #reqinst = requests.get('{}languageCode=en&pageIndex=0&pageSize=1&urlName={}'.format(selpo, genres['result'][gere]['displayName']))
    #reins = (reqinst.json())
    #print(reins)    
    #except Error:
    #    pass
    #else:
    #    print(reins['result'][0])
    #reins = (reqinst.json())
    #print(reins['result'][0])
    #if 'text0' in reins['result']:
    #    print(reins['result'][0])
In [ ]:
 
In [1274]:
#disnam
In [1275]:
jodis = ' '.join(disnam)
In [1276]:
''.join([str(jodis) for jodis in random.sample(jodis, len(jodis))])
Out[1276]:
' eknmycfm sci hKeNe osbgo c yu oinDk A lriCeonrTWJur nSoo  d eFhe Taue tmgirekNeh oFs uotrae  raooc yFLialgTMyt Fiv rGb pu nSureLrmIA a cAnooncoFsggBrD   wcoulvtdglolMuP nl lkdgiyxrceo ourbnli SDerhirlanhK tue n tpsWTGuciacGCo Bodnt nonolrC oeef agkr rn son lssdeshG howltgrrrlnyTr  cupae  ipgea inaaib e  aeFiayorBnanregr u otygeilnhsorsF lNYeGF pl tewSyoS aa aPY nnlF  ueuOdaaGi tys BwtrNiUooYsu to lAa Gaecm ooes rogt  sP uwllgydtd UFKdnocxaooCllnonnoapanWP e dulir am batAsr oirF p kmFyobou PahicIl rhyIeloiBAWmrie tae u roWhlreasea rikec P tiB a s oai ISisrariWlcnom n htnyontltaauDl dens Csn e   i FuoDSGdnecipteySbgWtine emrsF oh drSGo  nfg yJ iTtre Piy  oeweWgoWoKcedbl lomWsnrur skorIl rMM A atprIWrngeOc oDy fseieYluP nveiAlelos l CWSpmhtvaG oc '
In [1277]:
random.shuffle('wgewrgwgw')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1277-3ca69c866fcd> in <module>()
----> 1 random.shuffle('wgewrgwgw')

/usr/lib/python3.4/random.py in shuffle(self, x, random)
    270                 # pick an element in x[:i+1] with which to exchange x[i]
    271                 j = randbelow(i+1)
--> 272                 x[i], x[j] = x[j], x[i]
    273         else:
    274             _int = int

TypeError: 'str' object does not support item assignment
In [1278]:
tokens = nltk.word_tokenize(jodis)
In [ ]:
 
In [1279]:
#for tok in tokens:
    #print(tok.lower())
#    for tolo in tok.lower():
#        print(tolo)
In [1280]:
meimg = requests.get('https://api.imgflip.com/get_memes')
In [1281]:
mejsn = meimg.json()
In [1282]:
lenme = len(mejsn['data']['memes'])
In [1283]:
#PIL.Image
In [1284]:
imgpath = ('/home/{}/fashion/'.format(myusr))
In [1285]:
jurimg = PIL.Image.open(imgpath + 'fashion.jpg').convert('LA')
In [1286]:
jurimg.save(imgpath + 'greyscale.png')
In [1287]:
Image(imgpath + 'greyscale.png')
Out[1287]:
In [ ]:
 
In [1288]:
jurblack = PIL.Image.open(imgpath + 'greyscale.png')
In [1289]:
jurother = PIL.Image.open(imgpath + 'fashion2.jpg')
In [1291]:
Image(imgpath + 'fashion2.jpg')
Out[1291]:
In [ ]:
 
In [1290]:
jurthis = PIL.Image.open(imgpath + 'life.jpg')
In [1152]:
jurother.size
Out[1152]:
(1000, 562)
In [1153]:
jurthis.size
Out[1153]:
(1024, 768)
In [1154]:
jurconv = jurthis.resize((1000, 562), PIL.Image.ANTIALIAS)
In [1155]:
jurimg.size
Out[1155]:
(1000, 562)
In [1156]:
jurother.mode
Out[1156]:
'RGB'
In [1157]:
jurimg.mode
Out[1157]:
'LA'
In [1158]:
jurthis.mode
Out[1158]:
'RGB'
In [1293]:
jurcol = jurimg.convert('RGB')
In [1303]:
blenim = PIL.Image.blend(jurconv, jurcol, 0.7)
In [ ]:
 
In [1304]:
blenim.save(imgpath + 'blend.jpg')
In [1305]:
Image(imgpath + 'blend.jpg')
Out[1305]:
In [1306]:
mebig = meeim.resize((1000, 562), PIL.Image.ANTIALIAS)
In [1307]:
#blenim = PIL.ImageFilter.GaussianBlur(jurblack)
In [1308]:
#blenim.save(imgpath + 'blend.png')
In [1309]:
ble = PIL.Image.open(imgpath + 'blend.jpg')
In [1310]:
bleda = ble.getdata()
In [1311]:
#out = PIL.Image.FLIP_LEFT_RIGHT(ble)
In [1312]:
myrot = ble.rotate(180)
In [1313]:
myrot.save(imgpath + 'rot.png')
In [1314]:
blenow = PIL.Image.blend(myrot, mebig, 0.4)
In [1315]:
blenow.save(imgpath + 'blendz.png')
In [1316]:
Image(imgpath + 'blendz.png')
Out[1316]: