This is the exercise for the first tutorial: https://dev.cloudburo.net/2019/01/27/python-tutorial-retrieve-a-list-of-swiss-government-members-from-twitter.html
In order to identify the associated party of a Swiss politician, we introduce the method check_for_party, which checks the screen_name as well as the account description field for the mentioning of one of the party’s abbreviation.
A minimal implementation may look like this:
# Method will return the party of the list member by analyzing # twitter account attributes. If party cannot be detected the # account column have an entry "unknown" def check_for_party(self, account_list): party_column =  party_abbreviations = ["FDP", "CVP", "SP", "SVP", "EVP", "BDP"] for account in account_list: party = "unknown" for abbr in party_abbreviations: if abbr in account.description or abbr in account.screen_name: party = abbr party_column.append(party) return party_column
We extend the create_plotly_table with the following statemens
The new Plotly Table will look like this.
Clearly the algorithm is very inaccurate at the moment, but it shows you the direction. E.g. you could enhance by including the french abbreviations, or twitter handles of the party’s which are refrenced in the description (grunliberale) etc,
You can find the extended program (with the exercise code) here: https://github.com/talfco/clb-sentiment/blob/master/src/lesson1/lesson1-ex1.py
This blog entry was fully produced within Evernote and published using the Cloudburo Publishing Bot .