Skip to content

Add Resources Command#2117

Merged
wookie184 merged 2 commits into
python-discord:mainfrom
iamericfletcher:2079
Apr 3, 2022
Merged

Add Resources Command#2117
wookie184 merged 2 commits into
python-discord:mainfrom
iamericfletcher:2079

Conversation

@iamericfletcher
Copy link
Copy Markdown
Contributor

@iamericfletcher iamericfletcher commented Mar 17, 2022

Hi, everyone.

This pull request is in reference to approved issue #2079.

Demonstration of new resources command:

Kapture.2022-03-15.at.21.08.38.mp4

Notes:

@iamericfletcher iamericfletcher marked this pull request as ready for review March 17, 2022 01:51
Copy link
Copy Markdown
Contributor

@Bluenix2 Bluenix2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on your first pull request! Thanks ❤️.

Please look at the comments I made and to be clear, nothing here is an order and it's simply my ideas noted down so it's open for discussion if you do not agree with it.

Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
@Bluenix2 Bluenix2 added the s: waiting for author Waiting for author to address a review or respond to a comment label Mar 18, 2022
@Xithrius Xithrius added a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) p: 3 - low Low Priority t: enhancement Changes or improvements to existing features labels Mar 18, 2022
@Bluenix2 Bluenix2 added s: needs review Author is waiting for someone to review and approve and removed s: waiting for author Waiting for author to address a review or respond to a comment labels Mar 21, 2022
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py Outdated
Copy link
Copy Markdown
Contributor

@MaskDuck MaskDuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Copy link
Copy Markdown
Contributor

@Bluenix2 Bluenix2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this, I tried it out and it's working as expected! Very nice work here.

I do have one comment that would allow us to simplify the code.

Comment thread bot/exts/info/resources.py Outdated
@iamericfletcher
Copy link
Copy Markdown
Contributor Author

Copy link
Copy Markdown
Contributor

@wookie184 wookie184 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, this works nicely! Just two small things, other than that this seems good.

Comment thread bot/exts/info/resources.py Outdated
Comment thread bot/exts/info/resources.py
Copy link
Copy Markdown
Contributor

@wookie184 wookie184 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making those changes, this seems good to me now!

@vivekashok1221 vivekashok1221 self-requested a review April 2, 2022 16:06
Copy link
Copy Markdown
Contributor

@vivekashok1221 vivekashok1221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work, friend. Minor nitpick.

Comment thread bot/exts/info/resources.py Outdated
Copy link
Copy Markdown
Contributor

@vivekashok1221 vivekashok1221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected.
LGTM. 🌟

@iamericfletcher
Copy link
Copy Markdown
Contributor Author

iamericfletcher commented Apr 2, 2022

Putting this here for reference if needed in the future:

from typing import Optional

import requests
from bs4 import BeautifulSoup
from discord import Embed
from discord.ext import commands

from bot.bot import Bot

RESOURCES_URL = "https://www.pythondiscord.com/resources/"
SITE_TOPICS_TITLE_CASE = []


def get_topics():
    """Scrape Python Discord website for updated list of topics to include in embed."""
    topics_split = []
    topics_title = ""
    dont_capitalize = ["for", "and", "nor", "but", "or", "yet", "so", "in", "of", "a", "an"]
    page = requests.get(RESOURCES_URL)
    soup = BeautifulSoup(page.content, 'html.parser')
    # Obtain the topics using CSS selector
    topics_initial = soup.select('label.checkbox input[data-filter-name="topics"]')
    # Split topics at the dash, add to list, prep for iteration over each word
    for topic in topics_initial:
        topics_split.append(topic['data-filter-item'].split("-"))
    # Iterate over each word in order to title case and remove the OTHER category (not helpful to include in embed)
    for topic in topics_split:
        for word in range(0, len(topic)):
            if topic[word] != "other":
                if topic[word] not in dont_capitalize:
                    topics_title += topic[word].title() + " "
                if topic[word] in dont_capitalize:
                    topics_title += topic[word] + " "
                if word == len(topic) - 1:
                    SITE_TOPICS_TITLE_CASE.append(topics_title)
                    topics_title = ""

We can use this cog to get a URL with resources filtered by the terms
input by the user in the Discord command.
Copy link
Copy Markdown
Contributor

@Bluenix2 Bluenix2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you going through with this PR!

@wookie184 wookie184 enabled auto-merge April 3, 2022 18:02
@wookie184 wookie184 merged commit fc0ddf2 into python-discord:main Apr 3, 2022
@Xithrius Xithrius removed the s: needs review Author is waiting for someone to review and approve label May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) p: 3 - low Low Priority t: enhancement Changes or improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants