generated from GrafeasGroup/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from GrafeasGroup/56-subreddits-command
Add subreddits command to count submissions per subreddit
- Loading branch information
Showing
19 changed files
with
294 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from utonium import Payload, Plugin | ||
|
||
from bubbles.config import blossom | ||
from bubbles.utils import parse_time_constraints, TimeParseError | ||
|
||
|
||
def subreddits(payload: Payload) -> None: | ||
""" | ||
!subreddits [start time] [end time] - Get transcription counts by subreddit | ||
Usage: `!subreddits` or `!subreddits 2023-02-20 2023-02-27 | ||
""" | ||
parts = payload.get_text().split() | ||
|
||
start_text = parts[1] if len(parts) >= 2 else "1 week" | ||
end_text = parts[2] if len(parts) >= 3 else "now" | ||
|
||
try: | ||
start, end, time_str = parse_time_constraints(start_text, end_text) | ||
except TimeParseError: | ||
payload.say("Invalid time specified, please check the format.") | ||
return | ||
|
||
response = blossom.get( | ||
"submission/subreddits/", | ||
params={ | ||
"completed_by__isnull": False, | ||
"complete_time__gte": start, | ||
"complete_time__lte": end, | ||
}, | ||
) | ||
|
||
if not response.ok: | ||
payload.say( | ||
f"Sorry, but something went wrong. Please try again later.\n{response.text}" | ||
) | ||
return | ||
|
||
data = response.json() | ||
response_txt = "\n".join(f"- r/{sub}: {count}" for sub, count in data.item()) | ||
|
||
payload.say(response_txt) | ||
|
||
|
||
PLUGIN = Plugin(func=subreddits, regex=r"^subreddits.*") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.