示例#1
0
文件: views.py 项目: mitnk/mc
def kindle(request):
    if request.method == "POST":
        book_id = request.POST.get('book_id', 0)
        if not book_id:
            return HttpResponse("Invalid book_id")

        book_name = get_book_name(book_id)
        if not book_name:
            return HttpResponse("Cannot get book_name, zongheng lib broken?")

        if Novel.objects.filter(book_id=book_id).exists():
            novel = Novel.objects.get(book_id=book_id)
            if novel.title != book_name:
                novel.title = book_name
                novel.save()
        else:
            novel = Novel.objects.create(title=book_name, book_id=book_id)
        
        chapter_list = get_chapter_list(book_id)
        chapter_list = [x for x in chapter_list if int(x[0]) > int(novel.last_id)]
        if len(chapter_list) < settings.MIN_CHAPTER_COUNT:
            return HttpResponse("Not enough chapters.(%s/%s)\n" % (len(chapter_list), settings.MIN_CHAPTER_COUNT))

        chapter_list.reverse()
        file_name = write_to_file(book_id, chapter_list, book_name=book_name)
        send_to_kindle(file_name)
        novel.last_id = max([int(x) for x, y in chapter_list])
        novel.save()
        return HttpResponse("Send %s chapters to your kindle\n" % len(chapter_list))


    novels = Novel.objects.all()
    return render_to_response('zongheng/kindle.html',
                              {'novels': novels, })
示例#2
0
文件: views.py 项目: mitnk/mc
def index(request):
    book_id = request.POST.get('book_id')
    from_ = int(request.POST.get('from', 0))
    to_ = int(request.POST.get('to', 0))
    page = request.POST.get('page')
    if from_ and to_:
        if from_ > to_:
            from_, to_ = to_, from_
        book_name = get_book_name(book_id)
        chapter_list = get_chapter_list(book_id, page=page)
        chapter_list = [x for x in chapter_list if from_ <= x[0] <= to_]
        print from_, to_
        print chapter_list
        #file_name = write_to_file(book_id, chapter_list, book_name=book_name)
        #send_to_kindle(file_name)
        return HttpResponseRedirect(reverse("zongheng_index"))
    else:
        chapter_list = []
        pages = []
        if page:
            pages = get_book_pages(book_id, page=page)
        elif book_id:
            pages = get_book_pages(book_id)
        if book_id:
            if not page:
                page = 1
            chapter_list = get_chapter_list(book_id, page=page)
    return render_to_response('zongheng/index.html',
                              {'pages': pages,
                               'page': page,
                               'book_id': book_id,
                               'chapter_list': chapter_list, }
                             )