Git Product home page Git Product logo

lingqankisync's Introduction

Lingq Anki Sync

Codacy Badge

See it on AnkiWeb

Requirements

You will need your lingq API key. You can get that here.

The language code for the lingq language you want to sync with. Example: "es"

Usage

A menu item to open the ui can be found under Tools > Import LingQs from LingQ.com.

Main Ui

Input your lingq api key and language code, then select the deck you want to sync lingqs to or that you want to sync lingq known status based on the card interval. (Currently you should create a new deck only used for lingq's and import into that new deck, and only sync from that deck).

Click the "import" button to import all of your lingqs for that language code into the selected anki deck.

Click the "sync to Lingq" button to update the "known status" on your lingqs based on the interval of the card in anki. (As a precaution this addon will not set a lower known status in lingq, it will only raise it).

Be Patient, either of these operations will take some time. Once the operation completes you will see this screen and it will tell you how many Lingqs were imported.

Main Ui

After importing your API key and language code should be preserved for the next time you want to import or sync!

What does it currently do?

As the name implies the goal is to sync between lingq and anki. This addon is currently in early development, but it has the following features:

  • Import lingq's from a specified language to anki cards
    • This will also set the due date of the anki card based on the "known status" in Lingq.
      • The current status to interval definition is: {0: 0, 1: 5, 2: 10, 3: 20, 4: 40}
        • Lingq status : Interval (due date will be current day + interval)
        • 1 : 0
        • 2 : 5
        • 3 : 10
        • 4 : 20
        • 'known' : 40
  • Cards are rudimentary currently, just the word on the front and the translation on the back.
  • You can modify the look of the card, but the fields that are generated are required and can not be altered at this time.
  • Sync lingq status based on the interval of the anki card.
    • This will update your known status on lingq.
    • This uses the reverse of the lingq status : interval shown above.
    • For example, if your card interval is 21, then it will set your lingq status as 4
    • There is a built in check, it will never lower your lingq status.
      • This is done as a precaution to not remove lingq progress

Why does it exist?

Lingq is a great tool for reading in your target language, but I prefer to use anki as my SRS. Lingq has an option to export lingqs to anki, however it has some flaws which this addon attempts to address:

  1. The cards it sends you have no history, they all start as a "new" status in anki even if your lingq status for the card was "known".
  2. There is no syncing between anki and lingq. If I import a card from lingq that has a known status of "1", then review it in anki until I know the word, lingq will not update. This means I wouldn't get an accurate % words known when looking at lingq lessons and it breaks the flow to mark an already known word as known in lingq manually. The reverse is also true, if I start reading on lingq and mark a word as known, that word could still be shown as new in anki.
  3. If you add a new lingq you have to create a full new anki export via the lingq website. Sometimes anki decks don't merge well, so you could lose progress in anki just to import a new word from lingq.
  4. The lingq API documentation is not very good. I want to document some of the undocumented API calls available.

Future Goals

  • Import to custom note type.
  • Allow user to define what interval relates to what lingq known status.
  • Sync lingq status to previously imported lingqs
  • Better error catching and handling
  • Save settings for each language synced with lingq (what deck, note type, etc)
  • Allow to "sign in" with username and password instead of needing to copy / paste API key

Lingq API Documentation

This is a temporary measure, hopefully lingq updates their own API docs, or I may make a better one than this

Authentication

There is an API endpoint to retrieve your API key for lingq in their documentation. It's easiest to use this in dev at least.

Api auth key is set up in postman as

Type: API Key
Key: Authorization
value: Token {apiKey}
add to: Header

Objects

Lingq object

Lingq object is refering to a single lingq (word).

{
    "pk": primaryKey,
    "url": url to get single card info,
    "term": string,
    "fragment": string,
    "importance": int,
    "status": int,
    "extended_status": null,
    "last_reviewed_correct": null,
    "srs_due_date": date,
    "notes": string,
    "audio": null,
    "words": string[],
    "tags": string[],
    "hints": hintObject[],
    "transliteration": {},
    "gTags": [],
    "wordTags": [],
    "readings": {}
}

Hint object

{
    "id": int,
    "locale": string,
    "text": string,
    "term": string,
    "popularity": int,
    "is_google_translate": bool,
    "flagged": bool
}

GET

1. Get lingqs from a language

https://www.lingq.com/api/v3/{languageCode}/cards

Will return this json with the first 100 lingqs:

{
    "count": int,
    "next": string,
    "previous": string,
    "results": [
        List of lingq objects
    ]
}

Add ?page={pageNumber} to return a specific page of cards

2. Get single card by primary key

https://www.lingq.com/api/v3/{languageCode}/cards/{primaryKey}/

Will return a single lingq object that matches the primaryKey within the language code. If an invalid primaryKey is supplied the api will return a 404 Not found with a return body of

{
    "detail": "Not Found."
}

Patch

1. Update a lingq object

https://www.lingq.com/api/v2/{languageCode}/cards/{primarykey}/

Body Json object of the items that will be changing in the lingq object. Example:

{
    "status": 2
}

Note: Not all fields of the object can be updated here. I have tested the following:

  1. status (the known status, 0-5).
  2. tags

Post

1. Set card reviewed

https://www.lingq.com/api/v2/{languageCode}/cards/{primaryKey}/review/

Tells lingq that the card has been reviewed via srs on the date this is sent. Will update lingqs srs_due_date.

It seems like this needs to be called instead of changing the due date manually with the patch request.

Returns an object showing the new srs_due_date and status_changed_date:

{
    "srs_due_date": date,
    "status_changed_date": date
}

lingqankisync's People

Contributors

codacy-badger avatar sviatoslav-lebediev avatar thags avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lingqankisync's Issues

Sync from anki to lingq

We can currently add cards to a deck imported from lingq. We need to be able to sync the "known status" from anki back to lingq.

This will require some arbitrary decisions on what intervals equal what lingq status (0,1,2,3,4).

On import set due date as a range instead of a set date

Basically want to be able to have cards set to review staggered instead of so many in one day.

If importing 12k Lingqs and all of them are "known" then all of them will be set to review in 40 days. This could be a random range instead. So instead of 40 days it could be anywhere from 40 days to 40 + x days.

AttributeError

Hi,
thank you for this very useful addon. I recently started getting the following error, after pressing "Import LinQs from Linq.com"

Traceback (most recent call last):
  File "C:\Users\ercan\AppData\Roaming\Anki2\addons21\594879777\popUpWindow.py", line 93, in <lambda>
    action.triggered.connect(lambda: UI().run())
  File "C:\Users\ercan\AppData\Roaming\Anki2\addons21\594879777\popUpWindow.py", line 19, in __init__
    QPushButton("Import"), QDialogButtonBox.AcceptRole)
