Giter Site home page Giter Site logo

Comments (5)

thiswillbeyourgithub avatar thiswillbeyourgithub commented on September 27, 2024 1

For reference : I'm using some more naive code :

from ankipandas import Collection, find_db
from shutil import copy
from pathlib import Path

original_db = find_db(user=profile_name)  # profile name supplied by user, None to use the first found
Path.mkdir(Path("cache"), exist_ok=True)  # create cache folder
temp_db = copy(original_db, f"cache/{deckname.replace(' ', '_')}")  # copying database to cache

col = Collection(path=temp_db)  # load ankipandas on the temporary directory

I'll use this in the future but I think it's still a very valuable feature to implement (for example with an argument like read_only=True)

Thanks a lot for being so reactive and helpful last time, it was very useful and I'm really appreciative of it.

Have a nice day!

from ankipandas.

klieret avatar klieret commented on September 27, 2024

Hi @thiswillbeyourgithub AnnA looks really cool!

How about a quick & dirty approach: You can probably simply copy the database file to a temporary directory and open that. This will basically give you read only access.
So something like this (not tested at all, from top of my head):

from pathlib import Path
import shutil
import tmpfile
import ankipandas as ap
db_path = ap.paths.find_db()
with tempfile.TemporaryDirectory() as tmpdirname:
    new_loc = Path(tempdirname) / db_path.name
    shutil.copy(db_path, new_loc)
    col = ap.Collection(new_loc)
    # do your stuff with the collection
# Copy will get deleted

from ankipandas.

thiswillbeyourgithub avatar thiswillbeyourgithub commented on September 27, 2024

Thanks a bunch, I thought about doing this but was not sure about how to create temporary file on all platforms.

Thanks a lot!

from ankipandas.

klieret avatar klieret commented on September 27, 2024

Sure, let me know if it works!

from ankipandas.

thiswillbeyourgithub avatar thiswillbeyourgithub commented on September 27, 2024

I'll try to, but I won't try it for quite some time. Don't wait for me :)

from ankipandas.

Related Issues (20)

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.