承接 swayoleg/mvcr-trvaly-pobyt-lang-exam-online-prihlaska-notify 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

swayoleg/mvcr-trvaly-pobyt-lang-exam-online-prihlaska-notify

最新稳定版本:1.0.1

Composer 安装命令:

composer require swayoleg/mvcr-trvaly-pobyt-lang-exam-online-prihlaska-notify

包简介

Checks if at https://cestina-pro-cizince.cz/trvaly-pobyt/a2/online-prihlaska/ are free spots and notifies

README 文档

README

Use just as example reference

No Maintenance Intended

What is it project for?

In Czech republic to get permanent visa you need to get language exam. And there is a big problem to get term and register - they have always no spots. To get a spot for lang exam you need to go here https://cestina-pro-cizince.cz/trvaly-pobyt/a2/online-prihlaska/

So what I did its just simple parser that checks free spot and notifies you.

Notification and script options

The notification can be done via telegram, email and webhook. There is two type(styles I would say) to solve the problem. In noOOPJustForFunExample.php you just put the telegram token and chat id - and put the script on a cron. This is my style to solve one-time issues - just get it done.

BUT its not a cool and corporate style - right? So real "for fun" was to create script that can send notification with different type, can operate via guzzle or curl by config, can be extended - bla bla bla.

Installation

Composer

composer require swayoleg/mvcr-trvaly-pobyt-lang-exam-online-prihlaska-notify

Usage

I like to use it like this

<?php
require_once __DIR__ . '/vendor/autoload.php';

$config = include (__DIR__ . DIRECTORY_SEPARATOR . 'config.php');
$checker = new \Swayoleg\CestinaCheck\OnlinePrihlaskaChecker($config);
$checker->check();

where config.php looks like this - config_example.php

Or use the parser_example.php

require_once __DIR__ . '/vendor/autoload.php';

$configExample = [
    'notify' => [
        'telegram',
        //'email',
        //'webhook'
    ],
    'notify_options' => [
        'telegram' => [
            // can be a lot of chats
            'chats' => [
                '%YOURCHATIDHERE%',
                '%YOURCHATIDHERE%'
            ],
            'token' => '%TELEGRAMTOKEN%', //
        ],
        'email' => [
            // can be multiply
            'sendTo' => [
                'email@cc.cc'
            ],
            'subject' => 'New exam spot',
            'from' => 'webmaster@example.com',
            'replyTo' => 'webmaster@example.com',
        ],
        'webhook' => [
            // Can be a lot of urls
            'urls' => [
                '%YOUR URL HERE%'
            ]
        ]
    ],

    'url' => 'https://cestina-pro-cizince.cz/trvaly-pobyt/a2/online-prihlaska/',
    'noTermsText' => ['Nedostupná', 'Obsazeno'],
    'downloader' => 'curl',  // Can be "guzzle", "file" or "curl"
    'domParser' => 'xpath',
    'sendNotificationIfNoElementsFound' => false, // This will notify you if there is no disabled links found - for example in case if DOM scruture is changed.
    'message' => 'New Exam place Exists!' . PHP_EOL . 'Go for it: https://cestina-pro-cizince.cz/trvaly-pobyt/a2/online-prihlaska/', // Message to send
    'errorMessage' => 'No xpath elements found',
];

$checker = new \Swayoleg\CestinaCheck\OnlinePrihlaskaChecker($configExample);
$checker->check();

So if you are novice in this lets go with config. Use parser_example.php file.

If you need to send notification to your BE with webhook use this config:

$configExample = [
    'notify' => [
        'webhook',
    ],
    'notify_options' => [
        'webhook' => [
            'urls' => [
                '%YOUR URL HERE%'
            ]
        ]
    ],
    
    'sendNotificationIfNoElementsFound' => false, // This will notify you if there is no disabled links found - for example in case if DOM scruture is changed.
    'message' => 'New Exam place Exists!' . PHP_EOL . 'Go for it: https://cestina-pro-cizince.cz/trvaly-pobyt/a2/online-prihlaska/', // Message to send
    'errorMessage' => 'No xpath elements found',
    
    'url' => 'https://cestina-pro-cizince.cz/trvaly-pobyt/a2/online-prihlaska/',
    'noTermsText' => ['Nedostupná', 'Obsazeno'],
    'downloader' => 'curl',  // Can be "guzzle", "file" or "curl"
    'domParser' => 'xpath',
];

It will send simple GET request to your url with urlEncoded 'message' GET param.

Telegram notification sending

If you need to send it via telegram - create bot with @BotFather. telegram bot. Get your token. It will be right after this line Use this token to access the HTTP API:

To get your int id of telegram the fastest way is to write to @userinfobot. It will respond like this:

@swayoleg
Id: nnnnnnnn
First: Oleg
Last: Ovsianikov
Lang: en

In the nnnnnnnn place you will get your chat Id for config.

So set config like this:

$configExample = [
    'notify' => [
        'telegram',
    ],
    'notify_options' => [
        'telegram' => [
            'chats' => [
                *chat Id*, // TELEGRAM int chat ID here
            ],
            'token' => '*token*', // TELEGRAM TOKEN HERE
        ],
    ],
    
    'sendNotificationIfNoElementsFound' => false, // This will notify you if there is no disabled links found - for example in case if DOM scruture is changed.
    'message' => 'New Exam place Exists!' . PHP_EOL . 'Go for it: https://cestina-pro-cizince.cz/trvaly-pobyt/a2/online-prihlaska/', // Message to send
    'errorMessage' => 'No xpath elements found',
    
    
    'url' => 'https://cestina-pro-cizince.cz/trvaly-pobyt/a2/online-prihlaska/',
    'noTermsText' => ['Nedostupná', 'Obsazeno'],
    'downloader' => 'curl',  // Can be "guzzle", "file" or "curl"
    'domParser' => 'xpath',
];

If your file_get_contents function is allowed to open urls you can use 'downloader' => 'file' as an option. Other options are curl or guzzle.

Other Options:

url - the actually url for parsing

errorMessage - what should we send if xPath didnt find any links. Works only with sendNotificationIfNoElementsFound = true

sendNotificationIfNoElementsFound - flag if we need to send message if parser cant find the links at all (I mean document structure might be changed)

domParser - leave it for now. If you want another parser add it to src/Dom and implement Swayoleg\CestinaCheck\Dom\ParserInterface

downloader - if you use file it uses simple file_get_contents php function - so url open should be allowed. curl uses ext-curl and guzzle use guzzlehttp/guzzle package

noTermsText - Text on the btn which means that there is no terms. Array param from 1.0.1 version

Multiply notifications

Yes it works. You can use webhook email and telegram notification types same time, and multipy urls, chats and emails as well.

ChangeLog

1.0.1 noTermsText param changed from string to array

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固