def test_transition_planned_unplanned(self):
     self.test_init_show_planned()
     show = Show.get_active_show()
     show.end = show.end - timedelta(minutes=15)
     rfk.database.session.commit()
     liquidsoaphandler.init_show(self.user)
     self.assertNotEqual(show, Show.get_active_show())
     self.assertEqual(Show.get_active_show().flags & Show.FLAGS.UNPLANNED, Show.FLAGS.UNPLANNED)
예제 #2
0
 def test_transition_planned_unplanned(self):
     self.test_init_show_planned()
     show = Show.get_active_show()
     show.end = show.end - timedelta(minutes=15)
     rfk.database.session.commit()
     liquidsoaphandler.init_show(self.user)
     self.assertNotEqual(show, Show.get_active_show())
     self.assertEqual(Show.get_active_show().flags & Show.FLAGS.UNPLANNED,
                      Show.FLAGS.UNPLANNED)
 def test_init_show_planned(self):
     begin = now()-timedelta(minutes=10)
     end = now()+timedelta(minutes=10)
     show = Show(begin=begin,
                 end=end,
                 name='titel',
                 description='description',
                 flags=Show.FLAGS.PLANNED)
     rfk.database.session.add(show)
     rfk.database.session.flush()
     show.add_user(self.user)
     rfk.database.session.commit()
     self.test_do_connect_valid_user()
     self.assertEqual(show, show.get_active_show())
     self.assertEqual(Show.get_active_show().flags & Show.FLAGS.PLANNED, Show.FLAGS.PLANNED)
예제 #4
0
파일: helper.py 프로젝트: keios/PyRfK
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
예제 #5
0
 def test_init_show_planned(self):
     begin = now() - timedelta(minutes=10)
     end = now() + timedelta(minutes=10)
     show = Show(begin=begin,
                 end=end,
                 name='titel',
                 description='description',
                 flags=Show.FLAGS.PLANNED)
     rfk.database.session.add(show)
     rfk.database.session.flush()
     show.add_user(self.user)
     rfk.database.session.commit()
     self.test_do_connect_valid_user()
     self.assertEqual(show, show.get_active_show())
     self.assertEqual(Show.get_active_show().flags & Show.FLAGS.PLANNED,
                      Show.FLAGS.PLANNED)
예제 #6
0
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)})
예제 #7
0
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)})
예제 #8
0
 def test_transition_unplanned_planned(self):
     self.test_init_show_unplanned()
     show = Show.get_active_show()
     show.begin = show.begin - timedelta(minutes=5)
     rfk.database.session.commit()
     begin = now() - timedelta(minutes=3)
     end = now() + timedelta(minutes=10)
     show = Show(begin=begin,
                 end=end,
                 name='titel2',
                 description='description2',
                 flags=Show.FLAGS.PLANNED)
     rfk.database.session.add(show)
     rfk.database.session.flush()
     show.add_user(self.other_user)
     rfk.database.session.commit()
     self.test_do_metadata()
     self.assertEqual(Show.get_active_show(), show)
 def test_transition_unplanned_planned(self):
     self.test_init_show_unplanned()
     show = Show.get_active_show()
     show.begin = show.begin - timedelta(minutes=5)
     rfk.database.session.commit()
     begin = now()-timedelta(minutes=3)
     end = now()+timedelta(minutes=10)
     show = Show(begin=begin,
                 end=end,
                 name='titel2',
                 description='description2',
                 flags=Show.FLAGS.PLANNED)
     rfk.database.session.add(show)
     rfk.database.session.flush()
     show.add_user(self.other_user)
     rfk.database.session.commit()
     self.test_do_metadata()
     self.assertEqual(Show.get_active_show(), show)
예제 #10
0
파일: helper.py 프로젝트: keios/PyRfK
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)})
예제 #11
0
파일: helper.py 프로젝트: buckket/PyRfK
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)})
예제 #12
0
파일: helper.py 프로젝트: buckket/PyRfK
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
예제 #13
0
 def test_disconnect(self):
     liquidsoaphandler.doDisconnect(1)
     self.assertEqual(Show.get_active_show(), None)
     self.assertEqual(Track.current_track(), None)
예제 #14
0
 def test_disconnect(self):
     liquidsoaphandler.doDisconnect(1)
     self.assertEqual(Show.get_active_show(), None)
     self.assertEqual(Track.current_track(), None)
예제 #15
0
 def test_init_show_unplanned(self):
     self.test_do_connect_valid_user()
     self.test_do_metadata()
     self.assertEqual(Show.get_active_show().flags & Show.FLAGS.UNPLANNED, Show.FLAGS.UNPLANNED)
예제 #16
0
def api_legacy():
    '''lazy people...'''

    apikey = request.args.get("apikey")
    if apikey != '86c6c5162aa6845906cff55320ea8608991358c3':
        return ''

    #ltid=0&w=track%2Clistener%2Cdj%2Cshow%2Cnextshows,
    ret = {}
    listeners = Listener.query.filter(Listener.disconnect == None).all()
    tmp = {}
    for listener in listeners:
        if listener.stream_relay.stream.code in tmp:
            tmp[listener.stream_relay.stream.code]['c'] += 1
        else:
            tmp[listener.stream_relay.stream.code] = {'c': 1,
                                                      'name': listener.stream_relay.stream.code,
                                                      'description': listener.stream_relay.stream.name}
    ret['listener'] = tmp.values()

    currtrack = Track.current_track()
    ltid = request.args.get("apikey")
    if currtrack and ltid != currtrack.track:
        ret['trackid'] = currtrack.track
        ret['title'] = currtrack.title.name
        ret['artist'] = currtrack.title.artist.name

    show = Show.get_active_show()
    if show:
        user = show.get_active_user()
        ret['dj'] = user.username
        ret['djid'] = user.user
        ret['status'] = 'STREAMING'
        ret['showbegin'] = int(to_user_timezone(show.begin).strftime("%s"))
        if show.end:
            ret['showend'] = int(to_user_timezone(show.end).strftime("%s"))
        else:
            ret['showend'] = None
        ret['showtype'] = 'PLANNED';
        ret['showname'] = show.name
        ret['showdescription'] = show.description
        ret['showid'] = show.show
        ret['showthread'] = None;
        ret['showdj'] = user.username
        ret['showdjid'] = user.user

    ret['shows'] = []
    if show and show.end:
        filter_begin = show.end
    else:
        filter_begin = now()
    nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(Show.begin.asc()).first()
    if nextshow:
        arr = {}
        arr['showbegin'] = int(to_user_timezone(nextshow.begin).strftime("%s"))
        if nextshow.end:
            arr['showend'] = int(to_user_timezone(nextshow.end).strftime("%s"))
        else:
            arr['showend'] = None
        arr['showtype'] = 'PLANNED';
        arr['showname'] = nextshow.name;
        arr['showdescription'] = nextshow.description;
        arr['showid'] = nextshow.show;
        arr['showdj'] = nextshow.users[0].user.username;
        arr['showdjid'] = nextshow.users[0].user.user;
        arr['showthread'] = None;
        ret['shows'].append(arr)

    return jsonify(ret)
예제 #17
0
파일: __init__.py 프로젝트: keios/PyRfK
def api_legacy():
    '''lazy people...'''

    apikey = request.args.get("apikey")
    if apikey != '86c6c5162aa6845906cff55320ea8608991358c3':
        return ''

    #ltid=0&w=track%2Clistener%2Cdj%2Cshow%2Cnextshows,
    ret = {}
    listeners = Listener.query.filter(Listener.disconnect == None).all()
    tmp = {}
    for listener in listeners:
        if listener.stream_relay.stream.code in tmp:
            tmp[listener.stream_relay.stream.code]['c'] += 1
        else:
            tmp[listener.stream_relay.stream.code] = {
                'c': 1,
                'name': listener.stream_relay.stream.code,
                'description': listener.stream_relay.stream.name
            }
    ret['listener'] = tmp.values()

    currtrack = Track.current_track()
    ltid = request.args.get("apikey")
    if currtrack and ltid != currtrack.track:
        ret['trackid'] = currtrack.track
        ret['title'] = currtrack.title.name
        ret['artist'] = currtrack.title.artist.name

    show = Show.get_active_show()
    if show:
        user = show.get_active_user()
        ret['dj'] = user.username
        ret['djid'] = user.user
        ret['status'] = 'STREAMING'
        ret['showbegin'] = int(to_user_timezone(show.begin).strftime("%s"))
        if show.end:
            ret['showend'] = int(to_user_timezone(show.end).strftime("%s"))
        else:
            ret['showend'] = None
        ret['showtype'] = 'PLANNED'
        ret['showname'] = show.name
        ret['showdescription'] = show.description
        ret['showid'] = show.show
        ret['showthread'] = None
        ret['showdj'] = user.username
        ret['showdjid'] = user.user

    ret['shows'] = []
    if show and show.end:
        filter_begin = show.end
    else:
        filter_begin = now()
    nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(
        Show.begin.asc()).first()
    if nextshow:
        arr = {}
        arr['showbegin'] = int(to_user_timezone(nextshow.begin).strftime("%s"))
        if nextshow.end:
            arr['showend'] = int(to_user_timezone(nextshow.end).strftime("%s"))
        else:
            arr['showend'] = None
        arr['showtype'] = 'PLANNED'
        arr['showname'] = nextshow.name
        arr['showdescription'] = nextshow.description
        arr['showid'] = nextshow.show
        arr['showdj'] = nextshow.users[0].user.username
        arr['showdjid'] = nextshow.users[0].user.user
        arr['showthread'] = None
        ret['shows'].append(arr)

    return jsonify(ret)
예제 #18
0
 def test_init_show_unplanned(self):
     self.test_do_connect_valid_user()
     self.test_do_metadata()
     self.assertEqual(Show.get_active_show().flags & Show.FLAGS.UNPLANNED,
                      Show.FLAGS.UNPLANNED)