def post(self, uid): other_user = YoutifyUser.get_by_id(int(uid)) me = get_current_youtify_user_model() if other_user is None: self.error(400) self.response.out.write('Other user not found') return if me.key().id() == other_user.key().id(): self.error(400) self.response.out.write('You can not follow yourself') return if FollowRelation.all().filter('user1 =', me).filter('user2 =', other_user).get(): self.error(400) self.response.out.write('You already follow that user') return me.nr_of_followings += 1 other_user.nr_of_followers += 1 me.save() other_user.save() m = FollowRelation(user1=me.key().id(), user2=other_user.key().id()) m.put() create_follow_activity(me, other_user) send_new_follower_email(me, other_user) self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('ok')
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 try: stats.nr_of_playlists = Playlist.all(keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY) except: pass stats.nr_of_users_with_flattr_account = 0 stats.nr_of_users_with_dropbox = 0 try: stats.nr_of_flattrs = Activity.all().filter('type =', 'outgoing').filter('verb =', 'flattr').count(read_policy=EVENTUAL_CONSISTENCY) except: pass stats.nr_of_playlist_subscriptions = 0 try: stats.nr_of_follow_relations = FollowRelation.all(keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY) except: pass try: for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.dropbox_user_name: stats.nr_of_users_with_dropbox += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 except: pass pings = [] last_ping = None try: for m in PingStats.all().order('-date').fetch(6*24*7): if last_ping is not None and last_ping.date.hour is not m.date.hour: pings.append({ 'date': str(last_ping.date), 'pings': last_ping.pings }) last_ping = m elif last_ping is None or m.pings > last_ping.pings: last_ping = m except: pass stats.pings = simplejson.dumps(pings) stats.put()
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 stats.nr_of_playlists = len([i for i in Playlist.all()]) stats.nr_of_users_with_flattr_account = 0 stats.nr_of_flattrs = 0 stats.nr_of_playlist_subscriptions = 0 stats.nr_of_follow_relations = len([i for i in FollowRelation.all()]) for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 stats.nr_of_flattrs += len([i for i in Activity.all().filter('owner =', user).filter('verb =', 'flattr')]) stats.put()
def create_external_subscribe_activity(youtify_user_model, external_user_model): target = simplejson.dumps(get_external_user_subscription_struct(external_user_model)) actor = simplejson.dumps(get_youtify_user_struct(youtify_user_model)) m = Activity(owner=youtify_user_model, verb='external_subscribe', actor=actor, target=target, type='outgoing') m.put() for relation in FollowRelation.all().filter('user2 =', youtify_user_model.key().id()): m = Activity(owner=YoutifyUser.get_by_id(relation.user1), verb='external_subscribe', actor=actor, target=target, type='incoming') m.put()
def get(self): page = int(self.request.get('page', '0')) page_size = 30 ret = [] count = 0 for m in YoutifyUser.all().fetch(page_size, page_size * page): count += 1 m.nr_of_followers = FollowRelation.all().filter('user2 =', m.key().id()).count() m.nr_of_followings = FollowRelation.all().filter('user1 =', m.key().id()).count() m.save() self.response.headers['Content-Type'] = 'text/html' if (count < page_size): self.response.out.write(COMPLETE) else: self.response.out.write(Template(TEMPLATE).substitute({ 'progress': page_size * page, 'next': page + 1, }))
def create_flattr_activity(youtify_user_model, thing_id, thing_title): target = simplejson.dumps({ 'thing_id': thing_id, 'thing_title': thing_title, }) actor = simplejson.dumps(get_youtify_user_struct(youtify_user_model)) m = Activity(owner=youtify_user_model, verb='flattr', actor=actor, target=target, type='outgoing') m.put() for relation in FollowRelation.all().filter('user2 =', youtify_user_model.key().id()): m = Activity(owner=YoutifyUser.get_by_id(relation.user1), verb='flattr', actor=actor, target=target, type='incoming') m.put()
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 stats.nr_of_playlists = len([i for i in Playlist.all()]) stats.nr_of_users_with_flattr_account = 0 stats.nr_of_flattrs = len([ i for i in Activity.all().filter('type =', 'outgoing').filter( 'verb =', 'flattr') ]) stats.nr_of_playlist_subscriptions = 0 stats.nr_of_follow_relations = len([i for i in FollowRelation.all()]) for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len( user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 pings = [] last_ping = None for m in PingStats.all().order('-date').fetch(6 * 24 * 7): if last_ping is not None and last_ping.date.hour is not m.date.hour: pings.append({ 'date': str(last_ping.date), 'pings': last_ping.pings }) last_ping = m elif last_ping is None or m.pings > last_ping.pings: last_ping = m stats.pings = simplejson.dumps(pings) stats.put()
def delete(self, uid): me = get_current_youtify_user_model() other_user = get_youtify_user_model_by_id_or_nick(uid) if other_user is None: self.error(400) self.response.out.write('Other user not found') return m = FollowRelation.all().filter('user1 =', me.key().id()).filter('user2 =', int(uid)).get() if m: m.delete() me.nr_of_followings -= 1 other_user.nr_of_followers -= 1 me.save() other_user.save() self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('ok')
def create_external_subscribe_activity(youtify_user_model, external_user_model): target = simplejson.dumps( get_external_user_subscription_struct(external_user_model)) actor = simplejson.dumps(get_youtify_user_struct(youtify_user_model)) m = Activity(owner=youtify_user_model, verb='external_subscribe', actor=actor, target=target, type='outgoing') m.put() for relation in FollowRelation.all().filter('user2 =', youtify_user_model.key().id()): m = Activity(owner=YoutifyUser.get_by_id(relation.user1), verb='external_subscribe', actor=actor, target=target, type='incoming') m.put()
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 stats.nr_of_playlists = len([i for i in Playlist.all()]) stats.nr_of_users_with_flattr_account = 0 stats.nr_of_flattrs = len([i for i in Activity.all().filter('type =', 'outgoing').filter('verb =', 'flattr')]) stats.nr_of_playlist_subscriptions = 0 stats.nr_of_follow_relations = len([i for i in FollowRelation.all()]) for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len(user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 pings = [] last_ping = None for m in PingStats.all().order('-date').fetch(6*24*7): if last_ping is not None and last_ping.date.hour is not m.date.hour: pings.append({ 'date': str(last_ping.date), 'pings': last_ping.pings }) last_ping = m elif last_ping is None or m.pings > last_ping.pings: last_ping = m stats.pings = simplejson.dumps(pings) stats.put()
def delete(self, uid): me = get_current_youtify_user_model() other_user = get_youtify_user_model_by_id_or_nick(uid) if other_user is None: self.error(400) self.response.out.write('Other user not found') return m = FollowRelation.all().filter('user1 =', me.key().id()).filter( 'user2 =', int(uid)).get() if m: m.delete() me.nr_of_followings -= 1 other_user.nr_of_followers -= 1 me.save() other_user.save() self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('ok')
def get(self): stats = Stats() stats.nr_of_users = 0 stats.nr_of_active_users = 0 try: stats.nr_of_playlists = Playlist.all(keys_only=True).count( read_policy=EVENTUAL_CONSISTENCY) except: pass stats.nr_of_users_with_flattr_account = 0 stats.nr_of_users_with_dropbox = 0 try: stats.nr_of_flattrs = Activity.all().filter( 'type =', 'outgoing').filter( 'verb =', 'flattr').count(read_policy=EVENTUAL_CONSISTENCY) except: pass stats.nr_of_playlist_subscriptions = 0 try: stats.nr_of_follow_relations = FollowRelation.all( keys_only=True).count(read_policy=EVENTUAL_CONSISTENCY) except: pass try: for user in YoutifyUser.all(): stats.nr_of_users += 1 if user.flattr_user_name: stats.nr_of_users_with_flattr_account += 1 if user.dropbox_user_name: stats.nr_of_users_with_dropbox += 1 if user.playlist_subscriptions: stats.nr_of_playlist_subscriptions += len( user.playlist_subscriptions) if user.last_login: delta = datetime.now() - user.last_login if delta.seconds < 3600 * 24 * 7: stats.nr_of_active_users += 1 except: pass pings = [] last_ping = None try: for m in PingStats.all().order('-date').fetch(6 * 24 * 7): if last_ping is not None and last_ping.date.hour is not m.date.hour: pings.append({ 'date': str(last_ping.date), 'pings': last_ping.pings }) last_ping = m elif last_ping is None or m.pings > last_ping.pings: last_ping = m except: pass stats.pings = simplejson.dumps(pings) stats.put()