This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __init__(self, country_code): | |
self.__country_code = country_code | |
# Dependent on the country parameter load the relevant configurations | |
file_name = "config-"+country_code+".yaml" | |
with open("../../cfg/"+file_name, 'r') as stream: | |
try: | |
self.__cfg= yaml.load(stream) | |
print(self) | |
except yaml.YAMLError as exc: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_government_members(self): | |
lists = self.__api.lists_all('SoMePolis') | |
for list in lists: | |
if list.name == 'BundesparlamentarierInnen': | |
result = [] | |
for item in tweepy.Cursor(self.__api.list_members, list_id=list.id).items(): | |
result.append(item) | |
return result | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GovernmentSocialMediaAnalyzer(object): | |
# Class Instance Variable | |
__cfg = {} | |
__country_code = None | |
__api = None | |
def __init__(self, country_code): | |
self.__country_code = country_code | |
# Dependent on the country parameter load the relevant configurations | |
file_name = "config-"+country_code+".yaml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twitterListAccount: "SoMePolis" | |
twitterListName: "BundesparlamentarierInnen" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __get_government_members(self): | |
lists = self.__api.lists_all(self.__cfg['twitterListAccount']) | |
for list in lists: | |
if list.name == self.__cfg['twitterListName']: | |
result = [] | |
for item in tweepy.Cursor(self.__api.list_members, list_id=list.id).items(): | |
result.append(item) | |
return result | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __extract_columns(self): | |
accounts = self.__get_government_members() | |
labels = range(0,len(accounts)) | |
self.__col_screen_name = [account.screen_name for account in accounts] | |
self.__col_name = [account.name for account in accounts] | |
self.__col_description = [account.description for account in accounts] | |
self.__col_followers_count = [account.followers_count for account in accounts] | |
self.__col_friends_count = [account.friends_count for account in accounts] | |
self.__col_party = self.__check_for_party(accounts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twitterListAccount: "SoMePolis" | |
twitterListName: "BundesparlamentarierInnen" | |
# https://www.parlament.ch/de/organe/fraktionen/im-parlament-vertretene-parteien | |
parties: | |
- twitter: "spschweiz" | |
abbrs: ["SP","PS"] | |
- twitter: "FDP_Liberalen" | |
abbrs: ["FDP","PLR"] | |
- twitter: "SVPch" | |
abbrs: ["SVP","UDC"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __check_for_party(self, user_list): | |
party_column = [] | |
# iterate through each user account | |
for user in user_list: | |
# iterate trough all parties | |
for party in self.__cfg.get('parties'): | |
res = "unknown" | |
# Check first all abbreviations | |
# We don't do lower here because that could result to false positive | |
for abbr in party['abbrs']: |