def disco(): show = Show.get_active_show() ret = {} if show: user = show.get_active_user() ret['countryball'] = iso_country_to_countryball(user.country) ret['logo'] = show.get_logo(), else: ret['countryball'] = False ret['logo'] = False track = Track.current_track() if track: ret['track'] = { 'title': track.title.name, 'artist': track.title.artist.name, } #get listenerinfo for disco listeners = Listener.get_current_listeners() ret['listener'] = {} for listener in listeners: ret['listener'][listener.listener] = { 'listener': listener.listener, 'county': listener.country, 'countryball': iso_country_to_countryball(listener.country) } return ret
def now_playing(): try: ret = {} #gather showinfos show = Show.get_active_show() if show: user = show.get_active_user() if show.end: end = to_timestamp(to_user_timezone(show.end)) else: end = None ret['show'] = {'id': show.show, 'name': show.name, 'begin': to_timestamp(to_user_timezone(show.begin)), 'now': to_timestamp(to_user_timezone(now())), 'end': end, 'logo': show.get_logo(), 'type': Show.FLAGS.name(show.flags), 'user': {'countryball': iso_country_to_countryball(user.country)} } if show.series: ret['series'] = {'name': show.series.name} link_users = [] for ushow in show.users: link_users.append(make_user_link(ushow.user)) ret['users'] = {'links': natural_join(link_users)} #gather trackinfos track = Track.current_track() if track: ret['track'] = {'title': track.title.name, 'artist': track.title.artist.name, } #gather nextshow infos if show and show.end: filter_begin = show.end else: filter_begin = now() if request.args.get('full') == 'true': nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(Show.begin.asc()).first(); if nextshow: ret['nextshow'] = {'name': nextshow.name, 'begin': to_timestamp(to_user_timezone(nextshow.begin)), 'logo': nextshow.get_logo()} if nextshow.series: ret['nextshow']['series'] = nextshow.series.name #get listenerinfo for disco listeners = Listener.get_current_listeners() ret['listener'] = {} for listener in listeners: ret['listener'][listener.listener] = {'listener': listener.listener, 'county': listener.country, 'countryball': iso_country_to_countryball(listener.country)} return jsonify({'success': True, 'data': ret}) except Exception as e: raise e return jsonify({'success': False, 'data': unicode(e)})
def listeners(): # get current bandwidth of all active relays total_bandwidth = 0 relays = Relay.query.filter(Relay.status == Relay.STATUS.ONLINE).all() active_relays = len(relays) for relay in relays: total_bandwidth += relay.usage total_bandwidth *= 128 # convert kbit to byte # get all current listeners current_listener = Listener.get_current_listeners() # generate per country stats per_country = {} for listener in current_listener: country = listener.country try: per_country[country]['count'] += 1 except KeyError: per_country[country] = {'count': 1} per_country[country]['ball'] = iso_country_to_countryball(country) per_country = sorted(per_country.iteritems(), key=lambda (k, v): v['count'], reverse=True) return render_template('listenergraph.html', TITLE='Listeners', listeners=current_listener, per_country=per_country, total_bandwidth=total_bandwidth, active_relays=active_relays)
def now_playing(): try: ret = {} #gather showinfos show = Show.get_active_show() if show: user = show.get_active_user() if show.end: end = int(to_user_timezone(show.end).strftime("%s")) * 1000 else: end = None ret['show'] = { 'id': show.show, 'name': show.name, 'begin': int(to_user_timezone(show.begin).strftime("%s")) * 1000, 'now': int(to_user_timezone(now()).strftime("%s")) * 1000, 'end': end, 'logo': show.get_logo(), 'type': Show.FLAGS.name(show.flags), 'user': { 'countryball': iso_country_to_countryball(user.country) } } if show.series: ret['series'] = {'name': show.series.name} link_users = [] for ushow in show.users: link_users.append(make_user_link(ushow.user)) ret['users'] = {'links': natural_join(link_users)} #gather nextshow infos if show and show.end: filter_begin = show.end else: filter_begin = now() if request.args.get('full') == 'true': nextshow = Show.query.filter(Show.begin >= filter_begin).order_by( Show.begin.asc()).first() if nextshow: ret['nextshow'] = { 'name': nextshow.name, 'begin': int(to_user_timezone(nextshow.begin).strftime("%s")) * 1000, 'logo': nextshow.get_logo() } if nextshow.series: ret['nextshow']['series'] = nextshow.series.name return jsonify({'success': True, 'data': ret}) except Exception as e: raise e return jsonify({'success': False, 'data': unicode(e)})
def disco(): show = Show.get_active_show() ret = {} if show: user = show.get_active_user() ret['countryball'] = iso_country_to_countryball(user.country) ret['logo'] = show.get_logo(), else: ret['countryball'] = False ret['logo'] = False track = Track.current_track() if track: ret['track'] = {'title': track.title.name, 'artist': track.title.artist.name, } #get listenerinfo for disco listeners = Listener.get_current_listeners() ret['listener'] = {} for listener in listeners: ret['listener'][listener.listener] = {'listener': listener.listener, 'county': listener.country, 'countryball': iso_country_to_countryball(listener.country)} return ret
def info(user): user = User.get_user(username=user) upcoming_shows = Show.query.join(UserShow).filter(UserShow.user == user, Show.begin >= now()).order_by( Show.begin.asc()).limit(5).all() last_shows = Show.query.join(UserShow).filter(UserShow.user == user, Show.end <= now()).order_by( Show.end.desc()).limit(5).all() if user: ball = iso_country_to_countryball(user.country) return render_template('user/info.html', username=user.username, ball=ball, st=user.get_total_streamtime(), shows={'upcoming': upcoming_shows, 'last': last_shows}) else: abort(404)
def now_playing(): try: ret = {} #gather showinfos show = Show.get_active_show() if show: user = show.get_active_user() if show.end: end = int(to_user_timezone(show.end).strftime("%s")) * 1000 else: end = None ret['show'] = {'id': show.show, 'name': show.name, 'begin': int(to_user_timezone(show.begin).strftime("%s")) * 1000, 'now': int(to_user_timezone(now()).strftime("%s")) * 1000, 'end': end, 'logo': show.get_logo(), 'type': Show.FLAGS.name(show.flags), 'user': {'countryball': iso_country_to_countryball(user.country)} } if show.series: ret['series'] = {'name': show.series.name} link_users = [] for ushow in show.users: link_users.append(make_user_link(ushow.user)) ret['users'] = {'links': natural_join(link_users)} #gather nextshow infos if show and show.end: filter_begin = show.end else: filter_begin = now() if request.args.get('full') == 'true': nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(Show.begin.asc()).first(); if nextshow: ret['nextshow'] = {'name': nextshow.name, 'begin': int(to_user_timezone(nextshow.begin).strftime("%s")) * 1000, 'logo': nextshow.get_logo()} if nextshow.series: ret['nextshow']['series'] = nextshow.series.name return jsonify({'success': True, 'data': ret}) except Exception as e: raise e return jsonify({'success': False, 'data': unicode(e)})