Skip to content

Commit

Permalink
Switching to new ankiweb API (#7)
Browse files Browse the repository at this point in the history
* anker/anki_proto: Add protobuf files for a new Anki API

Recently, ankiweb change it's API and this changed was drastic.
They moved from html forms and bare http-requests to Protobuf
communication and sending binary Protobuf structures over http.

These are the Protobuf files used by ankiweb I handcrafted from
the frontend.

* requirements.txt: add protobuf

The version is fixed to work with current python version.
I picked it up from the error:
```
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
```

* setup.cfg: exclude *_pb2.py files from flake8

* Dockerfile: add protobuf-files generation

* anker: use new ankiweb's Protobuf API

* anker/bot/sticker_storage.py: add http requests timeout

* requirements.txt: remove unused beautifulsoup4 and lxml

* requirements/requirements-dev.txt: add types-protobuf

* tests/anki_api: skip tests and remove unused

* .gitignore: add *_pb2.py

* setup.cfg: fix mypy checks

* requirements/requirements-dev.txt: update some requirements

* Fix mypy issues

* .github/workflows/python-app.yml: generate protobuf files first
  • Loading branch information
szobov authored Aug 1, 2023
1 parent ff27625 commit a763909
Show file tree
Hide file tree
Showing 24 changed files with 274 additions and 475 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ jobs:
python-version: "3.10"
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y libzbar0
sudo apt-get update && sudo apt-get install -y libzbar0 protobuf-compiler
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements/requirements-dev.txt
- name: Generate python's protobuf files
run: |
protoc --python_out=. ./anker/anki_proto/*.proto
- name: Test with pytest
run: |
pytest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
run.sh

### Python ###
*_pb2.py
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -160,4 +161,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM python:3.10-slim

COPY requirements.txt /app/requirements.txt
WORKDIR /app/
RUN apt-get update && apt-get install -y libzbar0 && python -m pip install -U pip && pip install -r requirements.txt
RUN apt-get update && apt-get install -y libzbar0 protobuf-compiler && python -m pip install -U pip && pip install -r requirements.txt

COPY anker/card_generation/translation.py /app/anker/card_generation/translation.py
WORKDIR /app/anker/card_generation/
Expand All @@ -11,4 +11,6 @@ RUN python -c 'import translation; translation.initialize_translation_packages()
WORKDIR /app/
COPY . .

RUN protoc --python_out=. ./anker/anki_proto/*.proto

CMD ["bash", "run.sh"]
Loading

0 comments on commit a763909

Please sign in to comment.