Esempio n. 1
0
def _handle_items(data, on_items, on_error):
    if 'objects' in data:
        on_items(
            convert_json_from_unicode(data['objects']),
            hash=data.get('hash', None))
    elif on_error:
        on_error('post not found in response')
Esempio n. 2
0
 def _handle_channels(self, data):
     data = convert_json_from_unicode(data)
     self.streams = [
         PostsStream(manager=self, **chan_data) for chan_data in data
     ]
     self.connected = True
     Logger.info('PostsManager: connected. channels=%s' %
                 ([s.title for s in self.streams]))
Esempio n. 3
0
def get_post_themes():
    global themes
    try:
        if not themes:
            with open(post_themes, 'r') as f:
                data = convert_json_from_unicode(
                    json.loads(f.read()))
                themes = [PostTheme(**pdata) for pdata in data]
    except Exception as ex:
        Logger.error('PostScreen: failed loading post themes: %s' % ex)
    return themes
Esempio n. 4
0
 def _on_page(self, data, **kwargs):
     c = self.comments_container
     if c:
         numcomments = len(c.children)
         update_numcomments = False
         for cdata in reversed(data):
             updated = c.enqueue(cdata.get('key', None),
                                 convert_json_from_unicode(cdata))
             if updated:
                 numcomments += 1
                 update_numcomments = True
         self.status = 'populated' if data else 'empty'
         if update_numcomments:
             post_data = {'comment_count': int(numcomments)}
             if self.ref_post:
                 self.ref_post.update_widget(post_data)
             else:
                 self.userpost.update_widget(post_data)
Esempio n. 5
0
 def _on_page(self, data, **kwargs):
     c = self.comments_container
     if c:
         numcomments = len(c.children)
         update_numcomments = False
         for cdata in reversed(data):
             updated = c.enqueue(
                 cdata.get('key', None),
                 convert_json_from_unicode(cdata))
             if updated:
                 numcomments += 1
                 update_numcomments = True
         self.status = 'populated' if data else 'empty'
         if update_numcomments:
             post_data = {'comment_count': int(numcomments)}
             if self.ref_post:
                 self.ref_post.update_widget(post_data)
             else:
                 self.userpost.update_widget(post_data)
Esempio n. 6
0
    def _on_page(self, data, add_bottom=True, **kwargs):
        if not data:
            self.loading = False
            return

        # only insert when getting next page -- i.e. adding from the bottom
        systempost = self._on_page_add_system_post() if add_bottom else None

        removed = removed_ds.data()
        systempost_place = 0
        for pdata in data:
            systempost_place += 1
            if systempost and systempost_place == 4:
                self._add_system_post(
                    key='system_post_%s' % (self.sys_posts_count + 1),
                    index=0,
                    **systempost)

            post = pdata.get('post', None)
            hash = pdata.get('hash', None)
            if post:
                key = post.get('key', None)
                if key in removed:
                    continue
                d = convert_json_from_unicode(post)
                d['hash'] = hash
                if not key:
                    continue
                if self.stream_system and self.stream_system.key in d['channels']:
                    print 'Got system post'
                    self.stream_system.hash_bounds = hash
                    if len(d['content']) > 2 and d['content'][0] == '#':
                        print 'Systempost -- deep link'
                        key = d['content'][1:]
                        def on_get_deeplink(data, hash):
                            print 'Got deep links data'
                            if len(data) > 0:
                                wrapper = {'hash': hash, 'post': data[0]}
                                self._on_page([wrapper], add_bottom=False)
                        from api.items import get as getPostData
                        getPostData(keys=[key], on_items=on_get_deeplink)
                        continue
                    d['background'] = 'bkg.jpg'
                    d['when'] = 'once'
                    if d['role_text'].lower() == 'invite':
                        d['action'] = 'invite'
                        d['button'] = 'send invitation'
                    elif d['role_text'].lower() == 'linkedin':
                        d['action'] = 'linkedin'
                        d['button'] = 'Login with linkedin'
                    else:
                        d['action'] = 'close'
                    d['key'] = 'system_post_%s' % (self.sys_posts_count + 1)
                    d['index'] = -1
                    self._add_system_post(**d)
                    continue
                if add_bottom:
                    self.container.enqueue(key, d, index=0)
                else:
                    self.container.enqueue(key, d, index=-1)
        self.loading = False
Esempio n. 7
0
def _handle_post(data, on_post, on_error):
    if 'post' in data:
        on_post(convert_json_from_unicode(data['post']))
    elif on_error:
        on_error('post not found in response')
Esempio n. 8
0
def _handle_items(data, on_items, on_error):
    if 'objects' in data:
        on_items(convert_json_from_unicode(data['objects']),
                 hash=data.get('hash', None))
    elif on_error:
        on_error('post not found in response')
Esempio n. 9
0
 def _handle_channels(self, data):
     data = convert_json_from_unicode(data)
     self.streams = [PostsStream(manager=self, **chan_data) for chan_data in data]
     self.connected = True
     Logger.info('PostsManager: connected. channels=%s' % ([s.title for s in self.streams]))
Esempio n. 10
0
    def _on_page(self, data, add_bottom=True, **kwargs):
        if not data:
            self.loading = False
            return

        # only insert when getting next page -- i.e. adding from the bottom
        systempost = self._on_page_add_system_post() if add_bottom else None

        removed = removed_ds.data()
        systempost_place = 0
        for pdata in data:
            systempost_place += 1
            if systempost and systempost_place == 4:
                self._add_system_post(key='system_post_%s' %
                                      (self.sys_posts_count + 1),
                                      index=0,
                                      **systempost)

            post = pdata.get('post', None)
            hash = pdata.get('hash', None)
            if post:
                key = post.get('key', None)
                if key in removed:
                    continue
                d = convert_json_from_unicode(post)
                d['hash'] = hash
                if not key:
                    continue
                if self.stream_system and self.stream_system.key in d[
                        'channels']:
                    print 'Got system post'
                    self.stream_system.hash_bounds = hash
                    if len(d['content']) > 2 and d['content'][0] == '#':
                        print 'Systempost -- deep link'
                        key = d['content'][1:]

                        def on_get_deeplink(data, hash):
                            print 'Got deep links data'
                            if len(data) > 0:
                                wrapper = {'hash': hash, 'post': data[0]}
                                self._on_page([wrapper], add_bottom=False)

                        from api.items import get as getPostData
                        getPostData(keys=[key], on_items=on_get_deeplink)
                        continue
                    d['background'] = 'bkg.jpg'
                    d['when'] = 'once'
                    if d['role_text'].lower() == 'invite':
                        d['action'] = 'invite'
                        d['button'] = 'send invitation'
                    elif d['role_text'].lower() == 'linkedin':
                        d['action'] = 'linkedin'
                        d['button'] = 'Login with linkedin'
                    else:
                        d['action'] = 'close'
                    d['key'] = 'system_post_%s' % (self.sys_posts_count + 1)
                    d['index'] = -1
                    self._add_system_post(**d)
                    continue
                if add_bottom:
                    self.container.enqueue(key, d, index=0)
                else:
                    self.container.enqueue(key, d, index=-1)
        self.loading = False
Esempio n. 11
0
def _handle_post(data, on_post, on_error):
    if 'post' in data:
        on_post(convert_json_from_unicode(data['post']))
    elif on_error:
        on_error('post not found in response')