Tuesday, February 6, 2018

Checking for a generic welcome post in a twitterfeed - python

Well I have been thinking this was necessary for a while because when a year starts or a new class begins their individual blogs these start clogging the twitterfeeds with generic welcome posts. The feeds start looking like this.




Now I am no Python Guru so here is what I found out in creating the solution

I made a variable to hold what would be the last characters of the url 
welcome = 'welcome.html'   note you can replace this with what ever you have at the end of the blog title eg tenei-taonga.html

I put the last 12 characters [-12:] into a variable(welcomecheck) to check against 
welcomecheck = d.entries[0].link[-12:]

We were already checking if the post had already been promoted the highlighted text below adds a check to see if the post is a welcome one. It took me a while to work out the if statement needs to finish with a colon: the == sign is used to check that the strings match.

if post in url_string or welcomecheck == welcome:
        print('No new entries or welcomepost')

The rest of the code remains the same.


Check out a sample of the learners blogging at these twitter feeds.