Ejemplo n.º 1
0
    def post_new(self, type, **args):

        m = mpdclient2.connect()
        if not m:
            return MpcPost(randstr(), "offline", m.currentsong())

        return MpcPost(randstr(), "online", m.currentsong())
Ejemplo n.º 2
0
 def cb(result, box):
     if hasattr(result, 'error') and result.error == 'invalid_grant':
         self.logger.error('auth_code of dropbox "%s" is invalid',
             box.title)
         return
     box.token = result.access_token
     self.add_search_handler(DropboxSearchHandler(randstr(), box))
Ejemplo n.º 3
0
 def setUp(self):
     super(DropboxSearchHandlerTest, self).setUp()
     try:
         self.token = open(self.token_path).read().strip()
     except IOError:
         self.skipTest('could not read token from ' + self.token_path)
         return
     self.box = Box('Ivanova', token=self.token)
     self.handler = DropboxSearchHandler(randstr(), self.box)
Ejemplo n.º 4
0
 def create(cls, app, **kwargs):
     url = kwargs['url'].strip()
     if not url:
         raise ValueError('url')
     if not url.startswith(('http://', 'https://')):
         url = 'http://' + url
     post = UrlPost(app, 'url_post:' + randstr(), url, None, url)
     app.db.hmset(post.id, post.json())
     return post
Ejemplo n.º 5
0
 def create(cls, app, **args):
     url = args['url'].strip()
     if not url:
         raise ValueError('url')
     if not url.startswith(('http://', 'https://')):
         url = 'http://' + url
     post = UrlPost(id='url_post:' + randstr(), app=app, title=url,
         poster_id=app.user.id, posted=None, url=url)
     app.db.hmset(post.id, post.json())
     return post
Ejemplo n.º 6
0
    def post_new(self, type, **args):
        status = ""
        url = ""

        ts_mpg4_960x544_url = 'http://www.tagesschau.de/export/video-podcast/webl/tagesschau'
        feed = feedparser.parse(ts_mpg4_960x544_url)

        latest_broadcast = feed["items"][0]
        video_url = latest_broadcast["links"][0]["href"] 

        return TagesschauPost(randstr(), status, video_url)
Ejemplo n.º 7
0
    def post_new(self, type, **args):
        url = args['url'].strip()
        title = args['title'].strip()
        videoid = args['videoid'].strip()

        if not videoid:
            raise ValueError('videoid')
        if not url:
            raise ValueError('url')
        if not url.startswith(('http://', 'https://')):
            url = 'http://' + url
        if not title:
            title = 'No title'

        return YoutubePost(randstr(), videoid, url, title)
Ejemplo n.º 8
0
    def set_volume(self, msg):
        # TODO: read device and interval from config
        soundcard = "0"
        mixer = "Master"

        if msg.data == "down":
            diff = "5-"
        else:
            diff = "5+"

        cmd_setvol = "amixer -c {0} sset {1} {2}".format(soundcard, mixer, diff)
        setvol = subprocess.Popen(cmd_setvol, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        # trigger the display
        new_post = VolumePost(randstr(), self.get_volume())
        self.app.sendall(Message("volume.update", vars(new_post)))
Ejemplo n.º 9
0
    def join(self, user):
        if self.mode != 'lobby':
            raise ValueError('mode')

        player = Player(randstr(), user)
        self.players.append(player)

        goal = filter(lambda g: g.player is None, self.goals)[0]
        goal.player = player
        player.x = goal.x
        player.y = goal.y

        self._send_to_subscribers(Message('pyng.joined', player.json()))

        if len(self.players) == 2:
            self._start()
Ejemplo n.º 10
0
    def __init__(self, app):
        super(Brick, self).__init__(app)
        self.search_handlers = []

        self.app.add_post_type(UrlPost)
        self.app.add_message_handler('url.get_search_handlers',
            self._get_search_handlers_msg)
        self.app.add_message_handler('url.search', self._search_msg)

        # ----

        self.add_search_handler(
            YoutubeSearchHandler(randstr(), 'Youtube', '#ff0000'))

        # ----

        titles = self.config.get('url.title', '').split()
        auth_codes = self.config.get('url.auth_code', '').split()
        self.boxes = [Box(t, auth_code=a) for t, a in zip(titles, auth_codes)]
        self.logger.info('%d dropbox(es) configured', len(self.boxes))

        for box in self.boxes:
            def cb(result, box):
                if hasattr(result, 'error') and result.error == 'invalid_grant':
                    self.logger.error('auth_code of dropbox "%s" is invalid',
                        box.title)
                    return
                box.token = result.access_token
                self.add_search_handler(DropboxSearchHandler(randstr(), box))

            WebAPI('https://api.dropbox.com/1').call(
                '/oauth2/token',
                {
                    'code': box.auth_code,
                    'grant_type': 'authorization_code',
                    'client_id': dropbox_app_id,
                    'client_secret': dropbox_app_secret
                },
                partial(cb, box=box),
                method='POST'
            )
Ejemplo n.º 11
0
 def __init__(self):
     super(YoutubeSearchHandler, self).__init__(randstr(), 'Youtube',
                                                '#ff0000')
     # See https://developers.google.com/youtube/v3/docs/
     self._api = WebAPI('https://www.googleapis.com/youtube/v3/',
                        {'key': YOUTUBE_API_KEY})
Ejemplo n.º 12
0
 def post_new(self, type, **args):
     self.app.msg_handlers["volume.set"] = self.set_volume
     return VolumePost(randstr(), self.get_volume())
Ejemplo n.º 13
0
 def _start(self):
     #self.logger.info('match started')
     self.mode = 'match'
     self.ball = Ball(randstr(), 0, 0)
     self._start_round()
     self._clock.start()
Ejemplo n.º 14
0
 def create(cls, app, **args):
     post = TestPost(id='test_post:' + randstr(), app=app, title='Test',
         poster_id=app.user.id, posted=None)
     app.db.hmset(post.id, post.json())
     return post
Ejemplo n.º 15
0
Archivo: test.py Proyecto: krmnn/wall
 def create(cls, app, **args):
     post = TestPost(app, 'test_post:' + randstr(), 'Test', None)
     app.db.hmset(post.id, post.json())
     return post
Ejemplo n.º 16
0
 def subscribe(self, user):
     self.subscribers.append(Subscriber(randstr(), user))
     return self.players
Ejemplo n.º 17
0
 def post_new(self, type, **args):
     return OmfgDogsPost(randstr())