Note: This project is under development and may contain bugs.
This repository contains a Python library for scraping the latest listings from Nettikone and Tori autot, saving them to an SQLite database, along with a Discord bot that sends notifications about new listings.
It was originally created for personal use, but I thought maybe it can be handy for someone too.
The library is somewhat hard-coded and not as configurable as it should be, but there are plans to rewrite it for better flexibility.
- Scrape Nettikone: Retrieve listings of vehicles and equipment from Nettikone based on various criteria.
- Scrape Tori autot: Fetch listings of vehicles and equipment from Tori.fi based on your preferences.
- Discord Notifications: Receive notifications in a Discord channel when new listings are found.
- Customizable: Configure the bot to search for specific makes and models.
-
Clone this repository to your local machine:
git clone https://github.com/zozol12/nettikone-tori-discord-notifications.git
-
Install the required Python packages:
pip install -r requirements.txt
-
Import the
NettikoneScraper
andToriScraper
classes fromLib.py
. -
Initialize the scrapers with your preferences:
from nettikone_scraper import NettikoneScraper from tori_scraper import ToriScraper nettikone_scraper = NettikoneScraper(api_key="your_netikone_api_key", makes=["Make1", "Make2"]) tori_scraper = ToriScraper(config_file="config.json")
-
Use the
scrape_listings()
method to retrieve listings:nettikone_scraper.scrape_listings() tori_scraper.scrape_listings()
-
Save the listings to a database:
nettikone_scraper.save_listings() tori_scraper.save_listings()
-
Set up a Discord bot and obtain its token. Follow the official Discord documentation to create a bot.
-
Edit
config.json
with your configuration options (listing_urls are generated automatically based on makes):{ "bot_token": "your_discord_bot_token", "channel_id": 123456789, // Your Discord channel ID "makes": ["Make1", "Make2"], // Other configuration options... }
-
Import and run the Discord bot:
python bot.py
The helper.py
file contains a helper class for managing makes and generating Tori URLs. Use it as follows:
-
Import the helper class:
from helper import generate_tori_url, get_make_ids
-
Use the
generate_tori_url()
function to create Tori URLs based on makes:makes = ["Make1", "Make2"] tori_url = generate_tori_url(makes)
-
Use the
get_make_ids()
function to retrieve make IDs:make_names = ["Make1", "Make2"] make_ids = get_make_ids(make_names)
bot_token
: Your Discord bot token.channel_id
: The ID of the Discord channel where notifications will be sent.makes
: A list of makes to search for listings.api_key
(Nettikone only): Your Nettikone API key.delay
: Interval in seconds between scraping attempts.
This project is licensed under the MIT License - see the LICENSE file for details.
The code can be significantly improved, and there are plans to rewrite the library soon.
If you encounter any issues or have suggestions for improvements, please open an issue.