Skip to content

Instantly share code, notes, and snippets.

@bbelyeu
Created November 4, 2013 21:15
Show Gist options
  • Save bbelyeu/7309308 to your computer and use it in GitHub Desktop.
Save bbelyeu/7309308 to your computer and use it in GitHub Desktop.
class UpdateInbox(object):
'''
Update the Inbox for a user
Instantiate with the user's id to update, a where dictionary, and a
dictionary to replace the content with if required (otherwise will
just delete the notification)
'''
_items = []
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
social_db = Model().config['pg']['social']
with pg.open(social_db) as cursor:
cursor.execute(
'SELECT items FROM notifications WHERE user_id = '
'%(user_id)s',
{'user_id': self.user_id}
)
self._items = cursor.fetchone()['items']
def work(self):
for i in deepcopy(self._items):
if all(key in i for key in self.where.keys()):
if self.where['data'] == i['data'] and \
self.where['template'] == i['template']:
self._items[i]['template']['id'] = self.replace_with
ns_version_key = 'notifications-items-user-id-{0}-version'.format(
self.user_id
)
Model().memcache.incr(ns_version_key)
@bbelyeu
Copy link
Author

bbelyeu commented Nov 4, 2013

Is there a way to do a list comprehension on line 25-27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment