Esempio n. 1
0
def update_series(series, **kwargs):

    if 'chapters' in kwargs:
        # Update next_chapter_url for the chapter that was previously the
        # latest but not anymore
        new_chapters = kwargs['chapters']
        new_chapters_num = len(new_chapters) - len(series.chapters)
        if new_chapters_num > 0:

            # previously latest chapter that needs updating:
            chapter_url = series.chapters[0]['url']
            chap = Chapter.get_by_url(chapter_url)

            if chap is not None:
                i = new_chapters_num - 1
                chap.next_chapter_url = new_chapters[i]['url']
                chap.put()

        kwargs['chapters'] = new_chapters

    # Update if a field has new value
    changed_keys = []
    for key, val in kwargs.iteritems():
        if getattr(series, key) != val:
            setattr(series, key, val)
            changed_keys.append(key)

    # Update series name in all of its existing chapters
    if 'name' in changed_keys:
        Chapter.set_series_name(series.url, kwargs['name'])

    series.last_update = datetime.now()  # "refresh" this series
    series.put()
Esempio n. 2
0
def update_series(series, **kwargs):

    if 'chapters' in kwargs:
        # Update next_chapter_url for the chapter that was previously the
        # latest but not anymore
        new_chapters = kwargs['chapters']
        new_chapters_num = len(new_chapters) - len(series.chapters)
        if new_chapters_num > 0:

            # previously latest chapter that needs updating:
            chapter_url = series.chapters[0]['url']
            chap = Chapter.get_by_url(chapter_url)

            if chap is not None:
                i = new_chapters_num - 1
                chap.next_chapter_url = new_chapters[i]['url']
                chap.put()

        kwargs['chapters'] = new_chapters

    # Update if a field has new value
    changed_keys = []
    for key, val in kwargs.iteritems():
        if getattr(series, key) != val:
            setattr(series, key, val)
            changed_keys.append(key)

    # Update series name in all of its existing chapters
    if 'name' in changed_keys:
        Chapter.set_series_name(series.url, kwargs['name'])

    series.last_update = datetime.now()  # "refresh" this series
    series.put()
Esempio n. 3
0
def create_or_get_chapter(url):
    """
    Fetch info and create Chapter record if not already created.
    Returns Chapter object.
    """

    # Check if this url is supported
    site = sites.get_site(url)
    if site is None:
        raise PyError({'msg': 'unsupported_url'})

    chapter = Chapter.get_by_url(url)
    if chapter is None:
        page_html = site.fetch_chapter_seed_page(url)
        info = site.chapter_info(page_html)

        if info['series_url']:
            series = create_or_get_series(info['series_url'])
        else:
            series = type('', (object, ), {'name': 'Unknown'})

        chapter = Chapter.create(url,
                                 info['name'],
                                 info['pages'],
                                 info['series_url'],
                                 series.name,
                                 info['prev_chapter_url'],
                                 info['next_chapter_url'])
        chapter.put()

    return chapter
Esempio n. 4
0
def create_or_get_chapter(url):
    """
    Fetch info and create Chapter record if not already created.
    Returns Chapter object.
    """

    # Check if this url is supported
    site = sites.get_site(url)
    if site is None:
        raise PyError({'msg': 'unsupported_url'})

    chapter = Chapter.get_by_url(url)
    if chapter is None:
        page_html = site.fetch_chapter_seed_page(url)
        info = site.chapter_info(page_html, url=url)
        series = create_or_get_series(info['series_url'])

        chapter = Chapter.create(url,
                                 info['name'],
                                 info['pages'],
                                 info['series_url'],
                                 series.name,
                                 info['prev_chapter_url'],
                                 info['next_chapter_url'])
        chapter.put()

    return chapter
Esempio n. 5
0
    def post(self):
        url = self.data['url']
        progress = self.data['progress']

        chapter = Chapter.get_by_url(url)
        if chapter is None:
            raise PyError('nonexistent_chapter')

        ChapterProgress.set_progress(self.user.key.id(), progress,
                                     chapter.url, chapter.series_url)
        return {}
Esempio n. 6
0
File: api.py Progetto: kgov1/pytaku
    def post(self):
        url = self.data['url']
        progress = self.data['progress']

        chapter = Chapter.get_by_url(url)
        if chapter is None:
            raise PyError('nonexistent_chapter')

        ChapterProgress.set_progress(self.user.key.id(), progress, chapter.url,
                                     chapter.series_url)
        return {}
Esempio n. 7
0
    def post(self):
        "Add or remove chapter from provided URL to bookmark list"

        if self.data['action'] not in ('add', 'remove'):
            raise PyError({'msg': 'invalid_action'})

        chapter = Chapter.get_by_url(self.data['url'])
        if chapter is None:
            raise PyError({'msg': 'chapter_not_created'})

        if self.data['action'] == 'add':
            if not self.user.bookmark_chapter(chapter):
                raise PyError({'msg': 'chapter_already_bookmarked'})
            return {}

        else:
            if not self.user.unbookmark_chapter(chapter):
                raise PyError({'msg': 'chapter_not_bookmarked'})
            return {}
Esempio n. 8
0
File: api.py Progetto: kgov1/pytaku
    def post(self):
        "Add or remove chapter from provided URL to bookmark list"

        if self.data['action'] not in ('add', 'remove'):
            raise PyError({'msg': 'invalid_action'})

        chapter = Chapter.get_by_url(self.data['url'])
        if chapter is None:
            raise PyError({'msg': 'chapter_not_created'})

        if self.data['action'] == 'add':
            if not self.user.bookmark_chapter(chapter):
                raise PyError({'msg': 'chapter_already_bookmarked'})
            return {}

        else:
            if not self.user.unbookmark_chapter(chapter):
                raise PyError({'msg': 'chapter_not_bookmarked'})
            return {}