Source code for berhoel.django.media_ooimport.console.filme
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""Process the `Film` sheet.
"""
# Standard library imports.
from collections import namedtuple
# First party library imports.
from berhoel.helper import count_with_msg
from berhoel.django.media.models import Film, Seen, Person, Purchase
# Local library imports.
from ._helper import get_media
__date__ = "2022/08/01 23:47:58 hoel"
__author__ = "Berthold Höllmann"
__copyright__ = "Copyright © 2020 by Berthold Höllmann"
__credits__ = ["Berthold Höllmann"]
__maintainer__ = "Berthold Höllmann"
__email__ = "berhoel@gmail.com"
FilmRow = namedtuple("FilmRow", ("date", "name", "index", "options", "desc", "price"))
[docs]class Filme:
"Convert information on films seen."
[docs] def __init__(self, table):
"""
Args:
table (berhoel.odf.ods.Ods): OpenOffice table.
"""
self.table = table
[docs] def process(self) -> None:
"Process film entries."
rows = zip(self.table.rows, count_with_msg("Importing 'filme', line"))
_ = next(rows)
for row, _ in rows:
row = FilmRow(*row.cells[:6])
if row.date.date is None:
break
media, index = get_media(
media=row.price, index=row.index.text, name=row.name.text
)
film, _ = Film.objects.get_or_create(
title=row.name.text,
imdb_url=row.name.url,
dvd_index=index,
options=row.options.text,
medium=media,
desc=row.desc.text,
)
Seen.objects.create(date=row.date.date, watch_item=film)
if row.price.link is None and row.price.float > 0.0:
vendor, _ = Person.objects.get_or_create(name=row.index.text)
purchase = Purchase.objects.create(
date=row.date.date, price=row.price.float, vendor=vendor
)
purchase.media.set([media])
purchase.save()
# Local Variables:
# mode: python
# compile-command: "poetry run tox"
# time-stamp-pattern: "30/__date__ = \"%:y/%02m/%02d %02H:%02M:%02S %u\""
# End: