def get_hot_note(self, id): note_name = os.path.join(self.note_dir, "%s_hot.md" % id) if os.path.exists(note_name): with open(note_name, "r", encoding="utf-8") as f: return f.read() else: return wereader.get_bestbookmarks(id, cookies=self.cookies)
def main(): print('欢迎使用微信读书爬虫') try: books = get_bookshelf() except: print('请检查您的Cookie设置') return print('您的书架如下:') for b in books: print(b.bookId,b.title,b.author) while True: bid = input('想看哪本书的目录,请输入对应书籍id:') for c in get_chapters(int(bid)): print('#'*c[0],c[1]) y = input('是否需要查看该书的热门划线,y/n?') if y.lower() == 'y': bb = get_bestbookmarks(bid) print(bb) y = input('是否需要查看你的笔记,y/n?') if y.lower() == 'y': bb = get_bookmarklist(bid) print(bb) y = input('是否需要查看其他书,y/n?') if y.lower() == 'y': continue else: print('bye~') break
def export_popular(): global CURRENT bid = CURRENT.bookId bb = get_bestbookmarks(bid, cookies=cookies) with open(f"{CURRENT.title}-{CURRENT.bookId}-热门划线.{FMT}", "w") as f: f.write(bb) print("导出成功")
def export_popular(): global CURRENT bid = CURRENT.bookId bb = get_bestbookmarks(bid) with open(f'{CURRENT.title}-{CURRENT.bookId}-热门划线.{FMT}', 'w') as f: f.write(bb) print("导出成功")
def old_main(): print('欢迎使用微信读书爬虫') try: books = get_bookshelf() except: print('请检查您的Cookie设置') return print('您的书架如下:') for b in books: print(b.bookId, b.title, b.author) while True: bid = input('想看哪本书的目录,请输入对应书籍id:') current_book = [x for x in books if x.bookId == bid][0] for c in get_chapters(int(bid)): print('#' * c[0], c[1]) y = input('是否需要查看该书的热门划线,y/n?') if y.lower() == 'y': bb = get_bestbookmarks(bid) print(bb) y = input('是否需要查看你的笔记,y/n?') if y.lower() == 'y': bb = get_bookmarklist(bid) print(bb) y = input('是否需要保存你的笔记,y/n?') if y.lower() == 'y': bb = get_bookmarklist(bid) with open(f'{current_book.title}-{current_book.bookId}.txt', 'w') as f: f.write(bb) y = input('是否需要查看其他书,y/n?') if y.lower() == 'y': continue else: print('bye~') break
def see_popular(): global CURRENT bid = CURRENT.bookId bb = get_bestbookmarks(bid, cookies=cookies) print(bb)
def main(bookId): global file global way_to_append global comment_mode while True: # 调用print_guide()函数提示输入并将输入返回 y = print_guide().replace(' ', '').lower() if y[:5] == 'print': if y == 'print1': res = get_mark(bookId) print_and_copy(res) print( '**********************************************************' ) elif y == 'print2': res = get_mythought(bookId) print_and_copy(res) print( '**********************************************************' ) elif y == 'print3': res = get_bestbookmarks(bookId) print_and_copy(res) print( '**********************************************************' ) elif y == 'print4': # 输出目录 res = '' sorted_chapters = get_sorted_chapters(bookId) for chapter in sorted_chapters: res += set_chapter_level( chapter[1]) + ' ' + chapter[2] + '\n\n' print_and_copy(res) print( '**********************************************************' ) elif y == 'print5': res = get_bookinfo(bookId) print_and_copy(res) print( '**********************************************************' ) elif y == 'print6': if way_to_append == '': while True: mode = input('选择追加模式:按时间/按位置(1/2)?').replace(' ', '') if mode in ['1', '2']: way_to_append = mode break else: print('输入无效,重新输入') if way_to_append == '1': line_and_res = get_new_content_bytime(bookId) print_and_copy(line_and_res[1]) elif way_to_append == '2': line_and_res = get_new_content_byrange(bookId) print_and_copy(line_and_res[1]) elif way_to_append == '1': line_and_res = get_new_content_bytime(bookId) print_and_copy(line_and_res[1]) elif way_to_append == '2': line_and_res = get_new_content_byrange(bookId) print_and_copy(line_and_res[1]) else: print('输入无效') elif y == 'print7': print_books_as_tree(userVid=USERVID) print( '**********************************************************' ) elif y == 'print8': print_books_directly(userVid=USERVID) print( '**********************************************************' ) elif y == 'print9': comment = '' if comment_mode == '': while True: mode = input('选择评论输出模式(纯文本/html)(1/2)?').replace( ' ', '') if mode in ['1', '2']: comment_mode = mode break else: print('输入无效,重新输入') if comment_mode == '1': comment = get_comment(bookId, mode='1') elif comment_mode == '2': comment = get_comment(bookId, mode='2') print_and_copy(comment) print( '**********************************************************' ) elif y[:4] == 'push': if y == 'push1': res = get_mark(bookId) push_to_file(res) print( '**********************************************************' ) elif y == 'push2': res = get_mythought(bookId) push_to_file(res) print( '**********************************************************' ) elif y == 'push3': res = get_bestbookmarks(bookId) push_to_file(res) print( '**********************************************************' ) elif y == 'push4': res = '\n' sorted_chapters = get_sorted_chapters(bookId) for chapter in sorted_chapters: res += set_chapter_level( chapter[1]) + ' ' + chapter[2] + '\n\n' push_to_file(res) print( '**********************************************************' ) elif y == 'push5': res = get_bookinfo(bookId) push_to_file(res) print( '**********************************************************' ) elif y == 'push6': if way_to_append == '': way_to_append = input('选择追加模式:按时间/按位置(1/2)?').replace( ' ', '') elif way_to_append.strip() == '1': line_and_res = get_new_content_bytime(bookId) # 检查返回内容是否有效 if line_and_res[0] == '': continue print('将' + line_and_res[0] + '后的新内容push到文件') push_to_file(line_and_res[1]) elif way_to_append.strip() == '2': line_and_res = get_new_content_byrange(bookId) # 检查返回内容是否有效 if line_and_res[0] == '': continue print('将' + line_and_res[0] + '后的新内容push到文件') push_to_file(line_and_res[1]) else: print('输入无效') elif y == 'push7': comment = '' if comment_mode == '': while True: mode = input('选择评论输出模式(纯文本/html)(1/2)?').replace( ' ', '') if mode in ['1', '2']: comment_mode = mode break else: print('输入无效,重新输入') if comment_mode == '1': comment = get_comment(bookId, mode='1') elif comment_mode == '2': comment = get_comment(bookId, mode='2') push_to_file(comment) print( '**********************************************************' ) elif y == 'removeall': remove_all_bookmark(bookId) elif y == 'exit': return 0 elif y == 'changeid': return 1 elif y == 'changefile': f = input('请输入文件路径,内容将会追加到该文件中:').replace('\\', '\\\\') if len(f) > 0 and os.path.exists(f) and os.path.isfile(f): file = f print('设置成功') else: print('无效路径') elif y == 'appendmode': mode = input('选择追加模式:按时间/按位置(1/2)?').replace(' ', '') if mode in ['1', '2']: way_to_append = mode print('设置成功') else: print('输入无效') elif y == 'commentmode': mode = input('选择评论格式:纯文本/html(1/2)?').replace(' ', '') if mode in ['1', '2']: comment_mode = mode print('设置成功') else: print('输入无效') else: print('输入无效')