{"id":30689520,"url":"https://github.com/ripred/reddit","last_synced_at":"2025-09-02T01:39:12.063Z","repository":{"id":310140905,"uuid":"929866598","full_name":"ripred/reddit","owner":"ripred","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-19T07:43:44.000Z","size":781,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-27T18:48:33.389Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ripred.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-09T15:36:22.000Z","updated_at":"2025-08-19T07:43:48.000Z","dependencies_parsed_at":"2025-08-17T10:31:46.483Z","dependency_job_id":null,"html_url":"https://github.com/ripred/reddit","commit_stats":null,"previous_names":["ripred/reddit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ripred/reddit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ripred%2Freddit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ripred%2Freddit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ripred%2Freddit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ripred%2Freddit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ripred","download_url":"https://codeload.github.com/ripred/reddit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ripred%2Freddit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273218411,"owners_count":25065913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-02T01:39:11.226Z","updated_at":"2025-09-02T01:39:12.048Z","avatar_url":"https://github.com/ripred.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Python Tests and Coverage](https://github.com/ripred/reddit/actions/workflows/python-app.yml/badge.svg)](https://github.com/ripred/reddit/actions/workflows/python-app.yml)\n\n# Reddit Cache Utility for Moderators\n\n## Version Information\n\n**Current Version: `reddit_cache_v2.py`**  \nThis version uses the [PRAW (Python Reddit API Wrapper)](https://praw.readthedocs.io/) for robust, authenticated interactions with Reddit's API. It offers improved reliability, reduced network calls (by caching data locally), and additional features such as interactive code formatting checks and multiple output formats (JSON, ANSI-colored report, Markdown).\n\n**Legacy Version: `reddit_cache.py` (Deprecated)**  \nThe old version of this tool (using direct HTTP requests via `requests`) is still available for backward compatibility but is now deprecated. We recommend using the new version for a better, more feature-rich experience.\n\n## Getting Started: Creating a Reddit App and Generating Keys\n\nTo use `reddit_cache_v2.py`, you must supply Reddit API credentials. Follow these steps to create a Reddit app and obtain the required keys:\n\n1. **Sign in to your Reddit account.**\n\n2. **Visit the Reddit App Preferences page:**  \n   Go to [https://www.reddit.com/prefs/apps](https://www.reddit.com/prefs/apps).\n\n3. **Create a New App:**  \n   - Scroll down to the **Developed Applications** section.  \n   - Click the **\"Create App\"** or **\"Create Another App\"** button.\n   \n4. **Fill in the Application Details:**  \n   - **Name:** Give your app a descriptive name (e.g., \"Reddit Cache Utility\").\n   - **App type:** Select **\"script\"** (this is recommended for personal use and for command-line utilities).\n   - **Description:** (Optional) Provide a brief description.\n   - **Redirect URI:** You can enter a placeholder such as `http://localhost:8080` (this is required but not used by the script).\n   - **Other fields:** Leave other fields as default unless instructed otherwise.\n\n5. **Save the Application:**  \n   After creating the app, you will see a new app entry under your Developed Applications.\n\n6. **Obtain Your Credentials:**  \n   - **Client ID:** This is the string just under the app name (a 14-character alphanumeric string).\n   - **Client Secret:** This is the secret key provided for the app.\n   - **User Agent:** Create a user agent string (e.g., `\"reddit_cache_v2 script by /u/yourusername\"`). This is used to identify your application in API requests.\n\n7. **Set Up Your Environment:**  \n   You can provide these credentials to the script via a `praw.ini` file or by setting environment variables:\n   \n   - **Using Environment Variables:**  \n     ```bash\n     export REDDIT_CLIENT_ID=\u003cyour_client_id\u003e\n     export REDDIT_CLIENT_SECRET=\u003cyour_client_secret\u003e\n     export REDDIT_USER_AGENT=\"reddit_cache_v2 script by /u/yourusername\"\n     ```\n     \n   - **Using a `praw.ini` File:**  \n     Create a file named `praw.ini` in your project directory with the following content:\n     ```ini\n     [DEFAULT]\n     client_id=\u003cyour_client_id\u003e\n     client_secret=\u003cyour_client_secret\u003e\n     user_agent=reddit_cache_v2 script by /u/yourusername\n     ```\n\nOnce your credentials are set up, `reddit_cache_v2.py` will be able to authenticate with Reddit and retrieve posts as expected.\n\n## Overview\n\nThe **Reddit Cache Utility** is a command-line tool designed to help moderators quickly fetch, cache, and analyze the latest posts from one or more subreddits. The tool minimizes network traffic by caching posts locally and provides various reports and an interactive code formatting check to help you easily identify posts that may need further review or formatting corrections.\n\n## Features\n\n- **Caching:**  \n  Retrieves and caches the latest 100 posts from a subreddit. On subsequent runs, only new posts are fetched to reduce network calls.\n\n- **Flair Reports:**  \n  Generate reports summarizing unique flair counts from cached posts.\n\n- **Show Posts:**  \n  Display detailed information (title, author, full selftext, and flair) for a specified number of cached posts.\n\n- **Monthly Digest:**  \n  Automatically compile a digest from posts with titles containing \"Monthly Digest\" (including a header, narrative summary, and list of digest posts).\n\n- **Interactive Code Format Check:**  \n  Scans cached posts for unformatted source code (e.g., Arduino/C/C++ code that isn’t properly fenced or indented). When a violation is detected, the full, untruncated post body is printed for review, and you are prompted to flag, skip, or cancel further checks.\n  \n- **ANSI Colored Output:**  \n  The output is colorized using ANSI escape sequences for clarity:\n  - **Blue:** Subreddit names  \n  - **Green:** Summary statistics  \n  - **Magenta:** Report headers  \n  - **Yellow:** Warnings and applied filters\n\n*Note: The screenshot below is a simulated representation of the expected ANSI-colored terminal output.*\n\n![ANSI Output Screenshot](https://via.placeholder.com/800x200?text=ANSI+Colored+Output+Screenshot)\n\n## Usage\n\nRun the utility from the command line using the new version:\n\n```bash\n./reddit_cache_v2.py --help\n```\n\nThe help output is as follows:\n\n```\nusage: reddit_cache_v2.py [-h] [-r {flair}] [-l N] [-L M] [-D] [--check-code-format]\n                          [--output {json,report,markdown}] [subreddits ...]\n\nFetch and cache the newest 100 posts from one or more subreddits, displaying only new posts\n       and summary stats.\nIf multiple subreddits are specified, a global summary is also provided.\n\nPositional arguments:\n  subreddits            One or more subreddit names to fetch posts from (default: arduino).\n\nOptional arguments:\n  -h, --help            show this help message and exit\n  -r {flair}, --report {flair}\n                        Generate a report. Available option: flair\n  -l N, --show N        Show title, selftext, author, and flair for the last N cached posts\n  -L M, --limit-report M\n                        Limit the number of cached posts scanned for reports to M posts (default:\n                        no limit)\n  -D, --digest          Include a Monthly Digest report section (scans cached posts with titles containing\n                        'Monthly Digest')\n  --check-code-format   Check cached posts for code formatting violations interactively\n  --output {json,report,markdown}\n                        Output format: 'json' for JSON output, 'report' for human-readable ANSI report,\n                        'markdown' for Markdown-formatted report (default: json)\n\nExample: ./reddit_cache_v2.py arduino arduino_ai --check-code-format --output report\n```\n\n### How It Works\n\n1. **Caching:**  \n   The tool checks the local `caches/` folder for stored post data. If data exists, only new posts are fetched from Reddit.\n\n2. **Reporting:**  \n   Based on the provided options, the utility generates various reports (flair, show posts, monthly digest) using cached data, reducing redundant network calls.\n\n3. **Interactive Code Check:**  \n   When the `--check-code-format` flag is used, the utility scans each post’s selftext (after unescaping HTML entities) for blocks of 3+ consecutive non-empty lines that resemble code (ignoring properly formatted code blocks). If a violation is found, the complete post body is printed for review, and you are prompted to flag, skip, or cancel further checks.\n\n4. **ANSI Colors:**  \n   Output is colorized using ANSI escape sequences to improve readability (e.g., summary stats in green, report headers in magenta).\n\n## Example Use Cases\n\nBelow are some usage examples using the new version:\n\n```bash\n# 1. Fetch and cache posts from the default subreddit (r/arduino)\n$ ./reddit_cache_v2.py\n--- Result ---\nFilters applied: {'limit_report': 'None', 'report': 'None', 'show': 'None', 'digest': 'None', 'check_code_format': 'None', 'output': 'json'}\n[ANSI-colored output showing summary stats for 100 posts fetched from r/arduino]\n\n# 2. Generate a flair report for r/arduino (using cached data)\n$ ./reddit_cache_v2.py arduino -r flair\n--- Result ---\nFilters applied: {'limit_report': 'None', 'report': 'flair', 'show': 'None', 'digest': 'None', 'check_code_format': 'None', 'output': 'json'}\n[ANSI-colored output: flair report in magenta, with flair counts]\n\n# 3. Show detailed information for the last 5 cached posts from r/programming\n$ ./reddit_cache_v2.py programming -l 5\n--- Result ---\nFilters applied: {'limit_report': 'None', 'report': 'None', 'show': 5, 'digest': 'None', 'check_code_format': 'None', 'output': 'json'}\n[ANSI-colored output: Detailed info (title, author, selftext, flair) for 5 posts]\n\n# 4. Generate a Monthly Digest report for r/arduino in Markdown format\n$ ./reddit_cache_v2.py arduino -D --output markdown\n--- Result ---\nFilters applied: {'limit_report': 'None', 'report': 'None', 'show': 'None', 'digest': 'Enabled', 'check_code_format': 'None', 'output': 'markdown'}\n[Markdown output: Monthly Digest report with header, narrative, and digest posts]\n\n# 5. Interactively check for unformatted code in r/ripred\n$ ./reddit_cache_v2.py ripred --check-code-format --output report\nProcessing subreddits: [ANSI progress bar]\nPotential Code Format Violation Detected:\nPost ID: abc123\nTitle: \"Test Post # 1 – Should FAIL Formatting Check\"\nAuthor: ripred3\nComplete Selftext:\n[Full, untruncated post body with improperly formatted source code]\nDoes this post contain unformatted code? (y/n/s/c):\n[Interactive prompt with ANSI-colored text]\n```\n\n## Quick Command Examples\n\n```bash\n# Fetch posts from r/arduino (default)\n$ ./reddit_cache_v2.py\n\n# Generate a flair report for r/arduino\n$ ./reddit_cache_v2.py arduino -r flair\n\n# Show detailed info for the last 5 posts from r/programming\n$ ./reddit_cache_v2.py programming -l 5\n\n# Generate a Monthly Digest report for r/arduino in Markdown format\n$ ./reddit_cache_v2.py arduino -D --output markdown\n\n# Interactively check for unformatted code in r/ripred\n$ ./reddit_cache_v2.py ripred --check-code-format --output report\n```\n\n## Additional Notes\n\n- **Non-interactive Mode:**  \n  For automated testing, set the environment variable `TEST_NONINTERACTIVE=1` to simulate an automatic \"y\" response during code format checks.\n\n- **ANSI Color Output:**  \n  The utility’s output is colorized using ANSI escape sequences for enhanced readability in the terminal.\n\n- **Deprecated Legacy Version:**  \n  The legacy version (`reddit_cache.py`) is still available but is now deprecated. It uses direct HTTP requests via `requests` and is maintained only for backward compatibility. We recommend using `reddit_cache_v2.py` for a more robust and feature-rich experience.\n\n- **Reddit API Credentials:**  \n  To use `reddit_cache_v2.py`, you must create a Reddit app and obtain your API credentials:\n  1. Sign in to your Reddit account.\n  2. Go to [https://www.reddit.com/prefs/apps](https://www.reddit.com/prefs/apps).\n  3. Click **\"Create App\"** or **\"Create Another App\"**.\n  4. Fill in the details:\n     - **Name:** (e.g., \"Reddit Cache Utility\")\n     - **App type:** Select **\"script\"**.\n     - **Redirect URI:** Use a placeholder like `http://localhost:8080`.\n  5. Save your app.\n  6. Note your **Client ID** (displayed under your app name) and **Client Secret**.\n  7. Set these as environment variables or in a `praw.ini` file:\n     - Environment variables:\n       ```bash\n       export REDDIT_CLIENT_ID=\u003cyour_client_id\u003e\n       export REDDIT_CLIENT_SECRET=\u003cyour_client_secret\u003e\n       export REDDIT_USER_AGENT=\"reddit_cache_v2 script by /u/yourusername\"\n       ```\n     - Or create a `praw.ini` file with:\n       ```ini\n       [DEFAULT]\n       client_id=\u003cyour_client_id\u003e\n       client_secret=\u003cyour_client_secret\u003e\n       user_agent=reddit_cache_v2 script by /u/yourusername\n       ```\n\n- **Feedback and Contributions:**  \n  Please test the utility on your subreddits and share any issues or feature suggestions. Your feedback is highly appreciated!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fripred%2Freddit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fripred%2Freddit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fripred%2Freddit/lists"}