home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- import time
- from util.observe import ObservableList
- from datetime import date
- from collections import defaultdict
- from util import do, iproperty, strftime_u
- from datetime import datetime
- from logging import getLogger
- from itertools import chain
- log = getLogger('facebook.objects')
-
- class Alerts(object):
- stuff = [
- 'num_msgs',
- 'msgs_time',
- 'num_pokes',
- 'pokes_time',
- 'num_shares',
- 'shares_time',
- 'friend_requests',
- 'group_invites',
- 'event_invites']
- urls = dict(msgs = 'http://www.facebook.com/inbox/', pokes = 'http://www.facebook.com/home.php', shares = 'http://www.facebook.com/posted.php', friend_requests = 'http://www.facebook.com/reqs.php', group_invites = 'http://www.facebook.com/reqs.php#group', event_invites = 'http://www.facebook.com/reqs.php#event')
-
- def __init__(self, fb = None, notifications_get_xml = None):
- log.debug('type(notifications_get_xml) ==> %r', type(notifications_get_xml))
- self.fb = fb
- if notifications_get_xml is not None:
- log.debug('here')
- t = notifications_get_xml
- self.num_msgs = int(t.messages.unread)
- self.msgs_time = int(t.messages.most_recent)
- self.num_pokes = int(t.pokes.unread)
- self.pokes_time = int(t.pokes.most_recent)
- self.num_shares = int(t.shares.unread)
- self.shares_time = int(t.shares.most_recent)
- self.friend_requests = set((lambda .0: for uid in .0:
- int(uid))(t.friend_requests))
- self.group_invites = set((lambda .0: for gid in .0:
- int(gid))(t.group_invites))
- self.event_invites = set((lambda .0: for eid in .0:
- int(eid))(t.event_invites))
- else:
- self.num_msgs = 0
- self.msgs_time = 0
- self.num_pokes = 0
- self.pokes_time = 0
- self.num_shares = 0
- self.shares_time = 0
- self.friend_requests = set()
- self.group_invites = set()
- self.event_invites = set()
- log.debug('there')
-
-
- def __repr__(self):
- pformat = pformat
- import pprint
- s = []([ (a, getattr(self, a)) for a in self.stuff ])
- return '<Alerts %s>' % s
-
-
- def __sub__(self, other):
- ret = Alerts(self.fb)
- for attr in self.stuff:
- setattr(ret, attr, getattr(self, attr) - getattr(other, attr))
-
- return ret
-
-
- def __cmp__(self, other):
- if type(self) != type(other):
- return 1
-
- for attr in self.stuff:
- if getattr(self, attr) != getattr(other, attr):
- if not self.num_all - other.num_all:
- pass
- return 1
- continue
-
- return 0
-
-
- def num_all(self):
- return sum([
- self.num_msgs,
- self.num_pokes,
- self.num_shares,
- len(self.friend_requests),
- len(self.group_invites),
- len(self.event_invites)])
-
- num_all = property(num_all)
-
- def count(self):
- return sum([
- self['num_msgs'],
- self['num_pokes'],
- self['num_shares'],
- self['num_friend_requests'],
- self['num_group_invites'],
- self['num_event_invites']])
-
- count = property(count)
-
- def num_friend_requests(self):
- return len(self.friend_requests)
-
- num_friend_requests = property(num_friend_requests)
-
- def num_group_invites(self):
- return len(self.group_invites)
-
- num_group_invites = property(num_group_invites)
-
- def num_event_invites(self):
- return len(self.event_invites)
-
- num_event_invites = property(num_event_invites)
-
- def __nonzero__(self):
- return (any,)((lambda .0: for attr in .0:
- getattr(self, attr))(self.stuff))
-
-
- def __getitem__(self, key):
- if not hasattr(self, 'fb') or self.fb is None:
- raise KeyError(key)
-
- return self.fb.filters['alerts'][key] * getattr(self, key)
-
-
-
- class NewsfeedItem(object):
-
- def __init__(self, name = 'foo'):
- self.hidden = False
- self.correct_time = True
-
-
- def set_time(self, time):
- if time is not None:
- dt = datetime.fromtimestamp(time)
- self.formatted_time = strftime_u(dt, '%#I:%M') + strftime_u(dt, '%p').lower()
-
- self._time = time
-
-
- def get_time(self):
- return self._time
-
- time = property(get_time, set_time)
-
- def __repr__(self):
- return '<' + type(self).__name__ + ' ' + (' '.join,)((lambda .0: for attr in .0:
- if not attr.startswith('_'):
- '%s=%r' % (attr, getattr(self, attr))continue)(list(self.__dict__) + [
- 'time'])) + '>'
-
- link = iproperty('get_link', 'set_link')
- text = iproperty('get_text')
-
- def get_link(self):
- return 'http://www.facebook.com/'
-
-
- def set_link(self, link):
- pass
-
-
- def get_text(self):
- raise NotImplementedError
-
-
- def __unicode__(self):
- text = self.text
- return text
-
-
- def his_her_their(self):
- s = self.sex
- if s == 'female':
- return 'her'
- elif s == 'male':
- return 'his'
- else:
- return 'their'
-
- his_her_their = property(his_her_their)
-
-
- class ZeroTime(object):
- time = 0
-
-
- class NewsfeedList(list):
-
- def update_recent(self):
- self.most_recent = max((lambda .0: for thing in .0:
- thing.time)(self + [
- ZeroTime]))
-
-
- def extend(self, *a, **k):
- list.extend(self, *a, **k)
- self.update_recent()
-
-
-
- class Statuses(NewsfeedList):
-
- def __init__(self, statuses_xml):
- NewsfeedList.__init__(self)
- (do,)((lambda .0: for user in .0:
- self.append(Status(user)))(statuses_xml))
- self.update_recent()
-
-
-
- class Status(NewsfeedItem):
-
- def __init__(self, user):
- NewsfeedItem.__init__(self, 'status')
- self.time = int(user.status.time)
- self.uid = int(user.uid)
- self.name = unicode(user.name)
- self.message = unicode(user.status.message)
-
-
-
- class Profiles(object):
-
- def __init__(self, profiles_xml):
- self.data = defaultdict((lambda : defaultdict(set)))
- self.update(profiles_xml)
-
-
- def update(self, profiles_xml):
- new_profiles = [ Profile(user) for user in profiles_xml ]
- for p in new_profiles:
- self.data[date.fromtimestamp(p.time)][p.uid].add(p)
-
- return new_profiles
-
-
- def __iter__(self, include_hidden = False):
- for d in self.data.itervalues():
- for user in d.itervalues():
- user = max((chain,)((lambda .0: for u in .0:
- if not (u.hidden) or include_hidden:
- ucontinue)(user), iter([
- ZeroTime])), key = (lambda x: x.time))
- if user is not ZeroTime:
- yield user
- continue
-
-
-
-
-
- class Profile(NewsfeedItem):
-
- def __init__(self, user):
- NewsfeedItem.__init__(self, 'profile')
- self.time = int(user.profile_update_time)
- self.uid = int(user.uid)
- self.name = unicode(user.name)
- self.sex = unicode(user.sex)
-
-
-
- class WallNoteCounts(list):
-
- def __init__(self, counts_xml, time_ = None):
- list.__init__(self)
- (None, do)((lambda .0: for user in .0:
- self.append(WallNoteCount(user, time_)))(counts_xml))
- if self:
- t = self[0].time
- for user in self[1:]:
- user.time = t
-
-
-
-
-
- class WallNoteCount(object):
-
- def __init__(self, user, time_ = None):
- self.time = None if time_ is not None else int(user.anon)
- self.uid = int(user.uid)
- self.name = unicode(user.name)
- self.wall_count = None if getattr(user, 'wall_count', False) else -1
- self.notes_count = None if getattr(user, 'notes_count', False) else -1
- self.birthday = None if getattr(user, 'birthday', False) else None
-
-
-
- class FriendsWall(NewsfeedItem):
-
- def __init__(self, wall_note):
- NewsfeedItem.__init__(self, 'friends_wall')
- self.time = wall_note.time
- self.uid = wall_note.uid
- self.name = wall_note.name
- self.wall_count = wall_note.wall_count
-
-
- def __hash__(self):
- return hash(self.uid)
-
-
- def __cmp__(self, other):
- return cmp(self.uid, other.uid)
-
-
-
- class FriendsNotes(NewsfeedItem):
-
- def __init__(self, wall_note):
- NewsfeedItem.__init__(self, 'friends_notes')
- self.time = wall_note.time
- self.uid = wall_note.uid
- self.name = wall_note.name
- self.notes_count = wall_note.notes_count
-
-
- def __hash__(self):
- return hash(self.uid)
-
-
- def __cmp__(self, other):
- return cmp((self.uid, self.notes_count), (other.uid, other.notes_count))
-
-
-
- class Albums(NewsfeedList):
-
- def __init__(self, albums_xml):
- NewsfeedList.__init__(self)
- (do,)((lambda .0: for album in .0:
- self.append(Album(album)))(albums_xml))
- self.update_recent()
-
-
-
- class Album(NewsfeedItem):
-
- def __init__(self, album):
- NewsfeedItem.__init__(self, 'photos')
- self.time = None if album.modified else None
- self.link = unicode(album.link)
- self.aid = int(album.aid)
- self.name = unicode(album.name)
- self.owner = None if album.owner else None
-
-
- def __hash__(self):
- return hash(self.aid)
-
-
- def __cmp__(self, other):
- return cmp(self.aid, other.aid)
-
-
-
- class Photos(set):
-
- def __init__(self, photos_xml, time_ = None):
- set.__init__(self)
- (None, do)((lambda .0: for photo in .0:
- self.add(Photo(photo, time_)))(photos_xml))
-
-
-
- class Photo(object):
-
- def __init__(self, photo, time_ = None):
- self.pid = int(photo.pid)
- self.aid = int(photo.aid)
- self.owner = int(photo.owner)
- if photo.created:
- self.time = int(photo.created)
- elif time_ is not None:
- self.time = time_
- else:
- self.time = int(photo.anon)
-
-
- def __hash__(self):
- return hash(self.pid)
-
-
- def __cmp__(self, other):
- return cmp(self.pid, other.pid)
-
-
-
- class Tagged(NewsfeedItem):
-
- def __init__(self, album):
- NewsfeedItem.__init__(self, 'tagged')
- self.time = max((lambda .0: for x in .0:
- x.time)(album))
- self.count = len(album)
-
-
-
- class Wall(NewsfeedItem):
-
- def __init__(self, q):
- NewsfeedItem.__init__(self, 'your_wall')
- self.uid = int(q.user.uid)
- self.count = None if q.user.wall_count else None
- self.time = int(q.user.anon)
-
-
-
- class NewsFeed(ObservableList):
-
- def __init__(self):
- ObservableList.__init__(self)
- self.albums = defaultdict(dict)
- self.profiles = Profiles([])
- self.statuses = Statuses([])
- self.walls = []
- self.tags = defaultdict((lambda : defaultdict(set)))
- self.known_photos = set()
- self.album_names = { }
- self.friends_notes = set()
- self.friends_walls = defaultdict(dict)
- self.friends_walls_totals = { }
- self.fbtime = int(time.time())
- self.clock = self.fbtime
-
-
- def now(self):
- now = int(time.time())
- return (now - self.clock) + self.fbtime
-
- now = property(now)
-
- def get_aids(self):
- retval = set()
- for day, albums in self.tags.items():
- retval.update(albums.keys())
-
- return retval
-
-
- def get_unknown_aids(self):
- return self.get_aids() - set(self.album_names.keys())
-
-
- def get_unknown_album_owners(self):
- owners = set((lambda .0: for d in .0:
- for album in d.values():
- album.owner)(self.albums.values()))
- return owners - set(self.friends_walls_totals.keys())
-
-
- def update_aid_names(self, albums):
- if isinstance(albums, dict):
- for d in albums.values():
- for album in d.values():
- self.album_names[album.aid] = (album.name, album.link)
-
-
- elif isinstance(albums, list):
- for album in albums:
- self.album_names[album.aid] = (album.name, album.link)
-
-
-
-
- def rebuild(self):
- tags = []
- for day, albums in self.tags.items():
- for aid, s in albums.items():
- if max((lambda .0: for x in .0:
- x.time)(s)) != 0:
- t = Tagged(s)
- (t.album_name, t.link) = self.album_names[aid]
- tags.append(t)
- continue
-
-
- notes = _[1]
- fwalls = []
- for day, d in self.friends_walls.items():
- for wall in d.values():
- if wall.time != 0 and wall.wall_count > 0:
- fwalls.append(wall)
- continue
- []
-
-
- albums = []
- for d in self.albums.values():
- for album in d.values():
- album.owner_name = self.friends_walls_totals[album.owner].name
- albums.append(album)
-
-
- profiles = [ profile for profile in self.profiles ]
- statuses = _[3]
- self[:] = sorted(albums + profiles + statuses + self.walls[1:] + tags + notes + fwalls, key = (lambda x: x.time), reverse = True)
- log.info('finished rebuild')
-
-
- def update_albums(self, albums, rebuild = False):
- for a in albums:
- atime = date.fromtimestamp(a.time)
- if a.aid not in self.albums[atime] or self.albums[atime][a.aid].time <= a.time:
- self.albums[atime][a.aid] = a
- continue
-
- self.update_aid_names(self.albums)
- if rebuild:
- self.rebuild()
-
-
-
- def update_profiles(self, profiles):
- return self.profiles.update(profiles)
-
-
- def init_tags(self, photos):
- for photo in photos:
- self.tags[date.fromtimestamp(photo.time)][photo.aid].add(photo)
-
- self.known_photos.update(photos)
-
-
- def update_tags(self, photos, rebuild = False):
- new_photos = set(photos) - self.known_photos
- for photo in new_photos:
- if photo not in self.tags[date.fromtimestamp(photo.time)][photo.aid]:
- self.tags[date.fromtimestamp(photo.time)][photo.aid].add(photo)
- continue
-
- self.known_photos.update(new_photos)
- if rebuild:
- self.rebuild()
-
-
-
- def update_statuses(self, statuses, rebuild = False):
- self.statuses.extend(statuses)
- if rebuild:
- self.rebuild()
-
-
-
- def update_counts(self, wall_note_counts):
- notes = []([ FriendsNotes(c) for c in wall_note_counts ])
- new_notes = notes - self.friends_notes
- self.friends_notes |= new_notes
- new_walls = [ FriendsWall(c) for c in wall_note_counts ]
- new_walls = _[3]
- for wall in new_walls:
- self.friends_walls[date.fromtimestamp(wall.time)][wall.uid] = wall
- self.friends_walls_totals[wall.uid] = wall
-
- return (new_walls, new_notes)
-
-
- def update_wall(self, wall, rebuild = False):
- self.fbtime = wall.time
- self.clock = int(time.time())
- if wall.count is None:
- return None
-
- if self.walls:
- if wall.count > self.walls[-1].count:
- if date.fromtimestamp(self.walls[-1].time) == date.fromtimestamp(wall.time):
- self.walls[-1] = wall
- else:
- self.walls.append(wall)
- if rebuild:
- self.rebuild()
-
-
- else:
- wall.time = 0
- self.walls.append(wall)
-
-
- def __iter__(self):
- stuff = self[:]
- date = date
- import datetime
- last = False
- now = self.now
- today = date.fromtimestamp(now)
- yesterday = date.fromtimestamp(now - 86400)
- for thing in stuff:
- this = date.fromtimestamp(thing.time)
- if not last and this != today:
- yield None
-
- if not last and this == today:
- pass
- elif last == this:
- pass
- elif this == yesterday:
- yield 'Yesterday'
- else:
- yield strftime_u(this, '%B %d')
- yield thing
- last = this
-
-
-
-