import configparser import sys import tweepy from twitivity import Twitivity, TwitivityError config = configparser.ConfigParser() config.read('settings.cfg') consumer_key = config.get('Twitter', 'consumer_key') consumer_secret = config.get('Twitter', 'consumer_secret') environment_name = config.get('Twitter', 'environment_name') def unsubscribe(access_token, access_token_secret): handler = tweepy.OAuthHandler(consumer_key, consumer_secret) handler.set_access_token(access_token, access_token_secret) twitivity = Twitivity(tweepy.API(handler), environment_name) try: twitivity.check_subscription() except TwitivityError: return twitivity.unsubscribe() def main(): try: unsubscribe(*sys.argv[1:3]) except TypeError: print('Not enough arguments!') except TwitivityError as e: print(str(e)) else: print('Success.') if __name__ == '__main__': main()