I'm developing a webapp on facebook that enables customers to supply login particulars for a 3rd party website making demands via my application to that particular service. (i.e. they've a free account with my application, as well as an account using the third party website.)
There's no API with this 3rd party website, and so i am using URLlib to do the logins. In addition, all interactions with this particular third party application are using a Celery Queue, so there's no outcomes of the frontend of my application, and also the actual request from the application towards the third party
I'm attempting to develop the easiest method to cope with controlling the snacks came back through the 3rd party website to ensure that I do not have to log the consumer in at each action.
Will it be madness to produce a table that maps customers to snacks and serialise the snacks in to the database?
For anybody who happens across this later on, I could save the snacks within the database by utilizing cookielib (part of urllib) and creating my very own cookiejar that dumps and loads snacks as strings that may be held in a DB:
class StringCookieJar(cookielib.CookieJar): def __init__(self, cookie_string="", policy=None): cookielib.CookieJar.__init__(self, policy) if cookie_string: self._cookies = pickle.loads(cookie_string) def dump(self): return pickle.dumps(self._cookies)
When designing a clear case of my connection object, I setup the urllib opener with my custom cookielib:
self.cookiejar = StringCookieJar(cookie_string=str(self.account.cookies)) self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejar))
where self.account.snacks may be the area within the database I'm using to keep my cookie string:
cookies = models.CharField(max_length=2000, blank=True)
Growing around the answer above:
class MyConnection(models.Model): cookie_text = models.TextField(blank=True, null=True, editable=False) def __init__(self, *args, **kwargs): self.cookie_jar = StringCookieJar(self.cookies) def save(self, *args, **kwargs): self.cookies = self.cookie_jar.dump() return super(Connection, self).save(*args, **kwargs)