Esempio n. 1
0
    def add(self, jsondata = None, profile_id= None):
        if not jsondata:
            return json.dumps({"status" : "failed", "error" : "nodata"})

        # deserialize
        d = json.loads(jsondata)

        try:
            account = YahooAccountEmbedded()
            account.firstname = d['firstname']
            account.lastname = d['lastname']
            account.yahooid = d['yahooid']
            account.password = d['password']
            account.secret1 = d['secret1']
            account.secret2 = d['secret2']
            account.postalcode = d['postalcode']
            account.birthday = datetime.date(d['birthyear'], d['birthmonth'], d['birthday'])

            # Add account to a profile that doesn't have one yet
            try:
                if profile_id:
                    jkprofile = JokerProfile.objects.get(id = profile_id)
                else:
                    jkprofile = JokerProfile.objects.filter(accounts__yahoo__exists = False)[0]
            except:
                jkprofile = JokerProfile()
            jkprofile.add_account(account)
            jkprofile.save()

        except Exception as e:
            return json.dumps({"status" : "failed", "error" : unicode(e)})

        return json.dumps({"status" : "success"}) 
Esempio n. 2
0

# Import our models
from seocortex.joker.common.models import JokerProfile
from seocortex.joker.common.models import TwitterAccountEmbedded
from seocortex.joker.common.models import YahooAccountEmbedded


# Build Twitter account
twitter = TwitterAccountEmbedded()
twitter.name = "Tester"
twitter.username = "******"
twitter.password = "******"

# Build Yahoo account
yahoo = YahooAccountEmbedded()
yahoo.yahooid = "SomeYahooId"
yahoo.password = "******"
yahoo.firstname = "john"
yahoo.lastname = "smith"
yahoo.secret1 = "secret1"
yahoo.secret2 = "secret2"
yahoo.postalcode = "90210"
yahoo.birthday = datetime.datetime.now()

# Build JokerProfile
joker = JokerProfile()

# Add accounts
joker.add_account(twitter)
joker.add_account(yahoo)