Add Resources Command#2117
Conversation
Bluenix2
left a comment
There was a problem hiding this comment.
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.
Bluenix2
left a comment
There was a problem hiding this comment.
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.
|
@Bluenix2 - Added function to convert to kebab-case. (suggested here https://discord.com/channels/267624335836053506/635950537262759947/958979773189742602). Code adopted from: |
wookie184
left a comment
There was a problem hiding this comment.
Thanks for the PR, this works nicely! Just two small things, other than that this seems good.
wookie184
left a comment
There was a problem hiding this comment.
Thanks for making those changes, this seems good to me now!
vivekashok1221
left a comment
There was a problem hiding this comment.
Excellent work, friend. Minor nitpick.
|
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.
Bluenix2
left a comment
There was a problem hiding this comment.
Awesome, thank you going through with this PR!
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:
!resources data science @iamericfletcherlink the user to the resources page without any filtering applied.!resources data science & discord botswith URLs utilizing the%2Cseparator - https://www.pythondiscord.com/resources/?topics=data-science%2Cdiscord-bots