Project, Python, Research

Automating Making Memes & Instagram Posts 3: Improving the Script

Now that I’ve got the bare bones working of generating a meme and uploading a photo to Instagram, I can now get to the fun part: customizing the script! I haven’t used Python in quite a few years, but starting with a base gives me something to work off of, so I’m not too worried.

Frankly your sassy attitude is not appreciated

The first thing I did was combine the two main scripts into one so I can control their variables without having to call them. I then put all of my key variables at the top of the script, and entered comments of what I intend to do.

I decided the easiest way to make random meme captions to start (since my neural network output is all the way downstairs on my desktop PC), was to download this famous quote JSON file. Ideally I will capture a ton of possible meme captions in a text file to reference later anyway, so figuring this out will still be helpful.

I then looked up how to read a text file since my format is going to be one meme sentence per line, and I will program it to select a random sentence. First the code below opens a text file, then it reads in a random line to use as the meme’s text.

f = open("/home/thecatgeek/etc/quotes.txt")
upper_meme_text = random.choice(f.readlines())
lower_meme_text = f.readline()

Since I only have the one picture of David Rose, I decided to find some code that would automatically download a bunch of pictures for me. I ran into google-imaged-download and it worked without any issues. Which is a gd Christmas miracle given the problems I typically run into.

cd .virtualenvs
workon memebot_env
pip install google_images_download
python google_images_download.py --keywords "David Rose, Schitts Creek David" --limit 20

The results for “David Rose” only had a few pictures of the TV character, but “Schitts Creek David” was 20 for 20! Now I just need to figure out how to mass crop them into square and how to let my program randomly choose a picture.

David Rose Bot is getting so close, I cannot wait!

BUT FIRST…I’m going to set up my new Raspberry Pi and move what I’ve already done over to it. Then I can remote into that system to continue this project from any device I’m on in the future! ๐Ÿ™‚

And with that, I’ll leave off with pictures of my glorious fur babies!

Leave a Reply