diff --git a/Dockerfile b/Dockerfile index ada29f9..bdb3b87 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY /requirements/* /app/requirements/ RUN pip install -r /app/requirements/dev.txt # pyppeteer deps (https://stackoverflow.com/a/71935536) -RUN xargs apt-get install -y --no-install-recommends < /app/requirements/pyppeteer_deps.txt +# RUN xargs apt-get install -y --no-install-recommends < /app/requirements/pyppeteer_deps.txt # diff --git a/articles/migrations/0001_initial.py b/articles/migrations/0001_initial.py index 4395ec6..3a6252d 100644 --- a/articles/migrations/0001_initial.py +++ b/articles/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.0.1 on 2024-02-18 12:41 +# Generated by Django 5.0.1 on 2024-02-26 20:25 import django.db.models.deletion import django.db.models.functions.text @@ -24,7 +24,7 @@ class Migration(migrations.Migration): ), ), ( - "name", + "title", models.CharField( help_text="The name of the source", max_length=128, unique=True ), @@ -97,7 +97,7 @@ class Migration(migrations.Migration): ), ], options={ - "ordering": [django.db.models.functions.text.Lower("name")], + "ordering": [django.db.models.functions.text.Lower("title")], }, ), migrations.CreateModel( diff --git a/articles/models.py b/articles/models.py index 0c37f29..9c4c00a 100644 --- a/articles/models.py +++ b/articles/models.py @@ -74,7 +74,7 @@ class Source(models.Model): Metadata about the source of articles Fields: - name (models.CharField): name of the source + title (models.CharField): name of the source slug (models.SlugField): slug of the source publication_type (models.CharField): the type of publication of the source (newspaper, journal, blog...) @@ -97,7 +97,7 @@ class Source(models.Model): scraper """ - name = models.CharField( + title = models.CharField( max_length=128, unique=True, blank=False, @@ -164,11 +164,11 @@ class Source(models.Model): class Meta: ordering = [ - Lower("name"), + Lower("title"), ] def __str__(self): - return f"{self.name}" + return f"{self.title}" def to_dict(self): sitemap = { diff --git a/articles/tasks.py b/articles/tasks.py index ee5c151..49bcbd2 100644 --- a/articles/tasks.py +++ b/articles/tasks.py @@ -10,8 +10,8 @@ @shared_task -def get_articles_for_source(source_title: str): - source: Source = Source.objects.get(name=source_title) +def get_articles_for_source(source_title: str) -> None: + source: Source = Source.objects.get(title=source_title) sitemap = source.to_dict() starting_urls = [ sitemap["base_url"] + path for path in sitemap["paths"] @@ -19,18 +19,18 @@ def get_articles_for_source(source_title: str): spider = scraper.Spider(starting_urls, sitemap) spider.run() - data = [json.loads(article) for article in spider.articles] + articles = [json.loads(article) for article in spider.articles] Article.objects.bulk_create([ Article( headline=article_data["headline"], slug=article_data["slug"], - source=Source.objects.get(link=article_data["source_link"]), + source=Source.objects.get(url=article_data["source_link"]), summary=article_data["summary"], language=article_data["language"], url=article_data["url"], created_at=timezone.now(), - ) for article_data in data + ) for article_data in articles ], ignore_conflicts=True) diff --git a/articles/templates/articles/index.html b/articles/templates/articles/index.html index ae695cf..6ec749d 100644 --- a/articles/templates/articles/index.html +++ b/articles/templates/articles/index.html @@ -9,7 +9,7 @@
{% for source in sources %}
- +