From 2049ca9fca939bc4a07e8ac3d6b7c064b87898b4 Mon Sep 17 00:00:00 2001 From: 0x5c Date: Tue, 25 Feb 2020 19:45:32 -0500 Subject: [PATCH] Fix HamStudy image error - Fixed the image link - Removed unused import (pytz) - Added test pool file to dev-notes Fixes #203 --- CHANGELOG.md | 2 ++ dev-notes/test_pool_E5C14.json | 48 ++++++++++++++++++++++++++++++++++ exts/study.py | 3 +-- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 dev-notes/test_pool_E5C14.json diff --git a/CHANGELOG.md b/CHANGELOG.md index dd798c8..237f333 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Fixed issue where HamStudy questions with images would cause an error. ## [2.2.1] - 2020-02-20 diff --git a/dev-notes/test_pool_E5C14.json b/dev-notes/test_pool_E5C14.json new file mode 100644 index 0000000..c167c55 --- /dev/null +++ b/dev-notes/test_pool_E5C14.json @@ -0,0 +1,48 @@ +{ + "_id": "56956f51f65e5c590272e372", + "appears": "2016-04-01T06:00:00.000Z", + "class": "Amateur Extra", + "subtext": "Expires Jul 1, 2020", + "valid_from": "2016-07-01T06:00:00.000Z", + "expires": "2020-07-01T06:00:00.000Z", + "official_name": "Element 4", + "id": "E4_2016", + "slug": "extra2016", + "passing": 37, + "year": 2016, + "pool": [{ + "_id": "5cd63f15910d9b003d545bd7", + "qcount": 4, + "id": "E5", + "name": "ELECTRICAL PRINCIPLES", + "sections": [{ + "_id": "5cd63f15910d9b003d545beb", + "id": "E5C", + "questions": [{ + "_id": "5cd63f15910d9b003d545bef", + "keywords": ["4"], + "answer": "B", + "answers": { + "A": "Point 2", + "B": "Point 4", + "C": "Point 5", + "D": "Point 6" + }, + "fccpart": "", + "id": "E5C14", + "image": "E5-2.png", + "text": "Which point on Figure E5-2 best represents the impedance of a series circuit consisting of a 400 ohm resistor and a 38 picofarad capacitor at 14 MHz?" + }], + "summary": "Coordinate systems and phasors in electronics: Rectangular Coordinates; Polar Coordinates; Phasors" + }] + }], + "updated": "2019-05-11T03:18:46.121Z", + "category": "default", + "testIdEnd": 19999, + "testIdStart": 10000, + "__v": 12, + "mat_icon": "flash_on", + "tagline": "Serious General operators only! This is the most advanced US license class!", + "keywords": ["ham radio extra test prep", "amateur extra class radio study", "amateur extra class ham exam", "ham radio amateur extra test 2016", "2016 amateur extra class", "ham radio license exam", "extra class flash card"], + "replaces": "E4_2012" +} diff --git a/exts/study.py b/exts/study.py index 774c35e..f55dd9a 100644 --- a/exts/study.py +++ b/exts/study.py @@ -14,7 +14,6 @@ from datetime import datetime import asyncio import aiohttp -import pytz import discord.ext.commands as commands @@ -134,7 +133,7 @@ class StudyCog(commands.Cog): " the answer will be revealed."), inline=False) if "image" in question: - image_url = f"https://hamstudy.org/_1330011/images/{pool.split('_',1)[1]}/{question['image']}" + image_url = f"https://hamstudy.org/images/{pool_meta['year']}/{question['image']}" embed.set_image(url=image_url) q_msg = await ctx.send(embed=embed)