{"id":13408453,"url":"https://github.com/Constantin1489/trrc","last_synced_at":"2025-03-14T13:31:14.148Z","repository":{"id":172560710,"uuid":"606797087","full_name":"Constantin1489/trrc","owner":"Constantin1489","description":"trrc is a command-line program to add a card to Anki using AnkiConnect API.","archived":false,"fork":false,"pushed_at":"2023-06-17T14:23:54.000Z","size":1135,"stargazers_count":21,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-29T13:36:21.506Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Constantin1489.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-02-26T15:45:28.000Z","updated_at":"2024-08-10T23:12:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"2e157275-d449-4795-8ad5-aeb47ba3ec9b","html_url":"https://github.com/Constantin1489/trrc","commit_stats":null,"previous_names":["constantin1489/trrc"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantin1489%2Ftrrc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantin1489%2Ftrrc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantin1489%2Ftrrc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantin1489%2Ftrrc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Constantin1489","download_url":"https://codeload.github.com/Constantin1489/trrc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243584200,"owners_count":20314716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:00:52.953Z","updated_at":"2025-03-14T13:31:13.658Z","avatar_url":"https://github.com/Constantin1489.png","language":"Python","funding_links":[],"categories":["\u003ca name=\"flashcard\"\u003e\u003c/a\u003eAnki, decks and flashcards"],"sub_categories":[],"readme":"# ToRRential Card processor\n\n* [INTRODUCTION](#introduction)\n* [INSTALLATION](#installation)\n    * [PIP](#pip)\n    * [MANUAL_INSTALLATION](#manual-installation)\n* [USAGE](#usage)\n* [CONFIG_FILE](#config-file)\n* [LOCATIONS](#locations)\n* [OPTIONS](#options)\n* [FAQ](#faq)\n* [CHANGELOG](#changelog)\n* [CONTRIBUTION](#contribution)\n\n## INTRODUCTION\n\n**ToRRential Card processor**(**trrc**) is a command-line unix-like program to create anki cards using AnkiConnect plugin.(Think a yt-dlp, but this program is for adding cards into Anki.)\n\nI intent to make it as a Unix-like program. Therefore it **leverages a lot of Unix concepts**.\n\n- It **supports a standard input, PIPE, redirection.** Therefore, you can add bulk cards after mangling your cards with your favorite text editors. With the benefit of unix-like program, you can make a convenient script yourself with your favorite text editors like Vim, Emacs, VScode and so on. See [Usage](#usage)\n\n- It has **shell completions(Zsh, Bash)**.\n\n- It **adds multiple cards at once** using [`--file`](#–file-option) or [PIPE](#pipe) and so on. See [Usage](#usage)\n\n- It also **supports options for ip, port and apikey**. So even some environments you don't want to install Anki, you can add cards if your Anki is running in your home or somewhere, boundlessly.\n\n- It also supports a **rc(config) file** with a alias to reuse options you uses frequently.\n\n- you can **sync Anki** with option `--sync` of **trrc** with or without soon after adding cards.\n\n- It's **user-friendly**. In well-known cases, **trrc** provides solutions. If you\n  mistake deck name, it will print all deck name available. If your field is\n  wrong, it will print field of the card type used.\n\n```sh\n# default card type is 'Basic'\n$trrc --field 'fron:bakc:tags' 'What is GPL?\tThe GNU General Public License is a free, copyleft license for software and other kinds of works.\tLICENSE::GPL'\n#### Kinds of failures: 1\ntrrc Tip: --field 'Front:Back:Tags'\n\nYou don't have to use all those fields.\nFor example, if all field of a type is 'Front:Back:Source:Sound:Tags',\nyou can use only some of them. e.g.: 'Front:Back:Tags'.\n####\nTotal cards: 1 Total fails: 1\n```\n\nSee [Youtube demonstration video of the author](https://www.youtube.com/watch?v=-3jCwUEAOHE)\n\n***if you decide to use this app, I highly recommend to turn apikey option in your AnkiConnect to prevent malicious attack. (It's not a fault of this app nor AnkiConnect. If the port of AnkiConnect opens without an apikey, anybody can modify your anki deck.)*** See also [AnkiConnect Configure](docs/tips/AnkiConnect_configure/AnkiConnect_addon_configure_example.md)\n\n## INSTALLATION\n\n### pip\n`pip install trrc`\n\n### Manual installation\n`pip install -r requirements.txt`\n\n`pip install .`\n\n### Install AnkiConnect addon in Anki.\n\n## USAGE\nTo solve common mistakes, I wrote a lot of examples.\n\n### Standard Input\n```sh\n# the blank characters except a spacebar in 'Korean Conversation' is a tab.\n# the default IFS is a tab.\ntrrc '안녕\tHello\tKorean Conversation'\n          # ^         ^\n          #tab character\n\n# -F is --IFS. It sets a Internal Field Separator. Mobile devices may not\n#support a tab character in their keyboard. In that case, you should use --IFS\n#options. (e.g.:-F@)\ntrrc \"back\\ttestfront\\tvim\" -F '\\t'\n\n# you can set whatever character you want.\ntrrc --IFS % '안녕%Hello%Korean'\ntrrc -F @ '안녕@Hello@Korean'\n\n# you can choose only part of the fields of the card type.\n# you can change order of the fields.\ntrrc --field 'Arbitrary4thField:Arbitrary2ndFieldName:tags' 'FourthContent\\tsecondContent\\ttag'\n\n# to send your card to other computer(e.g.: ip is 192.168.1.230, port is 4832).\ntrrc --ip 192.168.1.230 --port 4832 --file Korean_English_conversation.txt\n```\n\n#### # To use '\\t' as a tab character in an standard input argument, you need to use '$' in front of the string.\n```sh\ntrrc $'안녕\\tHello\\tKorean'\n      ^\n```\nSee also [How to use '\\t' in a card content?](#how-to-use-‘%5Ct’-in-a-card-content%3F)\n\n### PIPE\n\nTo use PIPE, put `-` in the argument.\n\n```sh\necho 'basic_type_front_normal_tab with option\tbasic_type_back\tbasic_type_tag' | trrc -\n```\n\n```sh\n# bash: \\t\necho -e 'basic_type_front_normal_tab with option\\tbasic_type_back\\tbasic_type_tag' | trrc - -t 'Basic (and reversed card)' --field 'Front:Back:tag'\n\n# bash: using a tab\necho 'basic_type_front_normal_tab with option\tbasic_type_back\tbasic_type_tag' | trrc - -t 'Basic (and reversed card)' --field 'Front:Back:tag'\n\n# zsh: \\t\necho 'basic_type_front_normal_tab with option\\tbasic_type_back\\tbasic_type_tag' | trrc - -t 'Basic (and reversed card)' --field 'Front:Back:tag'\n\n# bash: using a tab\necho 'basic_type_front_normal_tab with option\tbasic_type_back\tbasic_type_tag' | trrc - -t 'Basic (and reversed card)' --field 'Front:Back:tag'\n\n# zsh: using a tab\necho 'basic_type_front_normal_tab with option\tbasic_type_back\tbasic_type_tag' | trrc - -t 'Basic (and reversed card)' --field 'Front:Back:tag'\n```\n\n#### PIPE with `cat`\n\n##### example_file_IFS_default.txt\nIf you use '\t'(a tab) as a IFS like a below,\n```\n#example_file_IFS_deafult.txt\nfront\tback\ttest\nfront2\tback\ttest\n```\nthen you don't have to use `--IFS` option.\n\n```sh\ncat example_file_IFS_deafult.txt | trrc -\n```\n\n##### example_file_IFS_backslash_t.txt\nIf you use '\\t' as a IFS like a below,\n```\n#example_file_IFS_backslash_t.txt\nfront\\tback\\ttest\nfront2\\tback\\ttest\n```\nthen use a command like this.\n\n```sh\ncat example_file_IFS_backslash_t.txt | trrc - --IFS '\\t'\n```\n\n#### HEREDOC Standard Input\n```sh\ntrrc --IFS '\\t' - \u003c\u003cEOF\nfront\tback\ttest\nfront2\tback\ttest\nEOF\n```\n\n#### HEREDOC PIPE\n```sh\ncat \u003c\u003cEOF | trrc - --IFS '\\t'\nfront\tback\ttest\nfront2\tback\ttest\nEOF\n```\n\n## Config File\n\n*trrc*'s config file extension is `.trrc`.\n\nSee [LOCATIONS](#locations) and [How to create a trrc config file](#how-to-create-a-trrc-config-file%3F)\n\n## Locations\n\nBy default, *trrc* searches for rc(config) files in directories of the below.\nIt means if you wrote the config file(only *.trrc*, without any file name.) there,\ntrrc import the setting in the files if they exists in order.\n\nmacOS, Linux:\n\n* `${HOME}/.trrc` # e.g. : `~/.trrc`\n\n* `./.trrc` # working directory.\n\n### Locations: macOS e.g.\n* `/Users/username/.trrc`\n\n* If you are in `/Users/username/study/english/`, then also, `/Users/username/study/english/.trrc`\n\n### Locations: Linux e.g.\n* `/home/username/.trrc`\n\n* If you are in `/home/username/study/english/`, then also, `/home/username/study/english/.trrc`\n\n## Options\n\n```\nusage: trrc [-h] [-D DECK] [-t CARDTYPE] [-i IP] [-p PORT] [-f [FILE ...]]\n            [-c FILE] [--alias SECTION] [-F IFS]\n            [--field COLON:DELIMITER-SEPARATED:FIELDS]\n            [--cloze-field COLON:DELIMITER-SEPARATED:FIELDS]\n            [--cloze-type CLOZE_TYPE] [--toml-generate] [--toml-write FILE]\n            [--toml-section SECTION] [-H] [--apikey APIKEY] [--sync]\n            [--force-add] [--dry-run] [--read-file-in-a-content] [-v]\n            [--debug [FILE]] [-V]\n            [cardContents ...]\n\nA command-line program to create Anki cards using AnkiConnect API.\n\npositional arguments:\n  cardContents          a string divided by IFS. the default IFS is a tab\n                        character. instead of a string, It can also take a\n                        file consists of strings without '--FILE' option.\n\noptions:\n  -h, --help            show this help message and exit\n  -D DECK, --deck DECK  set a Deck. the default is 'default'.\n  -t CARDTYPE, --type CARDTYPE\n                        set a card type. the default is 'Basic'.\n  -i IP, --ip IP        set a ip that AnkiConnect specified. the default is\n                        '127.0.0.1'.\n  -p PORT, --port PORT  set a port number that AnkiConnect specified. the\n                        default is '8765'.\n  -f [FILE ...], --file [FILE ...]\n                        set a file that contains card contents.\n  -c FILE, --config FILE\n                        set a config file to import config options. without\n                        this option, this program searches '~/.trrc'.\n  --alias SECTION       set a section of a config file to apply options.\n                        without this argument, the default is 'default'.\n  -F IFS, --IFS IFS     set a delimiter of card contents to use any character\n                        other than a tab character. the default is a tab\n                        character.\n  --field COLON:DELIMITER-SEPARATED:FIELDS\n                        set a card field corresponding to the cardContents.\n                        the default is 'Front:Back:Tags'.\n  --cloze-field COLON:DELIMITER-SEPARATED:FIELDS\n                        set a cloze type card field corresponding to the\n                        cardContents. The default is 'Text:Back Extra:Tags'.\n  --cloze-type CLOZE_TYPE\n                        set a type of a fallback for a cloze type. the default\n                        is 'cloze'. if user set --field option, then the\n                        default won't work. even a string contains cloze, the\n                        program will process as a field unless user set\n                        --cloze-type\n  --toml-generate       print toml configs with current arguments. to set a\n                        section of it, use it with '--toml-section' option.\n  --toml-write FILE     write a config file with options used. to set a\n                        section, use '--toml-section'.\n  --toml-section SECTION\n                        set a toml section. the default is 'untitled'.\n  -H, --render-HTML     set to allow to render a HTML tag. the default doesn't\n                        allow render a HTML tag, therefore \u003cbr\u003e won't be a new\n                        line.\n  --apikey APIKEY       set an api key for AnkiConnect. if it is specified,\n                        --debug options will mask it because of security\n                        concern.\n  --sync                sync Anki. if there is a card to process, trrc syncs\n                        after adding the card. the default is not to sync.\n  --force-add           create a card even if there is a duplicate in the\n                        deck.\n  --dry-run             perform a trial run without sending to Anki.\n  --read-file-in-a-content\n                        set to allow to replace a file in contents with its\n                        contents. a default setting doesn't read it\n  -v, --verbose         print a card being currently processed.\n  --debug [FILE]        print debug information. if you specify FILE, trrc\n                        writes debug there.\n  -V, --version         print a version number and a license of trrc.\n```\n\n### --file option\n\n#### examplefile.txt\nThis is an example which trrc takes. IFS is a tab which is a default IFS.\n\n```\nAnki\tAnki is a free and open-source flashcard program using spaced repetition\tanki\nTo make a log message in python, What library Should I use?\tlogging\tpython::library\n```\n* `trrc --file examplefile.txt`\n\n\n### --read-file-in-a-content\nLet's say you are learning Rust Language.\nSave this statements in a text file called 'rust_hello.txt'\n```rust\nfn main() {\n        println!(\"Hello, world!\");\n}\n```\n\nand create a card with `--read-file-in-a-content` option\n\n```sh\ntrrc '[Rust] print \"Hello, world!\"\trust_hello.txt\trust::println' --read-file-in-a-content\n```\n\ntrrc will read the file 'rust_hello.txt' and use it as a content.\n## FAQ\n\n### How to add several tags?\n\nA tag is a word. Therefore a spacebar will separate tags.\n\nSo for example, (IFS of tags is a tab character as a default.): `CS linux::http linux::network`\n\n```sh\ntrrc '[linux] port 80\tHTTP's port\tCS linux::http linux::network'\n```\n\ntrrc will interpret `CS linux::http linux::network` as a list which is `['CS', 'linux::http', 'linux::network']`\n\n### How to create a trrc config file?\n\ncreate config file with `.trrc` extension.\n\nLet's say your previous command was\n```sh\ntrrc -F@ --type 'Basic' --ip 127.0.0.1 --field 'Front:Back:Tags' --deck 'Computer Science' 'What is GPL?@The GNU General Public License is a free, copyleft license for software and other kinds of works.@LICENSE::GPL'\n```\n\nBefore creating a default config file, you should check the config.\n\nSo, add `--toml-generate` to print configs.\n\nAlso, set a section name with `--toml-section SECTION`\n\ne.g.:\n```sh\ntrrc -F@ --type 'Basic' --ip 127.0.0.1 --field 'Front:Back:Tags' --deck 'Computer Science' 'What is GPL?@The GNU General Public License is a free, copyleft license for software and other kinds of works.@LICENSE::GPL' --toml-generate --toml-section 'CS'\n\n```\n***But if you want to use the config as a default, then `--toml-section 'default'`***\n\ntrrc will print,\n```sh\n[CS]\ndeck = \"Computer Science\"\ncardtype = \"Basic\"\nip = \"127.0.0.1\"\nifs = \"@\"\nfield = \"Front:Back:Tags\"\n```\n\nIf there is nothing wrong, copy the text and paste to `~/.trrc`\nor use `--toml-write`\n\n```sh\ntrrc -F@ --type 'Basic' --ip 127.0.0.1 --field 'Front:Back:Tags' --deck 'Computer Science' 'What is GPL?@The GNU General Public License is a free, copyleft license for software and other kinds of works.@LICENSE::GPL' --toml-section 'CS' --toml-write ~/.trrc\n```\nAnd you can reuse your config with `--alias CS`.\n\n\nAlso you can overwrite the config with an argument,\n```sh\n--alias CS --IFS ^\n```\nIt will use CS config but IFS is '^'.\n\n### How to reuse the specific config?\n\nIf your config file has 'CS' section, the append `--alias 'CS'` in your command.\n\n### Tip for writing your own script.\n\nIn the case with your own script, for a backup purpose, I recommend to create a temp file to use `--file` option or PIPE.\n\nAvoid to use the modules of the library directly because it's alpha version.\n\nThis program's License is GPL3. See [License](LICENSE).\n\nIf you need to submit your code using trrc, discuss with the person concerned about the license.\n\n### How to use '\\t' in a card content?\n\nYes, It's possible to interpret `\\t` as a tab. But in a default '\t'(tab) IFS,\nthe shell behavior that doesn't interpret '\\t' as a tab character is a normal\nbehavior, therefore if you add a card using '\\t' as a IFS in a standard\ninput, you need to use `--IFS '\\t'` or put `$` in front of single qoute.\n- [ ] add detailed explanation.\n\n```sh\nset -x\necho 'front\tback\ttest'\necho 'front\\tback\\ttest'\necho $'front\\tback\\ttest'\nset +x\n```\n\n### How to add a new line?\n\nUse `\\n` to make a new line.\n```\ntrrc 'First line\\nSecond line\tback\ttag'\n```\n\n### How to open a port?\n\nBasically, when you are running anki with an AnkiConnect addon, the port(default is 8765) of AnkiConnect opens.\n\nBut if your want to send a card using **trrc** from outside of your computer which is running Anki with AnkiConnect, you may need to modify firewall option on the computer or a router.\n\n### How to make iOS shortcuts with **trrc**\n\nSee [iOS_shortcuts_example](docs/tips/iOS_shortcuts_setting_example/iOS_shortcuts_example.md)\n\n## Changelog\n\n| Version | Note                     | \n|:--------|:-------------------------|\n| HEAD    | add shell completion. | \n| 0.1.2    | fix sync option error handle. | \n| 0.1.1   | init                     | \n\n## Contribution\n\nThank you for letting me know the bug! Please report the bug in [issue tracker](https://github.com/Constantin1489/trrc/issues).\n\nPersonally I like this app as a method to add cards and use daily, so I will keep developing it. Because I'm trying to get a job, an update delivery can be slow. But after getting a job, I will learn some good clean code conventions and apply it.\n\nCurrently I'm writing tests to guarantee a basic functionality, documents and comments on codes.\n\nAlso there won't be massive changes for a while. Because I think I should\nredesign the program for scalability. Think about making card from 'git-diff'. To make such functions quickly I need to redesign.\n\nIf there is changes, I'll write how it changes, examples on how to change your codes.\n\nI'm happy to accept criticism, PR, and so on.\n\nThere are a lot of grammar mistakes. English is not my language. Catch! PR! PLEASE!\n\nIf you're good at unix, linux, or shell, please enlighten me! I really want to hear about book recomendations, cli program to benchmark and so on.\n\n## TODO\n\n- [ ] remove dependency: requests lib.\n- [ ] windows support.\n    - py2exe\n    - file path (e.g.: default config file)\n- [ ] send media files directly to Anki.\n- [ ] create card from git-diff, git-show\n    - option: --mode=git --header 'Optimize logging message\\n\t\t'\n    - without --header, use git commit message as header.\n- [ ] support markdown, mad type and so on.\n    - --vertical?\n    - Pseudo HEREDOC mode.\n- [ ] get fields of a deck.\n    - error handle.\n- [ ] support shell environment variable.\n    - prefix: TRRC\n    - e.g.: TRRC_deck, TRRC_tag: global tag\n- [ ] new verbose purpose.\n    - -v : stdout, other logging format.\n- [ ] add reliable and insightful pytests\n- [x] config file option\n- [x] HTML interpret on-off mode.\n    - [x] \\\u003cbr\\\u003e \u0026lt, \u0026gt \u0026 HTML on \u003c-\u003e HTML off and `\\n`\n        - [x] First, change every HTML tags to \u0026gt \u0026lt. then change \\n to \u003cbr\u003e\n    - [x] should it be a HTML off mode a default?\n- [ ] Embedding modules: allow trrc as a module to use in python script.\n- [x] Error message: file doesn't exist.\n- [x] search rc file in the working directory.\n- [ ] use # comment in a file as a temporary card option or method switcher.\n    - [ ] Allow adding card vertically\n        - [ ] #NEW FRONT(field)\n        - [ ] #DONE TAGS\n    - [ ] change option with # -F%\n        - [ ] back to option of stdin\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FConstantin1489%2Ftrrc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FConstantin1489%2Ftrrc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FConstantin1489%2Ftrrc/lists"}