ankit

package module
v0.0.0-...-74f8117 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 2 Imported by: 3

README

ankit

🔨 CSV export tool for Anki.

Anki

leetcode2anki

leetcode2anki will print CSV data from your LeetCode repository and corresponding question data. It use SQLite to store LeetCode question data. If data is not exist, it will be fetched from LeetCode API.

Therefore, you need to import CSV to your Anki.

Export LeetCode Repository to CSV
leetcode2anki -lang golang > leetcode.csv
Customize for your repository structure

If your LeetCode repository is different from mine, you need to change question and code function in leetcode2anki/main.go:

My LeetCode Repository structure:

LeetCode
├── 0003
│   ├── code.go
│   └── code_test.go
├── 0004
│   ├── code.go
│   └── code_test.go
└── 0007
    ├── code.go
    └── code_test.go
func question(path string, info os.FileInfo) (leetcode.Key, error) {
	if path == "." || !info.IsDir() {
		return nil, nil
	}
	// only handle directory in repository
	id, err := strconv.Atoi(path)
	if err != nil {
		return nil, filepath.SkipDir
	}
	// identify leetcode question by id
	return leetcode.KeyID(id), filepath.SkipDir
}

func code(path string, _ leetcode.Lang) (string, error) {
	fset := token.NewFileSet()

	f, err := parser.ParseFile(fset, filepath.Join(path, "code.go"), nil, parser.ParseComments)
	if err != nil {
		return "", err
	}
	// start from import declarations, then format code
	var w strings.Builder
	if err := format.Node(&w, fset, f.Decls); err != nil {
		return "", err
	}

	return w.String(), nil
}

Python example:

LeetCode
├──add-two-numbers.py
├──reverse-integer.py
└──two-sum.py
func question(path string, info os.FileInfo) (leetcode.Key, error) {
	if path == "." {
		return nil, nil
	}
	// skip directory in repository
	if info.IsDir() {
		return nil, filepath.SkipDir
	}

	filename := filepath.Base(path)
	ext := filepath.Ext(filename)
	// only handle python file
	if ext != ".py" {
		return nil, nil
	}
	// identify leetcode question by title slug: filename
	slug := strings.TrimSuffix(filename, ext)
	return leetcode.KeyTitleSlug(slug), nil
}

func code(path string, _ leetcode.Lang) (string, error) {
	b, err := ioutil.ReadFile(path)
	return string(b), err
}
Import CSV to Anki
  1. Get Anki note type from Shared Deck.
  2. Import CSV file in Anki.

Import CSV

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(dst io.Writer, src Reader) error

Copy copies from src to dst until either EOF is reached on src or an error occurs.

Types

type Note

type Note interface {
	Fields() []string
}

Note consists of fields.

type Reader

type Reader interface {
	Read() (fields []string, err error)
}

Reader is the interface that wraps the basic Read method.

func OneNoteReader

func OneNoteReader(n Note) Reader

OneNoteReader returns a Reader with only one Note.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL