From 7dbd3f8cb4a3e08834689bb307faf60a4ba8741a Mon Sep 17 00:00:00 2001 From: rly0nheart <74001397+rly0nheart@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:28:53 +0200 Subject: [PATCH 1/9] Added counter in posts and comments ouptut --- knewkarma/_project.py | 2 +- knewkarma/api.py | 2 +- knewkarma/base.py | 14 ++++++++------ knewkarma/data.py | 10 ++++++---- pyproject.toml | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/knewkarma/_project.py b/knewkarma/_project.py index 1b81dc6..951aac0 100644 --- a/knewkarma/_project.py +++ b/knewkarma/_project.py @@ -6,7 +6,7 @@ author: str = "Richard Mwewa" about_author: str = "https://about.me/rly0nheart" -version: str = "3.3.1.0" +version: str = "3.3.2.0" # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # diff --git a/knewkarma/api.py b/knewkarma/api.py index 888273e..88c0b60 100644 --- a/knewkarma/api.py +++ b/knewkarma/api.py @@ -117,7 +117,7 @@ async def get_updates(session: aiohttp.ClientSession): if remote_parts[0] != local_parts[0]: update_message = ( f"[bold][red]MAJOR[/][/] update ({remote_version}) available:" - f" It might introduce significant changes." + f" Introduces significant and important changes." ) # ---------------------------------------------------------- # diff --git a/knewkarma/base.py b/knewkarma/base.py index 76f5b14..8f6026e 100644 --- a/knewkarma/base.py +++ b/knewkarma/base.py @@ -110,11 +110,12 @@ async def comments(self, session: aiohttp.ClientSession) -> List[Comment]: session=session, ) - for raw_comment in raw_comments: + for comment_index, raw_comment in enumerate(raw_comments, start=1): comment_data: dict = raw_comment.get("data") comment = Comment( + index=comment_index, + body=comment_data.get("body"), id=comment_data.get("id"), - text=comment_data.get("body"), author=comment_data.get("author"), author_is_premium=comment_data.get("author_premium"), upvotes=comment_data.get("ups"), @@ -250,13 +251,14 @@ def __init__( @staticmethod def process_posts(raw_posts: list) -> List[Post]: posts_list: list = [] - for raw_post in raw_posts: + for post_index, raw_post in enumerate(raw_posts, start=1): post_data = raw_post.get("data") post = Post( - id=post_data.get("id"), - thumbnail=post_data.get("thumbnail"), + index=post_index, title=post_data.get("title"), - text=post_data.get("selftext"), + thumbnail=post_data.get("thumbnail"), + id=post_data.get("id"), + body=post_data.get("selftext"), author=post_data.get("author"), subreddit=post_data.get("subreddit"), subreddit_id=post_data.get("subreddit_id"), diff --git a/knewkarma/data.py b/knewkarma/data.py index ef57322..c2cfbf8 100644 --- a/knewkarma/data.py +++ b/knewkarma/data.py @@ -50,10 +50,11 @@ class Subreddit: @dataclass class Post: - id: str - thumbnail: str + index: int title: str - text: str + thumbnail: str + id: str + body: str author: str subreddit: str subreddit_id: str @@ -81,8 +82,9 @@ class Post: @dataclass class Comment: + index: int + body: str id: str - text: str author: str upvotes: int downvotes: int diff --git a/pyproject.toml b/pyproject.toml index cb169d5..d5a3f03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "knewkarma" -version = "3.3.1.0" +version = "3.3.2.0" description = "A Reddit Data Analysis Toolkit." authors = ["Richard Mwewa "] readme = "README.md" From 29274bc0865b543419571f7f37d39e79e259a090 Mon Sep 17 00:00:00 2001 From: rly0nheart <74001397+rly0nheart@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:34:40 +0200 Subject: [PATCH 2/9] Removed 'examples' directory (code examples will be available in the README) --- examples/posts.py | 29 ----------------------------- examples/subreddit.py | 41 ----------------------------------------- examples/user.py | 42 ------------------------------------------ 3 files changed, 112 deletions(-) delete mode 100644 examples/posts.py delete mode 100644 examples/subreddit.py delete mode 100644 examples/user.py diff --git a/examples/posts.py b/examples/posts.py deleted file mode 100644 index 5369880..0000000 --- a/examples/posts.py +++ /dev/null @@ -1,29 +0,0 @@ -import asyncio - -import aiohttp - -from knewkarma import RedditPosts - - -async def async_posts(timeframe: str, limit: int, sort: str): - # Initialize RedditPosts with the specified timeframe, limit and sorting criteria - posts = RedditPosts(timeframe=timeframe, limit=limit, sort=sort) - - # Create an asynchronous HTTP session - async with aiohttp.ClientSession() as session: - # Fetch front page posts - front_page_posts = await posts.front_page(session=session) - # Fetch posts from a specified listing ('best') - listing_posts = await posts.listing(listings_name="best", session=session) - # Fetch posts that match the specified search query 'covid-19' - search_results = await posts.search(query="covid-19", session=session) - - print(front_page_posts) - print(listing_posts) - print(search_results) - - -# Run the asynchronous function with a specified limit and sorting parameter -# timeframes: ["all", "hour", "day", "month", "year"] -# sorting: ["all", "controversial", "new", "top", "best", "hot", "rising"] -asyncio.run(async_posts(timeframe="year", limit=100, sort="all")) diff --git a/examples/subreddit.py b/examples/subreddit.py deleted file mode 100644 index 1ff9099..0000000 --- a/examples/subreddit.py +++ /dev/null @@ -1,41 +0,0 @@ -import asyncio - -import aiohttp - -from knewkarma import RedditSub - - -async def async_subreddit( - subreddit_name: str, data_timeframe: str, data_limit: int, data_sort: str -): - # Initialize a RedditSub object with the specified subreddit, data timeframe, limit, and sorting criteria - subreddit = RedditSub( - subreddit=subreddit_name, - data_timeframe=data_timeframe, - data_limit=data_limit, - data_sort=data_sort, - ) - - # Create an asynchronous HTTP session - async with aiohttp.ClientSession() as session: - # Fetch subreddit's profile - profile = await subreddit.profile(session=session) - - # Fetch subreddit's posts - posts = await subreddit.posts(session=session) - - print(profile) - print(posts) - - -# Run the asynchronous function with specified subreddit name, data limit, and sorting criteria -# timeframes: ["all", "hour", "day", "month", "year"] -# sorting: ["all", "controversial", "new", "top", "best", "hot", "rising"] -asyncio.run( - async_subreddit( - subreddit_name="MachineLearning", - data_timeframe="year", - data_limit=100, - data_sort="top", - ) -) diff --git a/examples/user.py b/examples/user.py deleted file mode 100644 index 6a6a49e..0000000 --- a/examples/user.py +++ /dev/null @@ -1,42 +0,0 @@ -import asyncio - -import aiohttp - -from knewkarma import RedditUser - - -async def async_user( - username: str, data_timeframe: str, data_limit: int, data_sort: str -): - # Initialize a RedditUser object with the specified username, data timeframe, limit, and sorting criteria - user = RedditUser( - username=username, - data_timeframe=data_timeframe, - data_limit=data_limit, - data_sort=data_sort, - ) - - # Establish an asynchronous HTTP session - async with aiohttp.ClientSession() as session: - # Fetch user's profile - profile = await user.profile(session=session) - - # Fetch user's posts - posts = await user.posts(session=session) - - # Fetch user's comments - comments = await user.comments(session=session) - - print(profile) - print(posts) - print(comments) - - -# Run the asynchronous function with a specified username, data limit, and sorting parameter -# timeframes: ["all", "hour", "day", "month", "year"] -# sorting: ["all", "controversial", "new", "top", "best", "hot", "rising"] -asyncio.run( - async_user( - username="automoderator", data_timeframe="year", data_limit=100, data_sort="all" - ) -) From a8b667a706c911a05efb82dbed6855125a78f147 Mon Sep 17 00:00:00 2001 From: rly0nheart <74001397+rly0nheart@users.noreply.github.com> Date: Fri, 8 Dec 2023 05:19:06 +0200 Subject: [PATCH 3/9] Consistency in base.py --- knewkarma/base.py | 106 ++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/knewkarma/base.py b/knewkarma/base.py index 8f6026e..f0d2283 100644 --- a/knewkarma/base.py +++ b/knewkarma/base.py @@ -112,30 +112,33 @@ async def comments(self, session: aiohttp.ClientSession) -> List[Comment]: for comment_index, raw_comment in enumerate(raw_comments, start=1): comment_data: dict = raw_comment.get("data") - comment = Comment( - index=comment_index, - body=comment_data.get("body"), - id=comment_data.get("id"), - author=comment_data.get("author"), - author_is_premium=comment_data.get("author_premium"), - upvotes=comment_data.get("ups"), - downvotes=comment_data.get("downs"), - is_nsfw=comment_data.get("over_18"), - is_edited=comment_data.get("edited"), - score=comment_data.get("score"), - hidden_score=comment_data.get("score_hidden"), - gilded=comment_data.get("gilded"), - is_stickied=comment_data.get("stickied"), - is_locked=comment_data.get("locked"), - is_archived=comment_data.get("archived"), - created_at=unix_timestamp_to_utc(timestamp=comment_data.get("created")), - subreddit=comment_data.get("subreddit_name_prefixed"), - subreddit_type=comment_data.get("subreddit_type"), - post_id=comment_data.get("link_id"), - post_title=comment_data.get("link_title"), - raw_data=comment_data, + comments_list.append( + Comment( + index=comment_index, + body=comment_data.get("body"), + id=comment_data.get("id"), + author=comment_data.get("author"), + author_is_premium=comment_data.get("author_premium"), + upvotes=comment_data.get("ups"), + downvotes=comment_data.get("downs"), + is_nsfw=comment_data.get("over_18"), + is_edited=comment_data.get("edited"), + score=comment_data.get("score"), + hidden_score=comment_data.get("score_hidden"), + gilded=comment_data.get("gilded"), + is_stickied=comment_data.get("stickied"), + is_locked=comment_data.get("locked"), + is_archived=comment_data.get("archived"), + created_at=unix_timestamp_to_utc( + timestamp=comment_data.get("created") + ), + subreddit=comment_data.get("subreddit_name_prefixed"), + subreddit_type=comment_data.get("subreddit_type"), + post_id=comment_data.get("link_id"), + post_title=comment_data.get("link_title"), + raw_data=comment_data, + ) ) - comments_list.append(comment) return comments_list @@ -253,34 +256,37 @@ def process_posts(raw_posts: list) -> List[Post]: posts_list: list = [] for post_index, raw_post in enumerate(raw_posts, start=1): post_data = raw_post.get("data") - post = Post( - index=post_index, - title=post_data.get("title"), - thumbnail=post_data.get("thumbnail"), - id=post_data.get("id"), - body=post_data.get("selftext"), - author=post_data.get("author"), - subreddit=post_data.get("subreddit"), - subreddit_id=post_data.get("subreddit_id"), - subreddit_type=post_data.get("subreddit_type"), - upvotes=post_data.get("ups"), - upvote_ratio=post_data.get("upvote_ratio"), - downvotes=post_data.get("downs"), - gilded=post_data.get("gilded"), - is_nsfw=post_data.get("over_18"), - is_shareable=post_data.get("is_reddit_media_domain"), - is_edited=post_data.get("edited"), - comments=post_data.get("num_comments"), - hide_from_bots=post_data.get("is_robot_indexable"), - score=post_data.get("score"), - domain=post_data.get("domain"), - permalink=post_data.get("permalink"), - is_locked=post_data.get("locked"), - is_archived=post_data.get("archived"), - created_at=unix_timestamp_to_utc(timestamp=post_data.get("created")), - raw_post=post_data, + posts_list.append( + Post( + index=post_index, + title=post_data.get("title"), + thumbnail=post_data.get("thumbnail"), + id=post_data.get("id"), + body=post_data.get("selftext"), + author=post_data.get("author"), + subreddit=post_data.get("subreddit"), + subreddit_id=post_data.get("subreddit_id"), + subreddit_type=post_data.get("subreddit_type"), + upvotes=post_data.get("ups"), + upvote_ratio=post_data.get("upvote_ratio"), + downvotes=post_data.get("downs"), + gilded=post_data.get("gilded"), + is_nsfw=post_data.get("over_18"), + is_shareable=post_data.get("is_reddit_media_domain"), + is_edited=post_data.get("edited"), + comments=post_data.get("num_comments"), + hide_from_bots=post_data.get("is_robot_indexable"), + score=post_data.get("score"), + domain=post_data.get("domain"), + permalink=post_data.get("permalink"), + is_locked=post_data.get("locked"), + is_archived=post_data.get("archived"), + created_at=unix_timestamp_to_utc( + timestamp=post_data.get("created") + ), + raw_post=post_data, + ) ) - posts_list.append(post) return posts_list From 50a2d0dbc9f09ee54632b4b8a92c1a38a619024c Mon Sep 17 00:00:00 2001 From: rly0nheart <74001397+rly0nheart@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:39:37 +0200 Subject: [PATCH 4/9] Update parser --- knewkarma/_cli.py | 40 +++++++++++++++++----------------------- knewkarma/_parser.py | 2 +- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/knewkarma/_cli.py b/knewkarma/_cli.py index bca61a3..79bfe68 100644 --- a/knewkarma/_cli.py +++ b/knewkarma/_cli.py @@ -131,40 +131,34 @@ def execute(): # -------------------------------------------------------------------- # - parser = create_parser() - arguments: argparse = parser.parse_args() + arguments: argparse = create_parser().parse_args() start_time: datetime = datetime.now() # -------------------------------------------------------------------- # - if arguments.mode: - print( - """ + print( + """ ┓┏┓ ┓┏┓ ┃┫ ┏┓┏┓┓┏┏ ┃┫ ┏┓┏┓┏┳┓┏┓ ┛┗┛┛┗┗ ┗┻┛ ┛┗┛┗┻┛ ┛┗┗┗┻""" - ) - - # -------------------------------------------------------------------- # + ) - try: - start_time: datetime = datetime.now() + # -------------------------------------------------------------------- # - log.info( - f"[bold]Knew Karma CLI[/] {version} started at " - f"{start_time.strftime('%a %b %d %Y, %I:%M:%S%p')}..." - ) - asyncio.run(setup_cli(arguments=arguments)) - except KeyboardInterrupt: - log.warning(f"User interruption detected ([yellow]Ctrl+C[/])") - finally: - log.info(f"Stopped in {datetime.now() - start_time} seconds.") + try: + start_time: datetime = datetime.now() - # -------------------------------------------------------------------- # + log.info( + f"[bold]Knew Karma CLI[/] {version} started at " + f"{start_time.strftime('%a %b %d %Y, %I:%M:%S%p')}..." + ) + asyncio.run(setup_cli(arguments=arguments)) + except KeyboardInterrupt: + log.warning(f"User interruption detected ([yellow]Ctrl+C[/])") + finally: + log.info(f"Stopped in {datetime.now() - start_time} seconds.") - else: - # Display usage information if no mode is provided - parser.print_usage() + # -------------------------------------------------------------------- # # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # diff --git a/knewkarma/_parser.py b/knewkarma/_parser.py index f5c890a..f69d68a 100644 --- a/knewkarma/_parser.py +++ b/knewkarma/_parser.py @@ -33,7 +33,7 @@ def create_parser() -> argparse.ArgumentParser: formatter_class=RichHelpFormatter, ) subparsers = parser.add_subparsers( - dest="mode", help="operation mode", required=False + dest="mode", help="operation mode", required=True ) parser.add_argument( "-l", From e42a3e51c0b30ca0b838ff11abcc5a8381f907cb Mon Sep 17 00:00:00 2001 From: rly0nheart <74001397+rly0nheart@users.noreply.github.com> Date: Sun, 10 Dec 2023 21:34:03 +0200 Subject: [PATCH 5/9] Minor fix in api.py --- knewkarma/api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/knewkarma/api.py b/knewkarma/api.py index 88c0b60..4862df2 100644 --- a/knewkarma/api.py +++ b/knewkarma/api.py @@ -161,7 +161,7 @@ async def get_updates(session: aiohttp.ClientSession): async def get_profile( profile_source: str, session: aiohttp.ClientSession, - profile_type: str = Literal["user_profile", "subreddit_profile"], + profile_type: Literal["user_profile", "subreddit_profile"], ) -> dict: """ Gets profile data from the specified profile_type and profile_source. @@ -194,8 +194,8 @@ async def get_profile( async def get_posts( limit: int, session: aiohttp.ClientSession, - timeframe: str = Literal["all", "hour", "day", "week", "month", "year"], - sort: str = Literal[ + timeframe: Literal["all", "hour", "day", "week", "month", "year"], + sort: Literal[ "all", "controversial", "new", @@ -204,7 +204,7 @@ async def get_posts( "hot", "rising", ], - posts_type: str = Literal[ + posts_type: Literal[ "user_posts", "user_comments", "subreddit_posts", From c324be7eaee923edb46009a3d2de7d0a7601086c Mon Sep 17 00:00:00 2001 From: rly0nheart <74001397+rly0nheart@users.noreply.github.com> Date: Fri, 15 Dec 2023 04:14:05 +0200 Subject: [PATCH 6/9] Minor update --- .idea/.gitignore | 3 +++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/knewkarma.iml | 14 ++++++++++++++ .idea/misc.xml | 9 +++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ Knew Karma GUI/KnewKarma/Handlers/ApiHandler.vb | 2 +- Knew Karma GUI/KnewKarma/Windows/AboutWindow.vb | 2 +- .../KnewKarmaSetup/KnewKarmaSetup.vdproj | 2 +- knewkarma/_project.py | 2 +- 10 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/knewkarma.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/knewkarma.iml b/.idea/knewkarma.iml new file mode 100644 index 0000000..a10eac4 --- /dev/null +++ b/.idea/knewkarma.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..20bd45f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..decaddc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Knew Karma GUI/KnewKarma/Handlers/ApiHandler.vb b/Knew Karma GUI/KnewKarma/Handlers/ApiHandler.vb index ca37f3b..0ece6bb 100644 --- a/Knew Karma GUI/KnewKarma/Handlers/ApiHandler.vb +++ b/Knew Karma GUI/KnewKarma/Handlers/ApiHandler.vb @@ -30,7 +30,7 @@ Public Class ApiHandler Using httpClient As New HttpClient() httpClient.DefaultRequestHeaders.Add( "User-Agent", - $"Knew-Karma/{appVersion} ({dotNetVersion}; +https://about.me/rly0nheart)" + $"Knew-Karma/{appVersion} ({dotNetVersion}; +https://rly0nheart.github.io)" ) Dim response As HttpResponseMessage = Await httpClient.GetAsync(endpoint) diff --git a/Knew Karma GUI/KnewKarma/Windows/AboutWindow.vb b/Knew Karma GUI/KnewKarma/Windows/AboutWindow.vb index 906c745..f968f76 100644 --- a/Knew Karma GUI/KnewKarma/Windows/AboutWindow.vb +++ b/Knew Karma GUI/KnewKarma/Windows/AboutWindow.vb @@ -50,7 +50,7 @@ ''' The source of the event. ''' The event data. Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Copyright.LinkClicked, Copyright.LinkClicked - Shell("cmd.exe /c start https://about.me/rly0nheart") + Shell("cmd.exe /c start https://rly0nheart.github.io") End Sub Private Sub ButtonCheckforUpdates_Click(sender As Object, e As EventArgs) Handles ButtonGetUpdates.Click diff --git a/Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj b/Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj index 4d62f4c..5583471 100644 --- a/Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj +++ b/Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj @@ -246,7 +246,7 @@ "ARPCONTACT" = "8:Richard Mwewa" "Keywords" = "8:reddit;scraper;reddit-scraper;osint;reddit-data" "ARPCOMMENTS" = "8:Reddit Data Analysis Toolkit." - "ARPURLINFOABOUT" = "8:https://about.me/rly0nheart" + "ARPURLINFOABOUT" = "8:https://rly0nheart.github.io" "ARPPRODUCTICON" = "8:_74130F0CE3BE422EBBC67E9C538BCD01" "ARPIconIndex" = "3:0" "SearchPath" = "8:" diff --git a/knewkarma/_project.py b/knewkarma/_project.py index 951aac0..c9a1742 100644 --- a/knewkarma/_project.py +++ b/knewkarma/_project.py @@ -5,7 +5,7 @@ # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # author: str = "Richard Mwewa" -about_author: str = "https://about.me/rly0nheart" +about_author: str = "https://rly0nheart.github.io" version: str = "3.3.2.0" # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # From b495cc425058218c53ff5e5f0950e8a5bef5c29a Mon Sep 17 00:00:00 2001 From: Richard Mwewa <74001397+rly0nheart@users.noreply.github.com> Date: Fri, 15 Dec 2023 04:16:02 +0200 Subject: [PATCH 7/9] Delete .idea directory --- .idea/.gitignore | 3 --- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/knewkarma.iml | 14 -------------- .idea/misc.xml | 9 --------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 6 files changed, 46 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/knewkarma.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/knewkarma.iml b/.idea/knewkarma.iml deleted file mode 100644 index a10eac4..0000000 --- a/.idea/knewkarma.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 20bd45f..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index decaddc..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 130e59c13070739b3c6ac4070640416089ff2643 Mon Sep 17 00:00:00 2001 From: rly0nheart <74001397+rly0nheart@users.noreply.github.com> Date: Thu, 21 Dec 2023 08:21:43 +0200 Subject: [PATCH 8/9] Python Library: Showing expected and default values to sort and timeframe parameters --- knewkarma/_cli.py | 6 +++--- knewkarma/_project.py | 14 +++++++++++++- knewkarma/api.py | 14 +++----------- knewkarma/base.py | 15 ++++++++++----- pyproject.toml | 6 +++--- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/knewkarma/_cli.py b/knewkarma/_cli.py index 79bfe68..8e3c24d 100644 --- a/knewkarma/_cli.py +++ b/knewkarma/_cli.py @@ -18,7 +18,7 @@ # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # -async def setup_cli(arguments: argparse.Namespace): +async def stage_cli(arguments: argparse.Namespace): """ Sets up the command-line interface and executes the specified actions. @@ -126,7 +126,7 @@ async def setup_cli(arguments: argparse.Namespace): # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # -def execute(): +def run_cli(): """Main entrypoint for the Knew Karma command-line interface.""" # -------------------------------------------------------------------- # @@ -152,7 +152,7 @@ def execute(): f"[bold]Knew Karma CLI[/] {version} started at " f"{start_time.strftime('%a %b %d %Y, %I:%M:%S%p')}..." ) - asyncio.run(setup_cli(arguments=arguments)) + asyncio.run(stage_cli(arguments=arguments)) except KeyboardInterrupt: log.warning(f"User interruption detected ([yellow]Ctrl+C[/])") finally: diff --git a/knewkarma/_project.py b/knewkarma/_project.py index c9a1742..27f4d58 100644 --- a/knewkarma/_project.py +++ b/knewkarma/_project.py @@ -1,12 +1,13 @@ # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # import os +from typing import Literal # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # author: str = "Richard Mwewa" about_author: str = "https://rly0nheart.github.io" -version: str = "3.3.2.0" +version: str = "3.4.0.0" # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # @@ -95,4 +96,15 @@ # Construct path to the program's directory PROGRAM_DIRECTORY: str = os.path.expanduser(os.path.join("~", "knewkarma-data")) +DATA_SORT_CRITERION: Literal[ + "controversial", + "new", + "top", + "best", + "hot", + "rising", +] + +DATA_TIMEFRAME = Literal["hour", "day", "week", "month", "year"] + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # diff --git a/knewkarma/api.py b/knewkarma/api.py index 4862df2..2474f95 100644 --- a/knewkarma/api.py +++ b/knewkarma/api.py @@ -5,7 +5,7 @@ import aiohttp from ._coreutils import log -from ._project import version, about_author +from ._project import version, about_author, DATA_SORT_CRITERION, DATA_TIMEFRAME # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # @@ -194,16 +194,8 @@ async def get_profile( async def get_posts( limit: int, session: aiohttp.ClientSession, - timeframe: Literal["all", "hour", "day", "week", "month", "year"], - sort: Literal[ - "all", - "controversial", - "new", - "top", - "best", - "hot", - "rising", - ], + timeframe: DATA_TIMEFRAME, + sort: DATA_SORT_CRITERION, posts_type: Literal[ "user_posts", "user_comments", diff --git a/knewkarma/base.py b/knewkarma/base.py index f0d2283..26100a4 100644 --- a/knewkarma/base.py +++ b/knewkarma/base.py @@ -5,6 +5,7 @@ import aiohttp from ._coreutils import unix_timestamp_to_utc +from ._project import DATA_TIMEFRAME, DATA_SORT_CRITERION from .api import get_profile, get_posts from .data import User, Subreddit, Comment, Post @@ -20,9 +21,9 @@ class RedditUser: def __init__( self, username: str, - data_timeframe: str, - data_sort: str, data_limit: int, + data_timeframe: DATA_TIMEFRAME = "all", + data_sort: DATA_SORT_CRITERION = "all", ): """ Initialises a RedditUser instance for getting profile, posts and comments data from the specified user. @@ -152,7 +153,11 @@ class RedditSub: # -------------------------------------------------------------- # def __init__( - self, subreddit: str, data_timeframe: str, data_sort: str, data_limit: int + self, + subreddit: str, + data_limit: int, + data_timeframe: DATA_TIMEFRAME = "all", + data_sort: DATA_SORT_CRITERION = "all", ): """ Initialises a RedditSub instance for getting profile and posts from the specified subreddit. @@ -232,9 +237,9 @@ class RedditPosts: def __init__( self, - timeframe: str, - sort: str, limit: int, + timeframe: DATA_TIMEFRAME = "all", + sort: DATA_SORT_CRITERION = "all", ): """ Initializes a RedditPosts instance for getting posts from various sources. diff --git a/pyproject.toml b/pyproject.toml index d5a3f03..d317f54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "knewkarma" -version = "3.3.2.0" +version = "3.4.0.0" description = "A Reddit Data Analysis Toolkit." authors = ["Richard Mwewa "] readme = "README.md" @@ -33,8 +33,8 @@ rich-argparse = "*" [tool.poetry.dev-dependencies] pytest = "*" pytest-asyncio = "*" +pytest-cov = "*" pytest-html = "*" - [tool.poetry.scripts] -knewkarma = "knewkarma._cli:execute" +knewkarma = "knewkarma._cli:run_cli" From c082fad64ca155796040a7b98808dbc06d3124ec Mon Sep 17 00:00:00 2001 From: rly0nheart <74001397+rly0nheart@users.noreply.github.com> Date: Fri, 22 Dec 2023 04:14:55 +0000 Subject: [PATCH 9/9] Bump version (3.4.0.0) --- Knew Karma GUI/KnewKarma/KnewKarma.vbproj | 8 ++++---- .../KnewKarma/My Project/Application.Designer.vb | 6 +++--- Knew Karma GUI/KnewKarma/My Project/Application.myapp | 4 ++-- Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Knew Karma GUI/KnewKarma/KnewKarma.vbproj b/Knew Karma GUI/KnewKarma/KnewKarma.vbproj index 0e3fef0..a21a021 100644 --- a/Knew Karma GUI/KnewKarma/KnewKarma.vbproj +++ b/Knew Karma GUI/KnewKarma/KnewKarma.vbproj @@ -9,14 +9,14 @@ Richard Mwewa A Reddit Data Analysis Toolkit. © 2023 Richard Mwewa. All rights reserved. - https://github.com/bellingcat/knewkarma/wiki + https://github.com/bellingcat/knewkarma README.md https://github.com/bellingcat/knewkarma - 3.3.0.0 - 3.3.0.0 + 3.4.0.0 + 3.4.0.0 LICENSE True - 3.3.0 + 3.4.0 reddit;scraper;reddit-scraper;osint;reddit-data 6.0-recommended diff --git a/Knew Karma GUI/KnewKarma/My Project/Application.Designer.vb b/Knew Karma GUI/KnewKarma/My Project/Application.Designer.vb index dcb51c3..f16efbb 100644 --- a/Knew Karma GUI/KnewKarma/My Project/Application.Designer.vb +++ b/Knew Karma GUI/KnewKarma/My Project/Application.Designer.vb @@ -30,12 +30,12 @@ Namespace My Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses Me.HighDpiMode = HighDpiMode.DpiUnaware End Sub - - + + _ Protected Overrides Sub OnCreateMainForm() Me.MainForm = Global.KnewKarma.MainWindow End Sub - + _ Protected Overrides Function OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean Me.MinimumSplashScreenDisplayTime = 2000 diff --git a/Knew Karma GUI/KnewKarma/My Project/Application.myapp b/Knew Karma GUI/KnewKarma/My Project/Application.myapp index 2872bff..0f377ee 100644 --- a/Knew Karma GUI/KnewKarma/My Project/Application.myapp +++ b/Knew Karma GUI/KnewKarma/My Project/Application.myapp @@ -1,12 +1,12 @@ true - Form1 + MainWindow false 0 true 0 true - SplashScreen + 2000 \ No newline at end of file diff --git a/Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj b/Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj index 5583471..559bb4f 100644 --- a/Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj +++ b/Knew Karma GUI/KnewKarmaSetup/KnewKarmaSetup.vdproj @@ -229,15 +229,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:Knew Karma" - "ProductCode" = "8:{EC317D6E-D0D6-4C8B-9120-59D6F8AE1626}" - "PackageCode" = "8:{5A52E59B-8C23-4400-8D0F-851C28E3DADA}" + "ProductCode" = "8:{54746087-7636-4C00-845D-253E0D22CBA6}" + "PackageCode" = "8:{64395976-B1A2-4CBC-95D0-0AC31AA608D1}" "UpgradeCode" = "8:{9B03AD0F-0C14-4075-AB75-01CD38A594B4}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:3.3.0" + "ProductVersion" = "8:3.4.0" "Manufacturer" = "8:Richard Mwewa" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:https://github.com/bellingcat/knewkarma/wiki"