def create_follow_activity(owner, other_user): """ owner started following other_user Both owner and other_user gets a new activity """ target = simplejson.dumps(get_youtify_user_struct(other_user)) actor = simplejson.dumps(get_youtify_user_struct(owner)) m = Activity(owner=owner, verb='follow', actor=actor, target=target, type='outgoing') m.put() m = Activity(owner=other_user, verb='follow', actor=actor, target=target, type='incoming') m.put()
def get(self): q = self.request.get('q') ret = [] for m in YoutifyUser.all().search(q, properties=['nickname', 'flattr_user_name', 'first_name', 'last_name', 'tagline']): ret.append(get_youtify_user_struct(m)) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(ret))
def get(self): """Get the currnet user, incuding private data""" user = get_current_youtify_user_model() if user: json = get_youtify_user_struct(user, include_private_data=True) else: json = {} self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(json))
def get(self): """Get the currnet user, incuding private data""" user = get_current_youtify_user_model() if user: json = get_youtify_user_struct(user, include_private_data=True) else: json = {} self.response.headers["Content-Type"] = "application/json" self.response.out.write(simplejson.dumps(json))
def create_signup_activity(youtify_user_model): target = simplejson.dumps({}) actor = simplejson.dumps(get_youtify_user_struct(youtify_user_model)) m = Activity(owner=youtify_user_model, verb='signup', actor=actor, target=target, type='outgoing') m.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, playlist_id): """Gets the list of users that follow a playlist""" playlist_model = Playlist.get_by_id(int(playlist_id)) json = [] for key in playlist_model.followers: youtify_user_model = db.get(key) json.append(get_youtify_user_struct(youtify_user_model)) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(json))
def get(self, playlist_id): """Gets the list of users that follow a playlist""" playlist_model = Playlist.get_by_id(int(playlist_id)) json = [] for key in playlist_model.followers: youtify_user_model = db.get(key) json.append(get_youtify_user_struct(youtify_user_model)) self.response.headers["Content-Type"] = "application/json" self.response.out.write(simplejson.dumps(json))
def get(self, type, external_user_id): """Gets the subscribers of an external user""" external_user_model = ExternalUser.all().filter('type =', type).filter('external_user_id =', external_user_id).get() json = [] if external_user_model is not None: for key in external_user_model.subscribers: youtify_user_model = db.get(key) json.append(get_youtify_user_struct(youtify_user_model)) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(json))
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 create_subscribe_activity(youtify_user_model, playlist_model): """ user subscribed to playlist Both user and playlists owner gets a new activity """ target = simplejson.dumps(get_playlist_struct_from_playlist_model(playlist_model)) actor = simplejson.dumps(get_youtify_user_struct(youtify_user_model)) m = Activity(owner=youtify_user_model, verb='subscribe', actor=actor, target=target, type='outgoing') m.put() m = Activity(owner=playlist_model.owner, verb='subscribe', actor=actor, target=target, type='incoming') m.put()
def get(self, type, external_user_id): """Gets the subscribers of an external user""" external_user_model = ExternalUser.all().filter('type =', type).filter( 'external_user_id =', external_user_id).get() json = [] if external_user_model is not None: for key in external_user_model.subscribers: youtify_user_model = db.get(key) json.append(get_youtify_user_struct(youtify_user_model)) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(json))
def get(self, id_or_nick): """Get user as JSON""" youtify_user_model = get_youtify_user_model_by_id_or_nick(id_or_nick) youtify_user_struct = None if youtify_user_model is None: self.error(404) return youtify_user_struct = get_youtify_user_struct(youtify_user_model) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(youtify_user_struct))
def get(self): my_followers_struct = [] my_followings_struct = [] settings_struct = {} youtify_user_struct = None current_user = users.get_current_user() youtify_user_model = get_current_youtify_user_model() if (current_user is not None) and (youtify_user_model is None): youtify_user_model = create_youtify_user_model() if youtify_user_model is not None: youtify_user_model.device = generate_device_token() youtify_user_model.last_login = datetime.now() youtify_user_struct = get_youtify_user_struct(youtify_user_model, include_private_data=True) # https://developers.google.com/appengine/docs/python/runtime#Request_Headers youtify_user_model.country = self.request.headers.get('X-AppEngine-Country', None) youtify_user_model.reqion = self.request.headers.get('X-AppEngine-Region', None) youtify_user_model.city = self.request.headers.get('X-AppEngine-City', None) youtify_user_model.latlon = self.request.headers.get('X-AppEngine-CityLatLong', None) youtify_user_model.save() my_followers_struct = get_followers_for_youtify_user_model(youtify_user_model) my_followings_struct = get_followings_for_youtify_user_model(youtify_user_model) settings_struct = get_settings_struct_for_youtify_user_model(youtify_user_model) lang_code = auto_detect_language(self.request) json = { 'ON_PRODUCTION': config.ON_PRODUCTION, 'SEARCH_STATS_URL': config.SEARCH_STATS_URL, 'languagesFromServer': [lang for lang in get_languages() if lang['enabled_on_site']], 'device': youtify_user_model is not None and youtify_user_model.device, 'user': youtify_user_struct, 'lastNotificationSeenTimestamp': youtify_user_model is not None and youtify_user_model.last_notification_seen_timestamp, 'myFollowers': my_followers_struct, 'myFollowings': my_followings_struct, 'settingsFromServer': settings_struct, 'autoDetectedLanguageByServer': lang_code, 'autoDetectedTranslations': get_deployed_translations_struct(lang_code), 'loginUrl': users.create_login_url('/'), 'logoutUrl': users.create_logout_url('/'), } self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(json));
def get(self): q = self.request.get('q').strip(' \t\n\r') if len(q) < 3: self.response.headers['Content-Type'] = 'application/json' self.response.out.write('[]') return ret = [] for m in YoutifyUser.all().search(q, properties=[ 'nickname', 'flattr_user_name', 'first_name', 'last_name', 'tagline' ]).fetch(30): ret.append(get_youtify_user_struct(m)) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(ret))
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 create_subscribe_activity(youtify_user_model, playlist_model): """ user subscribed to playlist Both user and playlists owner gets a new activity """ target = simplejson.dumps( get_playlist_struct_from_playlist_model(playlist_model)) actor = simplejson.dumps(get_youtify_user_struct(youtify_user_model)) m = Activity(owner=youtify_user_model, verb='subscribe', actor=actor, target=target, type='outgoing') m.put() m = Activity(owner=playlist_model.owner, verb='subscribe', actor=actor, target=target, type='incoming') m.put()
def get(self): current_user = users.get_current_user() youtify_user_model = get_current_youtify_user_model() youtify_user_struct = None playlists_struct = [] my_followers_struct = [] my_followings_struct = [] settings_struct = {} if (current_user is not None) and (youtify_user_model is None): youtify_user_model = create_youtify_user_model() if youtify_user_model is not None: youtify_user_model.device = str(random.random()) youtify_user_model.last_login = datetime.now() # https://developers.google.com/appengine/docs/python/runtime#Request_Headers youtify_user_model.country = self.request.headers.get('X-AppEngine-Country', None) youtify_user_model.reqion = self.request.headers.get('X-AppEngine-Region', None) youtify_user_model.city = self.request.headers.get('X-AppEngine-City', None) youtify_user_model.latlon = self.request.headers.get('X-AppEngine-CityLatLong', None) youtify_user_model.save() youtify_user_struct = get_youtify_user_struct(youtify_user_model, include_private_data=True) playlists_struct = get_playlist_structs_for_youtify_user_model(youtify_user_model, include_private_playlists=True) my_followers_struct = get_followers_for_youtify_user_model(youtify_user_model) my_followings_struct = get_followings_for_youtify_user_model(youtify_user_model) settings_struct = get_settings_struct_for_youtify_user_model(youtify_user_model) ON_PRODUCTION = os.environ['SERVER_SOFTWARE'].startswith('Google App Engine') # http://stackoverflow.com/questions/1916579/in-python-how-can-i-test-if-im-in-google-app-engine-sdk # Find videotag and generate open graph meta tags match = re.compile(r'tracks/youtube/(.*)').search(self.request.url) if match: og_tag = '<meta property="og:video" content="http://www.youtube.com/v/' + match.groups()[0] + '?version=3&autohide=1"/><meta property="og:video:type" content="application/x-shockwave-flash"/><meta property="og:video:width" content="396"/><meta property="og:video:height" content="297"/>' else: og_tag = '' # TODO add og_tag for SoundCloud & Official.fm tracks lang = auto_detect_language(self.request) path = os.path.join(os.path.dirname(__file__), 'html', 'index.html') self.response.headers['Content-Type'] = 'text/html; charset=utf-8'; self.response.out.write(template.render(path, { 'my_user_id': youtify_user_model is not None and youtify_user_model.key().id(), 'device': youtify_user_model is not None and youtify_user_model.device, 'USER': simplejson.dumps(youtify_user_struct), 'playlistsFromServer': simplejson.dumps(playlists_struct), 'myFollowers': simplejson.dumps(my_followers_struct), 'myFollowings': simplejson.dumps(my_followings_struct), 'settingsFromServer': simplejson.dumps(settings_struct), 'autoDetectedLanguageByServer': lang, 'autoDetectedTranslations': get_deployed_translations_json(lang), 'logged_in': int(current_user is not None), 'has_flattr_access_token': int(youtify_user_model is not None and youtify_user_model.flattr_access_token is not None), 'flattr_user_name': youtify_user_model is not None and youtify_user_model.flattr_user_name, 'login_url': users.create_login_url('/'), 'logout_url': users.create_logout_url('/'), 'youtubeTopList': get_youtube_toplist_json(), 'flattrTopList': get_flattr_toplist_json(), 'CURRENT_VERSION_ID': os.environ['CURRENT_VERSION_ID'], 'ON_PRODUCTION': ON_PRODUCTION, 'ON_DEV': ON_PRODUCTION is False, 'USE_PRODUCTION_JAVASCRIPT': ON_PRODUCTION, 'languages': [lang for lang in get_languages() if lang['enabled_on_site']], #'USE_PRODUCTION_JAVASCRIPT': True, # Uncomment to try out production settings. Remember to build production.js with localhost:8080/minimizer 'url': self.request.url, 'og_tag': og_tag, }))
def get(self): user = get_current_youtify_user_model() self.response.headers['Content-Type'] = 'application/json' self.response.out.write( simplejson.dumps( get_youtify_user_struct(get_current_youtify_user_model())))
def get(self): my_followers_struct = [] my_followings_struct = [] settings_struct = {} youtify_user_struct = None current_user = users.get_current_user() youtify_user_model = get_current_youtify_user_model() if (current_user is not None) and (youtify_user_model is None): youtify_user_model = create_youtify_user_model() if youtify_user_model is not None: youtify_user_model.device = generate_device_token() youtify_user_model.last_login = datetime.now() youtify_user_struct = get_youtify_user_struct( youtify_user_model, include_private_data=True) # https://developers.google.com/appengine/docs/python/runtime#Request_Headers youtify_user_model.country = self.request.headers.get( 'X-AppEngine-Country', None) youtify_user_model.reqion = self.request.headers.get( 'X-AppEngine-Region', None) youtify_user_model.city = self.request.headers.get( 'X-AppEngine-City', None) youtify_user_model.latlon = self.request.headers.get( 'X-AppEngine-CityLatLong', None) youtify_user_model.save() my_followers_struct = get_followers_for_youtify_user_model( youtify_user_model) my_followings_struct = get_followings_for_youtify_user_model( youtify_user_model) settings_struct = get_settings_struct_for_youtify_user_model( youtify_user_model) lang_code = auto_detect_language(self.request) json = { 'ON_PRODUCTION': config.ON_PRODUCTION, 'SEARCH_STATS_URL': config.SEARCH_STATS_URL, 'languagesFromServer': get_languages(), 'device': youtify_user_model is not None and youtify_user_model.device, 'user': youtify_user_struct, 'lastNotificationSeenTimestamp': youtify_user_model is not None and youtify_user_model.last_notification_seen_timestamp, 'myFollowers': my_followers_struct, 'myFollowings': my_followings_struct, 'settingsFromServer': settings_struct, 'autoDetectedLanguageByServer': lang_code, 'autoDetectedTranslations': get_translations_for_lang(lang_code), 'loginUrl': users.create_login_url('/'), 'logoutUrl': users.create_logout_url('/'), } self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(json))
def get(self): user = get_current_youtify_user_model() self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(get_youtify_user_struct(get_current_youtify_user_model())))