Giter Site home page Giter Site logo

raphaelsura / pet-finder Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 46 KB

App that scrapes the Danish animal protection association website and sends a telegram when a new pet is available.

License: MIT License

Python 97.13% Dockerfile 2.87%
telegram-bot web-monitoring sql-database

pet-finder's Introduction

build

pet-finder

App that scrapes the Danish animal protection association website and sends a telegram when a new pet is available. Small sized projects that samples a lot of practical code, which can easily be transferrable to other projects:

  • Web monitoring/scraping
  • SQLite database
  • Telegram bot
  • Github action
  • Crontab
  • Docker containers

I use this code as a running project to implement newly learned coding techniques and ideas.

Installation

The repo is setup so as to install petfinder as a package. Once cloned and done creating a virtual environment, pip install the repo in editable mode (-e), which will take care of all the dependencies.

$ git clone https://github.com/RaphaelSura/pet-finder.git
$ cd pet-finder
$ python -m virtualenv .env
$ source .env/bin/activate
$ pip install -e .

Now petfinder is like any other python package.

from petfinder.database import PetDB

Code formatting

Following Google Python style guide: https://google.github.io/styleguide/pyguide.html. This is set in VScode via .vscode/settings.json. Alternatively, run manually:

$ yapf *.py -r -i

Telegram bot setup

Install Telegram app on your phone or computer and create an account. Search for Botfather and type the following two commands in the chat:

  • /start to get the BotFather bot setup.

  • /newbot to create a new bot.

Choose a bot name e.g. FindMyPetBot. Then choose a bot usernmae e.g. mypetfinder_bot (must end with the word 'bot'). After creating the bot, it will display an HTTP API token ,you'll need this shortly.

Now start a conversation with the bot, in the telegram app search for @bot_name and press START.

In a browser, type https://api.telegram.org/bot{my_bot_http_api_token}/getUpdates, where you use the correct value for your bot API token. In the response, note down the Chat ID.

Put the HTTP API token and chat ID into etc/telegram_creds.txt. Note: the etc folder is in .gitignore as the content shouldn't be public.

Run the app - several ways

CRONTAB on Ubuntu server

# python script for Pet App bot, runs every 10 minutes from 6am til midnight
*/10 6-23 * * * ~/pet-finder/.env/bin/python3 ~/pet-finder/app_with_crontab.py

Inside DOCKER container

cd pet-finder
docker build -t pet-finder:latest .

Get the image_id with docker images | grep pet-finder. Then run in detached mode:

docker run -d --restart unless-stopped image_id

pet-finder's People

Contributors

raphaelsura avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.