from messenger import Skype
import keyring
import utils

token = keyring.get_password('messagesReceiver', 'skypeToken')
registrationToken = keyring.get_password('messagesReceiver', 'skypeRegistrationToken')
username = keyring.get_password('messagesReceiver', 'skypeUsername')
password = keyring.get_password('messagesReceiver', 'skypePassword')
s = Skype(token, registrationToken)
if s.token == None:
    s.login(username, password)
    print "logging in..."
if s.registrationToken == None:
    print s.createRegistrationToken()
    print s.subcribe()
    print "creating endpoint and registrationToken..."
while True:
    data = s.pull()
    if data == 404:
        

    if data == 400:
        continue
    messages = utils.skypeParse(data)
    if not messages:
        continue
    for sender, receiver, message in messages:
        if receiver != None:
            print "%s to %s" % (sender, receiver)
        else:
            print "From %s" % sender
        print message

print s.createRegistrationToken()
        print s.subcribe()
        data = s.pull()