Skip to content

kfiry77/10bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

10bot

A bot to buy 10Bis coupons. The project is a Python script that automates the purchase of Shufersal Coupons in a 10bis account if there is sufficient credit and only on working days. The script generates a report containing the list of coupons and their barcodes and saves it in both PDF and HTML formats. The PDF file is then published to a designated WhatsApp group. To ensure consistent operation, the script can be scheduled to execute daily, using CRON or cloud Bot, such as Azure Function.

Diagram 1

View Source
@startuml
start

: Read commands from WhatsApp;
if (/disable command exists) then (yes)
else
    if (Workingday & credit > 0) then (yes)
      :Purchase Shufersal\n Coupon;
    else (no)
    endif
endif

: Generate report with coupons\n barcodes;
: Save report as PDF and HTML ;
: Publish PDF to WhatsApp group;
stop
@enduml

Installation and usage

register to WhatApp API Provider

Register for a developer account in GREEN API. Go through the "Before you Start" instructions. Create instance, and authorized it.
write down idInstance, apiTokenInstance values, to be later use when installing.

repository download

download the repository

git clone https://github.com/kfiry77/10bot

install virtual environment and install requirements

cd 10bot
python -m venv .
source ./venv/bin/activate 
pip3 install -r requirements.txt

Addtional machine installations

Install prerequisites for weasyprint (for PDF report generation), as describe here

macOS

brew install weasyprint

linux / Ubuntu

apt install weasyprint

Windows

install gtk3 runtime and it's dependencies, and add the runtime to PATH environment variable

PATH=%PATH%;C:\Program Files\GTK3-Runtime Win64\bin

Execute script main

note: purchase won't be submitted if -d is specified.

python3 main.py -d 

When prompt, enter email id used for 10Bis Account. you should be getting an SMS with OTP. type it when prompt Enter OTP:

 user@machine:~/10bot python3 main.py -d 
 Enter Email: [email protected]
 Enter OTP: 12345

Enter the Green API data, you have noted initially.

*** Green API ***
Enter IntanceId : 1234567899 
Enter Api Token Instance : apiTokenInstance........
Enter ChatId/GroupId (Empty to create Group):

Hit enter to create a new chatgroup, enter the chatId(s) one by one ([email protected]), press enter when done.

Enter ChatId/GroupId (Empty to create Group):
Enter ChatId(Empty When Done): [email protected]
Enter ChatId(Empty When Done): [email protected]
Enter ChatId(Empty When Done):

Wait for the script execution

User [email protected] Logged In
budget available= True
Dry Run success, purchase will be skipped.
scanning Month:2023-11-01
scanning Month:2023-10-01
Created report until 2023-10-01

Validate, that it finishes correctly. Once finishes, a New group named "10Bot" will be added on WhatAppApplication a PDF with all the coupons will be shared in this group.

Add the script to the system crontab, by typing crontab -e and adding the following line to it.

0 23 * * *  (/bin/bash -c "cd /path/to/your/script && source .venv/bin/activate && python3 main.py  >> /path/to/your/log/10bot.log 2>&1 &") 

Whatsapp Group Commands:

The application now wakes up every day at 23:00, To disable specific day purchase (due to vacation), send /disable commands to the group. /enable command will enable it again. note that, only the command from last day is relevant, and of there is a conflict between command, the last one will be considered only.

references:

The code is bases from these repositories by Dvir Perets

TODO:

  • Bug Fix: user-token header is not needed due to 10bis change of API, RefreshToken API should be used instead.
  • Fix the holidays, to block only non-working day.
  • Add scrips the deployment to cloud providers:
    • Azure
    • GCP
  • Add Report generation.
    • Make the report formatter generic, for various kinds of files.
    • Make PDF report formatter.
  • Add report publisher, and make it generic using chain of responsibility GOF design pattern.
    • whatsApp Publisher
    • Google Drive or Microsoft OneDrive Publisher.
  • and make it generic to various kind for example: Google Drive share.
  • Bug Fix : Pdf is cannot be generated on windows due to weasyprint dependency.
  • describe software design with some plantuml class diagrams.
  • Coupon images crop, for a nicer report formatting.
  • Green API - send data to GroupChat
  • Before purchasing, read from whatapps group message, if a message /disable exists, then purchase will be skipped