Social media generated art in Python #ThisIsMyClassroom #Programming #STEAM

For the third blog post on this topic I wanted to use Python to generate different pieces of art without relying entirely on the random function. I decided to use the tweepy library, mainly because I had already used it to post content to Twitter but had never investigated how it could be used to read information back from Twitter.

It didn’t take long to find out how to read the latest 10 tweets from my own timeline using Python. Then I split the individual words into a list and sorted them into alphabetical order (for no real reason at the moment, but frequency analysis will follow!). Then I used the write method from the Turtle graphics library to place each word at a random location on the screen. This was my first attempt:

Screen Shot 2016-04-03 at 23.50.08

A bit tricky to read the words I thought. And I’d accidentally forgotten to penup before moving the turtle. However this accidental vector spider web became part of the artwork (because when I removed it, it looked quite boring).

A little while later I was able to change the font size at random (I changed the font to palatino after experimenting with a few others) and changing the pencolor in the same way as previous Python art programs changed the text colour too.

Screen Shot 2016-04-03 at 23.53.35

I had a lot of text to display, even just from 10 tweets, so I thought of ways to reduce the amount. I wrote a little Python subroutine that removed hashtags, mentions and URLs (as well as any other non ASCII text) and that was enough!

The video below shows the program in action. I decided to make a video this time because you can make out the individual words much more clearly at the beginning of the drawing than at the end!

https://youtu.be/M1OUkqwGX3k

As before the code is now on github (with my tweepy details removed for security). I’ve left in a commented out section of code that allows you to run a search for a keyword, hashtag or phrase instead of taking the latest timeline so you can experiment.

Any comments or improvements would be much appreciated!

Ian

Leave a Reply

Your email address will not be published. Required fields are marked *

AH Computing Science Computing Science Scotland Student Engagement

Connecting to a MySQL database using Python 3 #compsci #SQA #AHcomputingscience

Students completing the SQA Advanced Higher Computing Science course need to create their projects with a major and minor in mind. The major – the main area of content their project will showcase – can be either Software Development (e.g. Python), Web Design and Development (PHP) or Database Design and Development (e.g. MySQL). The minor […]

Read More
Student Engagement Uncategorized

Python Programming Challenges and open book assessments

Given that it is Computer Science in Education week and the last few weeks of term I wanted to wrap up my practical programming lessons for the term with some Python programming challenges. Why programming challenges? In the past I’ve used these successfully with lower age groups. In my opinion it helps to validate the […]

Read More
Digital Skills Google Apps for Education This Is My Classroom

Redirecting TinyURL shortcuts using Google Sites

I’ve had my CompSci department page live at my current school for nearly two years now. It links many of the resources students find invaluable and is regularly used across KS3, iGCSE and IB courses. However the new Google Sites layout is much easier to configure and seems to help with accessibility so I decided […]

Read More