def _run(self): format = self.params.format.name.lower() output_file = self.params.output_file result = ExportEntry(self.config, self.params.entry_id, format).request() if output_file.name.endswith(f'.{format}'): result.filename = output_file.name output_file = output_file.parent if not Path(output_file).exists(): Path(output_file).mkdir(parents=True) if result.filename: if result.filename.startswith('.'): entry = Entry( GetEntry(self.config, self.params.entry_id).request().response) result.filename = f'{entry.title}{result.filename}' new_name = result.filename else: new_name = str(f'{datetime.now().timestamp()}.{format}') output_file = PurePath(f'{Path(output_file).resolve()}/' f'{self.__get_filename(new_name)}') with open(output_file, 'wb') as file: file.write(result.content) return True, f'Exported to: {output_file}'
def __remove_from_entry(self): api = GetEntry(self.config, self.params.entry_id) entry = Entry(api.request().response) tag = list(filter( lambda t: t['slug'] == self.params.tags, entry.tags)) if not tag: return False, ( f'Tag "{self.params.tags}" not found ' f'in entry:\n\n\t{entry.title}\n') tag = tag[0] confirm_msg = ( f'{Back.RED}You are going to remove tag ' f'{Fore.BLUE}{self.params.tags}{Fore.RESET} from entry:' f'{Back.RESET}' f'\n\n\t{entry.title}\n\n' 'Continue?') if not wclick.confirm(confirm_msg): return True, 'Cancelling' DeleteTagFromEntry( self.config, self.params.entry_id, tag['id']).request() return True, None
def _run(self): params = self.params api = GetListEntries(self.config, { ListParams.TAGS: self.tags, ListParams.COUNT: 100 }) entries = Entry.create_list( api.request().response['_embedded']["items"]) if not params.force: titles = "\n\t".join([x.title for x in entries]) confirm_msg = (f'{Back.GREEN}You are going to update ' f'{self.__get_update_status()} ' f'of followed entries:{Back.RESET}' f'\n\n\t{titles}\n\nContinue?') if not wclick.confirm(confirm_msg): return True, 'Cancelling' for entry in entries: self.__log(entry.title) UpdateEntry( self.config, entry.entry_id, { Params.STAR: self.params.set_star_state, Params.READ: self.params.set_read_state }).request() self.__log(entry.title) return True, None
def _run(self): self.__calculate_alignment() api = GetEntry(self.config, self.params.entry_id) output = ExportFactory.create(Entry(api.request().response), self.params, self.params.type, self.width).run() if not self.params.raw: output = self.__format_output(output) return True, output
def _run(self): api = GetListEntries( self.config, { ListEntriesParams.COUNT: self.__get_quantity(), ListEntriesParams.FILTER_READ: self.params.filter_read, ListEntriesParams.FILTER_STARRED: self.params.filter_starred, ListEntriesParams.OLDEST: self.params.oldest, ListEntriesParams.TAGS: self.params.tags }) entries = Entry.create_list( api.request().response['_embedded']["items"]) return True, self.__print_entries(entries)
def __get_result(self, type, extension): if type.name in ScreenType.list(): result = GetEntry(self.config, self.params.entry_id).request() entry = Entry(result.response) result.filename = f'{entry.title}.{extension}' result.content = bytes( ExportFactory.create(entry, None, format_to_screen(type), None).run(), 'utf-8') else: result = ExportEntry(self.config, self.params.entry_id, type.name.lower()).request() return result
def _run(self): api = GetListEntries( self.config, { ListEntriesParams.COUNT: sys.maxsize, ListEntriesParams.FILTER_READ: self.params.filter_read, ListEntriesParams.FILTER_STARRED: self.params.filter_starred, ListEntriesParams.TAGS: self.params.tags }) entries = Entry.create_list( api.request().response['_embedded']["items"]) if self.params.untagged: entries = list(filter(lambda e: not e.tags, entries)) return True, len(entries)
def _run(self): params = self.params if params.command in (AnnoSubcommand.LIST, AnnoSubcommand.SHOW): api = GetEntry(self.config, params.entry_id) entry = Entry(api.request().response) result = [] for anno in sorted( entry.annotations, key=lambda x: int(x['id'])): result.append(self.__get_anno[params.command](anno)) return True, "\n".join(filter(None, result)) if params.command == AnnoSubcommand.REMOVE: DeleteAnnotation(self.config, self.params.anno_id).request() return True, 'Annotation successfully deleted' return False, "Unknown command"
def _run(self): api = GetEntry(self.config, self.params.entry_id) entry = Entry(api.request().response) self.__calculate_alignment() article = entry.content if not self.params.html: article = self.__html2text(article, entry.annotations) output = f"{entry.title}\n{self.__header_delimiter()}\n{article}" if not self.params.raw: output = self.__format_output(output) return True, output
def _run(self): if not self.params.force: request = GetEntry(self.config, self.params.entry_id).request() entr = Entry(request.response) confirm_msg = ( f"{Back.RED}{DeleteCommand.WARN_MSG}:{Back.RESET}\n\n" f"\t{entr.title}\n\n" "Continue?") if not wclick.confirm(confirm_msg): return True, 'Cancelling' request = DeleteEntry(self.config, self.params.entry_id).request() if not self.params.quiet: return True, "Entry successfully deleted." return True, None
def _run(self): api = GetEntry(self.config, self.params.entry_id) entry = Entry(api.request().response) url = "" if self.params.open_original: url = entry.url else: serverurl = self.config.get(Sections.API, Options.SERVERURL) url = f"{serverurl}/view/{entry.entry_id}" browser = webbrowser.get(self.params.browser) wclick.stop_spinner() browser.open_new_tab(url) return True, None
def __remove_by_tag_name(self): entries = list() for tag in self.params.tags.split(','): api = GetListEntries(self.config, { ListParams.TAGS: tag, ListParams.COUNT: 100 }) entries.extend(Entry.create_list( api.request().response['_embedded']["items"])) titles = "\n\t".join([x.title for x in entries]) confirm_msg = ( f'{Back.RED}You are going to remove tag ' f'{Fore.BLUE}{self.params.tags}{Fore.RESET} ' f'from this entries:{Back.RESET}\n\n\t{titles}' '\n\nContinue?') if not wclick.confirm(confirm_msg): return True, 'Cancelling' DeleteTagsByLabel(self.config, self.params.tags).request() return True, None
def _run(self): params = self.params read_value = params.set_read_state star_value = params.set_star_state request = GetEntry(self.config, self.entry_id).request() entry = Entry(request.response) if params.toggle_read is not None and params.toggle_read: read_value = not entry.read if params.toggle_star is not None and params.toggle_star: star_value = not entry.starred request = UpdateEntry( self.config, self.entry_id, { UpdateEntryParams.TITLE: params.new_title, UpdateEntryParams.STAR: star_value, UpdateEntryParams.READ: read_value }).request() if not params.quiet: return True, "Entry successfully updated." return True, None
def _run(self): api = GetListEntries(self.config, { ListEntriesParams.TAGS: self.params.tags, ListEntriesParams.COUNT: 100 }) entries = Entry.create_list( api.request().response['_embedded']["items"]) if not self.params.force: titles = "\n\t".join([x.title for x in entries]) confirm_msg = ( f'{Back.RED}You are going to remove ' f'followed entries:{Back.RESET}' f'\n\n\t{titles}\n\nContinue?') if not wclick.confirm(confirm_msg): return True, 'Cancelling' for entry in entries: if not self.params.quiet: wclick.echo(f'Deleting entry: {entry.title}', nl=False) DeleteEntry(self.config, entry.entry_id).request() if not self.params.quiet: wclick.echo(f'\t...\t{Fore.GREEN}success{Fore.RESET}') return True, None
def _run(self): entry = Entry( GetEntry(self.config, self.params.entry_id).request().response) return True, self.__entry_to_string(entry)
def __fix_file_name(self, result, extension): if not result.filename or result.filename.startswith('.'): entry = Entry( GetEntry(self.config, self.params.entry_id).request().response) result.filename = f'{entry.title}.{extension}'