AttributeError: type object 'QDialogButtonBox' has no attribute 'AcceptRole'

My System info is the following:

Anki 23.12.1 (1a1d4d54)  (ao)
Python 3.9.15 Qt 6.6.1 PyQt 6.6.1
Platform: Windows-10-10.0.19045

Thank you very much

BUG: Import from LINQ seems to be broken.

Steps to reproduce

  1. Menu Tools -> Import LingQs
  2. Immediate error pops up

image

Seems like this might be a regression related to the upgrade to pyqt 6?

Debug Log:

Anki 23.12.1 (1a1d4d54) (src) (ao)
Python 3.11.8 Qt 6.6.2 PyQt 6.6.1
Platform: Linux-6.8.2-zen1-1-zen-x86_64-with-glibc2.39

Traceback (most recent call last):
  File "/home/notnight/.local/share/Anki2/addons21/594879777/popUpWindow.py", line 93, in <lambda>
    action.triggered.connect(lambda: UI().run())
                                     ^^^^
  File "/home/notnight/.local/share/Anki2/addons21/594879777/popUpWindow.py", line 19, in __init__
    QPushButton("Import"), QDialogButtonBox.AcceptRole)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'QDialogButtonBox' has no attribute 'AcceptRole'

===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
Lingq Anki Sync ['594879777', 2023-12-25T14:25, 'None', '']
More Overview Stats 21 ['738807903', 2021-07-30T13:13, 'None', '']
PassFail 2 Remove the Easy and Hard buttons ['876946123', 2023-01-23T18:59, 'None', '']
Review Heatmap ['1771074083', 2022-06-29T19:43, 'None', '']

===IDs of active AnkiWeb add-ons===
1771074083 594879777 738807903 876946123

===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])

Dependency unavailable

Hi, I added the add-on via the normal mechanism and restarted anki. It's the only add-on I have.

When loading '⁨Lingq Anki Sync⁩':
⁨Traceback (most recent call last):
  File "aqt.addons", line 247, in loadAddons
  File "/home/abby/.var/app/net.ankiweb.Anki/data/Anki2/addons21/594879777/__init__.py", line 1, in <module>
    from .popUpWindow import UI
  File "/home/abby/.var/app/net.ankiweb.Anki/data/Anki2/addons21/594879777/popUpWindow.py", line 6, in <module>
    from .UIActionHandler import ActionHandler
  File "/home/abby/.var/app/net.ankiweb.Anki/data/Anki2/addons21/594879777/UIActionHandler.py", line 1, in <module>
    from .Converter import ConvertAnkiCardsToLingqs, ConvertLingqsToAnkiCards
  File "/home/abby/.var/app/net.ankiweb.Anki/data/Anki2/addons21/594879777/Converter.py", line 4, in <module>
    from Models.Lingq import Lingq
