Skip to content

Commit

Permalink
Merge pull request #438 from Xpirix/fix_fetch_feeds_and_resize_logo
Browse files Browse the repository at this point in the history
Fix fetch_feeds script, add image resizing process
  • Loading branch information
Xpirix authored Sep 24, 2024
2 parents f3e9985 + 1922068 commit 602e4bb
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 21 deletions.
1 change: 1 addition & 0 deletions REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ tomli==2.0.1
typing_extensions==4.4.0
urllib3==1.26.13
icalendar==5.0.12
pillow==10.4.0
65 changes: 44 additions & 21 deletions fetch_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
import json
import shutil
import os
from rss_parser import Parser
from requests import get
import atoma
from dateutil.parser import parse as date_parse
try:
import urlparse
except ImportError:
from urllib.parse import urlparse
from scripts.resize_image import resize_image

### Funders
def fetch_funders():
"""
Fetch the sustaining members from the QGIS changelog
and create markdown files
"""
response = requests.get("https://changelog.qgis.org/en/qgis/members/json/")
data = json.loads(response.text)
items = data["rss"]["channel"]["item"]
Expand Down Expand Up @@ -64,6 +67,13 @@ def fetch_funders():
shutil.copyfileobj(response.raw, out_file)
print(f"Writing: {image_filename}")
del response
try:
if level.lower() in ["flagship", "large"]:
resize_image(image_filename, max_height=150)
else:
resize_image(image_filename)
except Exception as e:
print(f"Error resizing image: {e}")

### Flickr screenshots
def fetch_flickr_screenshots(showcase_type, rss_url):
Expand Down Expand Up @@ -188,25 +198,38 @@ def fetch_blog_feed(showcase_type, rss_url):
parser.parse_args()
args = parser.parse_args()

fetch_funders()
try:
fetch_funders()
except Exception as e:
print(f"Error fetching funders: {e}")

if args.flickr:
fetch_flickr_screenshots(
showcase_type="map",
rss_url = "https://api.flickr.com/services/feeds/groups_pool.gne?id=2244553@N22&lang=en-us&format=atom"
)
fetch_flickr_screenshots(
showcase_type="screenshot",
rss_url = "https://api.flickr.com/services/feeds/groups_pool.gne?id=2327386@N22&lang=en-us&format=atom"
try:
if args.flickr:
fetch_flickr_screenshots(
showcase_type="map",
rss_url = "https://api.flickr.com/services/feeds/groups_pool.gne?id=2244553@N22&lang=en-us&format=atom"
)
fetch_flickr_screenshots(
showcase_type="screenshot",
rss_url = "https://api.flickr.com/services/feeds/groups_pool.gne?id=2327386@N22&lang=en-us&format=atom"
)
except Exception as e:
print(f"Error fetching flickr screenshots: {e}")

try:
# Planet blog aggregator
fetch_blog_feed(
showcase_type="planet",
rss_url="https://plugins.qgis.org/planet/feed/atom/"
)
except Exception as e:
print(f"Error fetching planet blog feed: {e}")

# Planet blog aggregator
fetch_blog_feed(
showcase_type="planet",
rss_url="https://plugins.qgis.org/planet/feed/atom/"
)
# QGIS User group feed
fetch_blog_feed(
showcase_type="qug",
rss_url="https://raw.githubusercontent.com/qgis/QGIS-Website/master/source/feeds/qugsnews.atom"
)
try:
# QGIS User group feed
fetch_blog_feed(
showcase_type="qug",
rss_url="https://raw.githubusercontent.com/qgis/QGIS-Website/main/source/feeds/qugsnews.atom"
)
except Exception as e:
print(f"Error fetching QUG blog feed: {e}")
45 changes: 45 additions & 0 deletions scripts/resize_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from PIL import Image
import os


def resize_image(image_filename, max_height=120):
"""
Resize an image to a maximum height, keeping the aspect ratio.
The image is resized in place.
param image_filename: The image file to resize
param max_height: The maximum height in pixels
"""
if (
image_filename.lower().endswith('.png') or
image_filename.lower().endswith('.jpg')
):
if os.path.exists(image_filename):
print(f'Processing: {image_filename}')
with Image.open(image_filename) as img:
width, height = img.size
if height > max_height:
new_height = max_height
new_width = int((new_height / height) * width)

img_resized = img.resize(
(new_width, new_height), Image.LANCZOS
)

# Determine the file format
file_format = (
'PNG' if image_filename.lower().endswith('.png')
else 'JPEG'
)

# Save the resized image with optimization
img_resized.save(
image_filename,
format=file_format,
optimize=True,
quality=85
)
print(f'Resized and optimized: {image_filename}')
else:
print(f'No resizing needed for: {image_filename}')
else:
print(f'File not found: {image_filename}')
File renamed without changes.

0 comments on commit 602e4bb

Please sign in to comment.