Skip to content

Python News implemention#899

Merged
SebastiaanZ merged 36 commits into
python-discord:masterfrom
ks129:python-news
May 13, 2020
Merged

Python News implemention#899
SebastiaanZ merged 36 commits into
python-discord:masterfrom
ks129:python-news

Conversation

@ks129
Copy link
Copy Markdown
Contributor

@ks129 ks129 commented Apr 21, 2020

Closes #890
Site issue (stalled until it merged): python-discord/site#352

Summary of what is done

  • Added 2 new dependencies: feedparser (used in PEP news fetching) and beautifulsoup4 (used in maillist news fetching)
  • Set the log level of logger chardet to warning to avoid log spam.
  • bot.cogs.news extension loading added to __main__.py
  • Added news config entries + constants
  • Created News cog
    • Added fetching PEP news
    • Added fetching maillist news
    • Added following helper functions: sync_maillists, get_webhook_names, check_new_exist, send_webhook, get_thread_and_first_mail and get_webhook_and_channel.

ks129 added 16 commits April 19, 2020 20:09
Added general content of cog: class and setup.
Function sync maillists listing with API, that hold IDs of message that have news. PEPs handling is over RSS, so this will added manually in this function.
`News.get_webhook` fetch discord.Webhook by ID provided in config. `self.webhook` use webhook that it got from this function.
…nnel and webhook.

This use local dev environment IDs.
Removed Webhook and Channel from their listings, created new class `PythonNews` that hold them + mail lists.
Replaced in-file mail lists with constants.py's, replaced webhook ID getting.
- Created task `post_pep_news` that pull existing news message IDs from API, do checks and send new PEP when it's not already sent.
- Removed `get_webhook`
- Removed `self.webhook`
…ook_names`

Function fetch display names of these mail lists, that bot will post. These names will be used on Webhook author names. `News.webhook_names` storage these name and display name pairs.
…date check

- Created helper function `News.get_thread_and_first_mail`
- Created helper function `News.send_webhook`
- Created helper function `News.check_new_exist`
- Task `post_maillist_news`, that send latest maillist threads to news, when they don't exist.
- Implemented helper functions to PEP news
- Added date check
- Created new helper function `News.get_webhook_and_channel` to will be run in Cog loading and will fetch #python-news channel and webhook.
- Fixed `News.send_webhook` when you pass `None` as author, this will not add author.
- Replaced individual channel and webhook fetches with `News.webhook` and `News.channel`.
- Replaced positional arguments with kwargs in `send_webhook` uses.
- Moved maillists syncing from `News.__init__` to `News.post_maillist_news`.
- Simplified `News.post_pep_news` already exist checks.
@ks129 ks129 requested a review from a team as a code owner April 21, 2020 06:02
@kwzrd kwzrd added a: dependencies Related to package dependencies and management a: information Related to information commands: (doc, help, information, reddit, site, tags) p: 2 - normal Normal Priority status: needs review t: feature New feature or request labels Apr 21, 2020
Copy link
Copy Markdown
Member

@jb3 jb3 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 the contribution ks, I've left a couple of proposals on improvements to the feature.

Comment thread bot/cogs/news.py
Comment thread bot/cogs/news.py Outdated
ks129 added 2 commits April 27, 2020 08:21
- Added footer to webhook sent message
- Made `send_webhook` return `discord.Message` instead ID of message
- Added waiting for Webhook on `send_webhook`
- Added message publishing in new loops
Added `features="lxml"` to `BeautifulSoup` class creating to avoid warning.
@ks129 ks129 requested a review from jb3 April 27, 2020 08:14
Comment thread config-default.yml Outdated
Comment thread config-default.yml Outdated
Co-Authored-By: Joseph <joseph@josephbanks.me>
@MrHemlock MrHemlock self-requested a review April 30, 2020 13:13
Copy link
Copy Markdown
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

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

I've got some concerns on how well this will scale. If we have 100 posts in the channel (not an unachievable number) and there are 10 new ones without any caches in the bot (not unlikely since we restart a lot) we will be making 1,000 API calls. A better way to do this is not use Discord for this and instead store the ID of the thread, using the thread_id property of the mailman API (see below) and compare against that.

Comment thread bot/cogs/news.py Outdated
Comment thread bot/cogs/news.py Outdated
@MrHemlock MrHemlock removed their request for review April 30, 2020 13:22
ks129 and others added 4 commits May 1, 2020 15:46
- Removed (now) unnecessary helper function `News.check_new_exist`.
- Use thread IDs instead message IDs on maillists checking to avoid Discord API calls.
- Use PEP number instead message IDs on PEP news checking to avoid Discord API calls.
Comment thread bot/cogs/news.py Outdated
In `News` cog PEP news posting, define `utf-8` as encoding on response parsing to avoid the error.

Co-authored-by: Joseph Banks <joseph@josephbanks.me>
@ks129 ks129 requested a review from jb3 May 2, 2020 06:02
Comment thread bot/cogs/news.py Outdated
Copy link
Copy Markdown
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

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

Getting very close with this one now, looking almost ready!

Co-authored-by: Joseph Banks <joseph@josephbanks.me>
Copy link
Copy Markdown
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

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

This looks good to me! Seems we've handled most of the oddities provided by the PEP URL and the mailing list API!

Comment thread bot/cogs/news.py Outdated
Comment thread config-default.yml Outdated
Comment thread bot/cogs/news.py Outdated
Copy link
Copy Markdown
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

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

Not everything has been updated to use the new filename

Comment thread bot/__main__.py Outdated
Co-authored-by: Joseph Banks <joseph@josephbanks.me>
@ks129 ks129 requested review from SebastiaanZ and jb3 May 7, 2020 18:47
Copy link
Copy Markdown
Contributor

@lemonsaurus lemonsaurus left a comment

Choose a reason for hiding this comment

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

lgtm

@SebastiaanZ SebastiaanZ merged commit 64e81d2 into python-discord:master May 13, 2020
@ks129 ks129 deleted the python-news branch May 13, 2020 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: dependencies Related to package dependencies and management a: information Related to information commands: (doc, help, information, reddit, site, tags) p: 2 - normal Normal Priority t: feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relay Python language news to #python-news

5 participants