Exemplo n.º 1
0
def load_db(password=''):
  creds = {}
  keychain = Keychain()
  account = getlogin()
  payload = keychain.get_generic_password(KEYCHAIN, account, SERVICE_NAME)
  if payload and 'password' in payload:
    parts = payload['password'].split(JOIN_STRING)
    if(len(parts) > 1):
      creds['password'] = password and decrypt(password, unhexlify(parts[1])) or parts[1]
      creds['username'] = password and decrypt(password, unhexlify(parts[0])) or parts[0]
  return creds
Exemplo n.º 2
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        message = argv[1]
    except IndexError:
        message = None

    if not message:
        growl.notify("failure", "No message", "You need to actually say something!")
        return
    
    # Check length
    # TODO: use URL shortening service
    if len(message) > MAX_MSG:
        growl.notify("failure", "Message too long", "%d characters, %d allowed." %
            (len(message), MAX_MSG))
        return

    # get credentials:
    keychain = Keychain()
    credentials = keychain.get_generic_password('login', servicename='Twitterrific')
    # getgenericpassword returns a tuple upon error but a dict on success, duh:
    if type(credentials) == type(tuple):
        # if Twitterific hasn't stored credentials, we try a generic key
        credentials = keychain.get_generic_password('login', item=FALLBACK_KEY)
    if type(credentials) == type(tuple):
        # notify the user about where to store credentials, if none are stored
        growl.notify("failure", "No credentials", 
        "Please add username/password to your login keychain with the item name '%s'" \
        % FALLBACK_KEY,
        sticky=True)
        return

    # post the message
    twit = Twitter(credentials['account'], credentials['password'], agent=AGENT_STR)
    message = (message.encode('utf8', 'replace'))
    twit.statuses.update(status=message)
    growl.notify("success", "Tweet sent.", message)
Exemplo n.º 3
0
def get_login_parameters(config_dict) :
    """
        Get the login details from the keychain
    """

    keychain = Keychain()

    keychain_service = config_dict['keychain_service']

    spider_data = keychain.get_generic_password('login',
                                        servicename = keychain_service)

    user = spider_data['account']
    user32 = re.search('^([^=]*)(==*)$', base64.b32encode(user)).group(1)
    password = spider_data['password']

    return user32, password