This project implements a cross-platform search API that allows users to search for hottest posts by keyword across multiple platforms including Reddit, Hacker News, GitHub, V2EX, and TheresAnAIForThat.
- Search across multiple platforms with a single API call
- Caching mechanism for improved performance
- Rate limiting to prevent abuse
- Keyword translation for non-English queries
- Performance monitoring
- Swagger documentation
.
├── api
│ ├── error_handlers.py
│ ├── routes.py
│ └── schemas.py
├── core
│ ├── emails
│ └── platforms
│ ├── __init__.py
│ ├── github_repos_search.py
│ ├── hackernews_search.py
│ ├── platform.py
│ ├── reddit_search.py
│ ├── theresanaifforthat_search.py
│ ├── twitter_search_v2_oauth.py
│ ├── twitter_search.py
│ ├── v2ex_search_google.py
│ └── v2ex_search.py
│ ├── __init__.py
│ ├── cache.py
│ ├── cli.py
│ ├── models.py
│ ├── performance.py
│ ├── posts_search.py
│ ├── tasks.py
│ ├── translator.py
│ └── utils.py
├── tests
│ ├── conftest.py
│ └── test_search_api.py
├── utils
│ └── env_manager.py
├── venv
├── .env.example
├── .gitignore
├── app.py
├── config.py
├── main.py
├── pytest.ini
├── README.md
├── requirements.txt
└── run.py
-
Clone the repository:
git clone https://github.com/Rarestq/multi-platform-hot-post-search.git cd multi-platform-hot-post-search
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Copy the
.env.example
file to.env
- Fill in the necessary API keys and configuration options
- Copy the
-
Start the Flask server:
python run.py
-
The API will be available at
http://localhost:5000
-
Use the
/v1/search
endpoint to perform searches:POST /v1/search Content-Type: application/json { "keyword": "artificial intelligence", "platforms": ["reddit", "hackernews", "github"] }
you can use
curl
command to send post request:curl -X POST http://127.0.0.1:5000/search \ -H "Content-Type: application/json" \ -d '{"keyword": "AI", "platforms": ["reddit", "hackernews", "github"]}'
if your computer's system is Windows, then use
curl
command like below:curl -X POST http://127.0.0.1:5000/search -H "Content-Type: application/json" -d "{\"keyword\": \"AI\", \"platforms\": [\"reddit\", \"hackernews\", \"github\"]}"
-
View the Swagger documentation at
http://localhost:5000/apidocs
The following environment variables can be used to configure the application:
RATELIMIT_DEFAULT
: Default rate limit (e.g., "100 per day, 20 per hour")CACHE_TYPE
: Type of cache to use (default: "simple")CACHE_DEFAULT_TIMEOUT
: Default cache timeout in seconds (default: 600)HOT_KEYWORDS
: Comma-separated list of hot keywords for cache preheatingENABLE_PERFORMANCE_MONITORING
: Enable/disable performance monitoring (default: True)LOG_LEVEL
: Logging level (default: INFO)DEFAULT_PLATFORMS
: Comma-separated list of default platforms to search- etc.
This project uses pytest for testing. To run the tests:
pytest
If you would like to contribute to this project, please follow these steps:
- Fork this repository.
- Create a new branch (
git checkout -b feature
) - Make your changes.
- Commit your changes (
git commit -m 'Add new feature'
) - Push to the branch (
git push origin feature
) - Create a new Pull Request.
- Email: rarestzhou@gmail.com
- DM me on twitter is also welcome.
- Wechat: zjc111369
Feel free to customize this README further based on your specific project details and requirements!