Sha256: 65c59d82e62a5f73f96cfd87db6606d192b9295a5d6bcaf3e5164833ff330a4c
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true # # Fetch list of methods from Telegram docs. # Use it to update client.rb. require 'net/http' require 'nokogiri' DOCS_URL = 'https://core.telegram.org/bots/api' page_html = Net::HTTP.get(URI(DOCS_URL)) doc = Nokogiri::HTML(page_html) # Select `h4`s, but use `h3`s to group them. headers = doc.css('h3, h4'). chunk_while { |_, x| x.name == 'h4' }. map { |g| g.select { |x| x.name == 'h4' } }. map { |g| g.map(&:text) } # Method starts with lowercase and does not have spaces. NOT_METHOD_REGEXP = /(\A[^a-z])|\s/.freeze # Filter method names. method_list = headers. map { |g| g.grep_v(NOT_METHOD_REGEXP) }. reject(&:empty?) api_version = doc.text.match(/^(?:Introducing )?(Bot API ([\d\.]+))\.?$/) result = ['# Generated with bin/fetch-telegram-methods'] result << "# #{api_version[1]}" if api_version result << '' result << method_list.map { |g| g.join("\n") }.join("\n\n") result << '' result_txt = result.join("\n") puts result_txt API_METHODS_FILE = File.expand_path('../lib/telegram/bot/client/api_methods.txt', __dir__).freeze File.write(API_METHODS_FILE, result_txt) puts '', "Updated #{API_METHODS_FILE}"
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
telegram-bot-0.16.5 | bin/fetch-telegram-methods |
telegram-bot-0.16.4 | bin/fetch-telegram-methods |
telegram-bot-0.16.3 | bin/fetch-telegram-methods |