check_for_craiglist_deals
This is a script that will check craigslist URLS on an hourly basis and will notify on Discord when a new post is added.
It was developed on Python 3.12, but will likely work on most Python 3 versions.
You can find the github for this project here.
This project requires a .env file as well as a csv file in the configs directory.
Create a .env file in the root of the project. the .env file should look like this:
DISCORD_TOKEN=ASDFASDASDA123423DQWEQWEQWEQWE
CHANNELID=23424523456234234234
You can find guides online on how to create the discord bot and token and find the channel id.
In the configs directory, create a file called "craigslist_deals_to_check.csv"
It should look like this:
friendly_name,url
somegenericterm,https://craigslist.org/search/actualsearchurl(justcopyfrombrowser)
It's recommended to run this in a virtual environment (as always)
To install the prerequisites, run:
pip install -r requirements.txt
I deploy this in a docker container. Here's one way to do that:
docker build --no-cache \
-t check_for_craiglist_deals /path/check_for_craiglist_deals"
This path has the Dockerfile, which contains:
FROM python:3
RUN apt-get update && apt-get install -y git
RUN python -m pip install --upgrade pip
# can use this if pip keeps using cached modules (it does)
RUN pip cache purge
RUN pip install httpx[http2] parsel nested_lookup
RUN pip install requests
RUN pip install beautifulsoup4
RUN pip install discord.py
RUN pip install colorlog
RUN pip install python-dotenv
WORKDIR /data/check_for_craiglist_deals
CMD [ "python", "check_for_craiglist_deals.py" ]
That allows me to deploy once and then subsequent deployments are just copies of the .py files to the data directory.
docker create --name=check_for_craiglist_deals \
-v /path/data:/data \
-v /etc/localtime:/etc/localtime:ro \
--restart=always check_for_craiglist_deals
docker start check_for_craiglist_deals
You can check if the container started succesfully with this command:
docker logs -f check_for_craiglist_deals
Alternatively you can also just run python check_for_craiglist_deals.py
, assuming python is installed on your system.
This bot only notifies during certain hours, but this can't be configured currently (if there's interest, I might add that as a configurable option)
Currently this is set in the code, function load_deal_data_and_start_checking()
:
if datetime.datetime.now().hour > 12 or datetime.datetime.now().hour < 2
You can always change the hours there to something you'd prefer.