Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.10.1 #59

Merged
merged 7 commits into from
Oct 15, 2024
Merged
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
See for sample https://raw.githubusercontent.com/favoloso/conventional-changelog-emoji/master/CHANGELOG.md
-->

## [0.10.1] - 2024-09-15
### 🛠 Improvements
- Improve side navigation (#55)
- Improve favicon scrapper (#56)

## [0.10.0] - 2024-09-14
### ✨ Feature
- Display Favicons (#38)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ python ../scheduler/start_celery_beat.py
or using docker

```
docker-compose -f docker-compose-scheduler.yaml --env-file=scheduler/.env up -d
docker-compose -f docker-compose-beat.yaml --env-file=.env up -d
```

### Worker
Expand All @@ -83,13 +83,13 @@ Worker will listen to tasks and run then individually

```
cd src
python ../scheduler/start_celery_worker.py
python ../worker/start_celery_worker.py
```

or using docker

```
docker-compose -f docker-compose-worker.yaml --env-file=worker/.env up -d
docker-compose -f docker-compose-worker.yaml --env-file=.env up -d
```

## Running documentation
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# The short X.Y version.
version = '0.10'
# The full version, including alpha/beta/rc tags.
release = '0.10.0'
release = '0.10.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion src/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

VERSION = [0, 10, 0]
VERSION = [0, 10, 1]

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')
Expand Down
222 changes: 108 additions & 114 deletions src/core/templates/application.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{% block favicon %}<link rel="shortcut icon" type="image/svg" href="{% static 'favicon.svg' %}" />{% endblock %}
{% tailwind_css %}
{% block css %}{% endblock %}
<script src="//unpkg.com/alpinejs"></script>
</head>
<body class="bg-gray-50 leading-normal tracking-normal {% block body_class %}{% endblock %}">
{% block body %}{% endblock %}
Expand Down
34 changes: 18 additions & 16 deletions src/projects/signals.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
from django.utils import timezone
from django.db.models.signals import pre_save
from django.db.models.signals import post_save
from django.dispatch import receiver
from .tasks.fetch_favicon import fetch_favicon
from .models import Project

DELAY_REFRESH_FAVICON_SECONDS = 10 # Every 10 seconds
DELAY_REFRESH_FAVICON_SECONDS = 30 # Every 30 seconds

@receiver(pre_save, sender=Project)
def post_save_fetch_favicon(sender, instance=None, **kwargs):
@receiver(post_save, sender=Project)
def post_save_fetch_favicon(sender, instance, created, **kwargs):
favicon_need_refresh = False

# Fetch the existing instance from the database if it exists
if instance.pk:
try:
old_instance = Project.objects.get(pk=instance.pk)
# Check if the favicon value has changed
if old_instance.favicon != instance.favicon:
instance.favicon_task_status = 'SUCCESS'
instance.favicon_last_edited = timezone.now()
except Project.DoesNotExist:
# If the object does not exist in the database, it's a new object
favicon_need_refresh = True
else:
try:
old_instance = Project.objects.get(pk=instance.pk)
# Check if the favicon value has changed
if old_instance.favicon != instance.favicon:
instance.favicon_task_status = 'SUCCESS'
instance.favicon_last_edited = timezone.now()
except Project.DoesNotExist:
# If the object does not exist in the database, it's a new object
favicon_need_refresh = True

if created:
# If instance.pk is None, it's a new object
favicon_need_refresh = True

if instance.favicon_task_status == 'UNKNOWN':
favicon_need_refresh = True
if (timezone.now() - instance.favicon_last_edited).seconds > DELAY_REFRESH_FAVICON_SECONDS and instance.favicon_task_status != 'PENDING':

if (timezone.now() - instance.favicon_last_edited).seconds > DELAY_REFRESH_FAVICON_SECONDS:
favicon_need_refresh = True

if favicon_need_refresh:
instance.favicon_task_status = 'PENDING'
instance.favicon_last_edited = timezone.now()
fetch_favicon.delay(instance.pk, instance.url)
51 changes: 30 additions & 21 deletions src/projects/tasks/fetch_favicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,36 @@ def fetch_favicon(pk, url):
largest_favicon = None
largest_size = (0, 0)

for favicon_url in favicons:
try:
# Fetch the favicon image
favicon_response = requests.get(favicon_url, timeout=10)
favicon_response.raise_for_status()

# Open the image and get its size
image = Image.open(BytesIO(favicon_response.content))
width, height = image.size

# Update the largest favicon if this one is larger
if width * height > largest_size[0] * largest_size[1]:
largest_size = (width, height)
largest_favicon = {
'url': favicon_url,
'width': width,
'height': height,
}

except Exception as e:
print(f"Error fetching or processing {favicon_url}: {e}")
# If one url in favicon end with svg we keep this ad largest favicon
sebastienbarbier marked this conversation as resolved.
Show resolved Hide resolved
if any(favicon_url.endswith('.svg') for favicon_url in favicons):
largest_favicon = {
'url': next(favicon_url for favicon_url in favicons if favicon_url.endswith('.svg')),
'width': 0,
'height': 0,
}
print(f"Largest favicon found: {largest_favicon} (SVG)")
sebastienbarbier marked this conversation as resolved.
Show resolved Hide resolved
else:
for favicon_url in favicons:
try:
# Fetch the favicon image
favicon_response = requests.get(favicon_url, timeout=10)
favicon_response.raise_for_status()

# Open the image and get its size
image = Image.open(BytesIO(favicon_response.content))
width, height = image.size

# Update the largest favicon if this one is larger
if width * height > largest_size[0] * largest_size[1]:
largest_size = (width, height)
largest_favicon = {
'url': favicon_url,
'width': width,
'height': height,
}

except Exception as e:
print(f"Error fetching or processing {favicon_url}: {e}")

if largest_favicon:
print(f"Largest favicon found: {largest_favicon['url']} ({largest_favicon['width']}x{largest_favicon['height']})")
Expand Down
Loading