ModuleNotFoundError: No module named 'Models'

⁩My system info is:

Anki 2.1.60 (76d88073) Python 3.9.15 Qt 6.4.2 PyQt 6.4.0
Platform: Linux-5.15.0-69-generic-x86_64-with-glibc2.35
Flags: frz=True ao=True sv=2    

Anki was installed via flatpak.
I've looked into this directory "/.../net.ankiweb.Anki/.../594879777/" and ./Models/ and it's .py files on your github exist there.

Typo in LingqAPI.py

The add-on currently doesn't seem to sync back properly to lingq, although you can pull vocabulary from the LingQ website.

I believe the error lies in this string

    def __init__(self, apiKey, languageCode):
        self.apiKey = apiKey
        self.languageCode = languageCode
        self._baseUrl = f"https://www.lingq.com/api/v3/{languageCode}/cards/"
        self.unformatedLingqs = []
        self.lingqs = []

I think if you simply remove the / on the end of cards, it will resolve

    def __init__(self, apiKey, languageCode):
        self.apiKey = apiKey
        self.languageCode = languageCode
        self._baseUrl = f"https://www.lingq.com/api/v3/{languageCode}/cards"
        self.unformatedLingqs = []
        self.lingqs = []

Resolve some tech debt

  • General clean up.
  • Refactor a lot of stuff (create some classes, try to organize into folders, create a handler for actions that need do things on both the anki and lingq side).
  • create tests

issue when installing

Hi, when I try to install the addon and I restart it, it shows me this message :

"Traceback (most recent call last):
File "aqt/addons.py", line 230, in loadAddons
File "/Users/pierreg/Library/Application Support/Anki2/addons21/594879777/init.py", line 1, in
from .popUpWindow import UI
File "/Users/pierreg/Library/Application Support/Anki2/addons21/594879777/popUpWindow.py", line 6, in
from .UIActionHandler import ActionHandler
File "/Users/pierreg/Library/Application Support/Anki2/addons21/594879777/UIActionHandler.py", line 1, in
from .Converter import ConvertAnkiCardsToLingqs, ConvertLingqsToAnkiCards
File "/Users/pierreg/Library/Application Support/Anki2/addons21/594879777/Converter.py", line 7, in
def ConvertAnkiCardsToLingqs(ankiCards: list[AnkiCard], statusToInterval: dict[int:int]) -> list[Lingq]:
TypeError: 'type' object is not subscriptable"

mac OS Big sur 11.7.4
Anki version : 2.1.49
Python 3.8.6 Qt 5.14.2 PyQt 5.14.2

On the anki addon link --> Supported Anki versions: 2.1.6-2.1.16+ (Updated 2023-03-20)

Thanks.

429 Client Error

Hi folks,

The add-on has been working swimmingly for a couple of months on my end, but I'm now getting this error when trying to sync:

429 Client Error: Too Many Requests for url: https://www.lingq.com/api/v2/fi/cards/452013826/

I tried deleting the card referenced in the URL, but the error just happens again with a different card. I've tried to sync about five times in the past 12 hours.

Any thoughts?

[Tip] LingQ cannot modify review time through the review API

lingqAnkiSync/readme.md

Lines 186 to 201 in b479154

#### 1. Set card reviewed
`https://www.lingq.com/api/v2/{languageCode}/cards/{primaryKey}/review/`
Tells lingq that the card has been reviewed via srs on the date this is sent. Will update lingqs srs_due_date.
It seems like this needs to be called instead of changing the due date manually with the patch request.
Returns an object showing the new srs_due_date and status_changed_date:
```json
{
"srs_due_date": date,
"status_changed_date": date
}
```

I tried to modify the scheduling time through https://www.lingq.com/api/v2/ja/cards/508507061/review/, and I found that even if I don't fill in srs_due_date and status_changed_date, the scheduling is still based on the current time (including time zone information), which is determined by the card's status and extended_status.

image
  • If status=0, the scheduling time is 1 day.
  • If status=1, the scheduling time is 3 days.
  • If status=2, the scheduling time is 7 days.
  • If status=3, the scheduling time is 15 days.
  • If status=3 and extended_status=3, then the scheduling time is 5000 days.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.