示例#1
0
文件: api.py 项目: NamPNQ/pytaku
    def get(self):

        series = create_or_get_series(self.data['url'])

        resp = {
            field: getattr(series, field)
            for field in ('site', 'name', 'thumb_url', 'tags', 'status',
                          'description', 'authors')
        }

        # If the provided chapter_limit is valid, return only that many
        # chapters in API response.
        chapters = series.chapters
        chapter_limit = self.data['chapter_limit']
        if chapter_limit in range(len(chapters)):
            chapters = chapters[:chapter_limit]
        resp['chapters'] = chapters

        # If user is logged in
        if hasattr(self, 'user'):
            # tell if this series is in their bookmarks
            resp['is_bookmarked'] = series.is_bookmarked_by(self.user)

            # insert user's reading progress into each chapter too
            progresses = ChapterProgress.get_by_series_url(self.user.key.id(),
                                                           self.data['url'])
            for chap in resp['chapters']:
                if chap['url'] in progresses:
                    chap['progress'] = progresses[chap['url']]
                else:
                    chap['progress'] = 'unread'
        return resp
示例#2
0
文件: api.py 项目: PythonPaper/pytaku
 def get(self):
     series = [create_or_get_series(url, no_update=True)
               for url in self.user.bookmarked_series]
     return [{
         'site': s.site,
         'name': s.name,
         'url': s.url,
         'thumb_url': s.thumb_url,
     } for s in series]
示例#3
0
文件: routes.py 项目: hnq90/pytaku
 def get(self, query=None):
     url = unquote(query)
     chapter = create_or_get_chapter(url)
     series = create_or_get_series(chapter.series_url)
     template = jinja.get_template('series.html')
     self.response.write(template.render({
         'title': '%s - %s' % (chapter.name, chapter.series_name),
         'thumb_url': chapter.pages[0],
         'descriptions': series.description if series.description else [],
     }))
示例#4
0
文件: routes.py 项目: hnq90/pytaku
    def get(self, query=None):
        url = unquote(query)
        series = create_or_get_series(url, no_update=True)

        template = jinja.get_template('series.html')
        self.response.write(template.render({
            'title': series.name,
            'thumb_url': series.thumb_url,
            'descriptions': series.description,
        }))
示例#5
0
文件: api.py 项目: kgov1/pytaku
 def get(self):
     series = [
         create_or_get_series(url, no_update=True)
         for url in self.user.bookmarked_series
     ]
     return [{
         'site': s.site,
         'name': s.name,
         'url': s.url,
         'thumb_url': s.thumb_url,
     } for s in series]
示例#6
0
    def get(self, query=None):
        url = unquote(query)
        series = create_or_get_series(url, no_update=True)

        template = jinja.get_template('series.html')
        self.response.write(
            template.render({
                'title': series.name,
                'thumb_url': series.thumb_url,
                'descriptions': series.description,
            }))
示例#7
0
文件: api.py 项目: PythonPaper/pytaku
    def get(self):

        series = create_or_get_series(self.data['url'])

        resp = {
            field: getattr(series, field)
            for field in ('site', 'name', 'thumb_url', 'tags', 'status',
                          'description', 'authors', 'chapters')
        }

        if not hasattr(self, 'user'):
            self._fetch_first_chapter(resp['chapters'])
            return resp

        # tell if this series is in their bookmarks
        resp['is_bookmarked'] = series.is_bookmarked_by(self.user)

        # insert user's reading progress into each chapter too
        progresses = ChapterProgress.get_by_series_url(self.user.key.id(),
                                                       self.data['url'])

        # Only show chapters that come after the latest "finished" chapter, or
        # starting from the latest "reading" chapter, whichever comes last.
        if self.data['only_unread']:
            shown_chapters = deque(maxlen=6)

            for chap in resp['chapters']:

                if chap['url'] in progresses:
                    chap['progress'] = progresses[chap['url']]
                    if chap['progress'] == 'finished':
                        break
                    elif chap['progress'] == 'reading':
                        shown_chapters.append(chap)
                        break

                else:
                    chap['progress'] = 'unread'

                shown_chapters.append(chap)

            resp['chapters'] = list(shown_chapters)

        # Show all chapters:
        else:
            for chap in resp['chapters']:
                if chap['url'] in progresses:
                    chap['progress'] = progresses[chap['url']]
                else:
                    chap['progress'] = 'unread'

        self._fetch_first_chapter(resp['chapters'])
        return resp
示例#8
0
文件: api.py 项目: kgov1/pytaku
    def get(self):

        series = create_or_get_series(self.data['url'])

        resp = {
            field: getattr(series, field)
            for field in ('site', 'name', 'thumb_url', 'tags', 'status',
                          'description', 'authors', 'chapters')
        }

        if not hasattr(self, 'user'):
            self._fetch_first_chapter(resp['chapters'])
            return resp

        # tell if this series is in their bookmarks
        resp['is_bookmarked'] = series.is_bookmarked_by(self.user)

        # insert user's reading progress into each chapter too
        progresses = ChapterProgress.get_by_series_url(self.user.key.id(),
                                                       self.data['url'])

        # Only show chapters that come after the latest "finished" chapter, or
        # starting from the latest "reading" chapter, whichever comes last.
        if self.data['only_unread']:
            shown_chapters = deque(maxlen=6)

            for chap in resp['chapters']:

                if chap['url'] in progresses:
                    chap['progress'] = progresses[chap['url']]
                    if chap['progress'] == 'finished':
                        break
                    elif chap['progress'] == 'reading':
                        shown_chapters.append(chap)
                        break

                else:
                    chap['progress'] = 'unread'

                shown_chapters.append(chap)

            resp['chapters'] = list(shown_chapters)

        # Show all chapters:
        else:
            for chap in resp['chapters']:
                if chap['url'] in progresses:
                    chap['progress'] = progresses[chap['url']]
                else:
                    chap['progress'] = 'unread'

        self._fetch_first_chapter(resp['chapters'])
        return resp
示例#9
0
 def get(self, query=None):
     url = unquote(query)
     chapter = create_or_get_chapter(url)
     series = create_or_get_series(chapter.series_url)
     template = jinja.get_template('series.html')
     self.response.write(
         template.render({
             'title':
             '%s - %s' % (chapter.name, chapter.series_name),
             'thumb_url':
             chapter.pages[0],
             'descriptions':
             series.description if series.description else [],
         }))