示例#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 = TwitterAccountEmbedded()
            account.name = d['name']
            account.username = d['username']
            account.password = d['password']

            # 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__twitter__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"}) 
示例#2
0
# Start MongoEngine
import mongoengine
MONGO_ARGS = ('seocortex',)
mongoengine.connect(*MONGO_ARGS) 


# 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()