buergerbot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e1998a4cfa96d4da389483a24c2ac4cce6bdaa4227758ca2b16038130c75f843
4
+ data.tar.gz: 408192c7b9888b9a8ef0e180330670d39d24e21b22f92cd6afc718e6b3b70056
5
+ SHA512:
6
+ metadata.gz: 5decc70ff301e8c1cac989715268a18c84dfa8705b0bcf1c3f16859b173c76b0c40f90b543b5f44d3a33902a602e9ba433ae2e386439b9b328a242d4a5c739f3
7
+ data.tar.gz: 98c0aa2f5ff6ffd7b2ec5daeea8ddda936894a985442a7d5cc0d1cf38fd918879bc2090cfc0bdf5f3b65d6aaa369f57330e3be7474e12a21699c7091983e2b06
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 3.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-11-08
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ ruby '~> 3.1.2'
6
+
7
+ # Specify your gem's dependencies in buerger-bot.gemspec
8
+ gemspec
9
+
10
+ gem 'rake', '~> 13.0'
11
+
12
+ gem 'standard', '~> 1.3'
13
+
14
+ gem 'ruby-lsp', '~> 0.3.5'
15
+
16
+ gem "watir", "~> 7.1"
17
+ gem "terminal-notifier", "~> 2.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ buergerbot (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ childprocess (4.1.0)
11
+ json (2.6.2)
12
+ language_server-protocol (3.17.0.1)
13
+ parallel (1.22.1)
14
+ parser (3.1.2.1)
15
+ ast (~> 2.4.1)
16
+ prettier_print (1.0.2)
17
+ rainbow (3.1.1)
18
+ rake (13.0.6)
19
+ regexp_parser (2.6.0)
20
+ rexml (3.2.5)
21
+ rubocop (1.35.1)
22
+ json (~> 2.3)
23
+ parallel (~> 1.10)
24
+ parser (>= 3.1.2.1)
25
+ rainbow (>= 2.2.2, < 4.0)
26
+ regexp_parser (>= 1.8, < 3.0)
27
+ rexml (>= 3.2.5, < 4.0)
28
+ rubocop-ast (>= 1.20.1, < 2.0)
29
+ ruby-progressbar (~> 1.7)
30
+ unicode-display_width (>= 1.4.0, < 3.0)
31
+ rubocop-ast (1.23.0)
32
+ parser (>= 3.1.1.0)
33
+ rubocop-performance (1.14.3)
34
+ rubocop (>= 1.7.0, < 2.0)
35
+ rubocop-ast (>= 0.4.0)
36
+ ruby-lsp (0.3.5)
37
+ language_server-protocol (~> 3.17.0)
38
+ sorbet-runtime
39
+ syntax_tree (>= 4.0.2)
40
+ ruby-progressbar (1.11.0)
41
+ rubyzip (2.3.2)
42
+ selenium-webdriver (4.6.1)
43
+ childprocess (>= 0.5, < 5.0)
44
+ rexml (~> 3.2, >= 3.2.5)
45
+ rubyzip (>= 1.2.2, < 3.0)
46
+ websocket (~> 1.0)
47
+ sorbet-runtime (0.5.10545)
48
+ standard (1.16.1)
49
+ rubocop (= 1.35.1)
50
+ rubocop-performance (= 1.14.3)
51
+ syntax_tree (4.3.0)
52
+ prettier_print (>= 1.0.2)
53
+ terminal-notifier (2.0.0)
54
+ unicode-display_width (2.3.0)
55
+ watir (7.1.0)
56
+ regexp_parser (>= 1.2, < 3)
57
+ selenium-webdriver (~> 4.0)
58
+ websocket (1.2.9)
59
+
60
+ PLATFORMS
61
+ arm64-darwin-21
62
+
63
+ DEPENDENCIES
64
+ buergerbot!
65
+ rake (~> 13.0)
66
+ ruby-lsp (~> 0.3.5)
67
+ standard (~> 1.3)
68
+ terminal-notifier (~> 2.0)
69
+ watir (~> 7.1)
70
+
71
+ RUBY VERSION
72
+ ruby 3.1.2p20
73
+
74
+ BUNDLED WITH
75
+ 2.3.11
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Fahad Hossain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # BuergerBot
2
+
3
+ BuergerBot is a bot for finding appointments at the Bürgeramt in Berlin.
4
+
5
+ ## Installation
6
+
7
+ IDK (not a ruby guy), probably goes something like:
8
+
9
+ ```bash
10
+ $ gem install buerger-bot
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```sh
16
+ $ buerger-bot
17
+ ```
18
+
19
+ ## Development
20
+
21
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
22
+
23
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fa7ad/buerger-bot.
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'standard/rake'
5
+
6
+ task default: :standard
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/buergerbot/bot/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'buergerbot'
7
+ spec.version = BuergerBot::VERSION
8
+ spec.authors = ['Fahad Hossain']
9
+ spec.email = ['set.name.fahad@gmail.com']
10
+
11
+ spec.summary = 'Find appointments at the Bürgeramt in Berlin'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/fa7ad/buerger-bot'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.1.0'
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
data/exe/buerger-bot ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'buergerbot/bot'
5
+
6
+ bot = BuergerBot::Bot.new
7
+ bot.run
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BuergerBot
4
+ # Logging utility for the bot.
5
+ module Logger
6
+ def self.log(message)
7
+ puts " #{message}"
8
+ end
9
+
10
+ def self.success(message)
11
+ puts "+ #{message}"
12
+ end
13
+
14
+ def self.fail(message)
15
+ puts "- #{message}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'terminal-notifier'
4
+
5
+ require_relative 'version'
6
+
7
+ module BuergerBot
8
+ # Notification utility for the bot.
9
+ module Notifications
10
+ def self.notify(message, open_chrome: false)
11
+ TerminalNotifier.notify(
12
+ message,
13
+ title: "#{NAME} #{VERSION}",
14
+ activate: open_chrome ? 'com.google.Chrome' : nil
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'watir'
4
+
5
+ require_relative 'logger'
6
+ require_relative 'notify'
7
+
8
+ module BuergerBot
9
+ BASE_URL = 'https://service.berlin.de/terminvereinbarung/termin/tag.php'
10
+
11
+ PERM_PARAMS = '?termin=1&herkunft=1'
12
+
13
+ DIENSTLEISTER = [
14
+ 122_210, 122_217, 122_219, 122_227, 122_231, 122_238, 122_243, 122_252, 122_260, 122_262, 122_254, 122_271, 122_273,
15
+ 122_277, 122_280, 122_282, 122_284, 122_291, 122_285, 122_286, 122_296, 150_230, 122_301, 122_297, 122_294, 122_312,
16
+ 122_314, 122_304, 122_311, 122_309, 317_869, 324_433, 325_341, 324_434, 324_435, 122_281, 324_414, 122_283, 122_279,
17
+ 122_276, 122_274, 122_267, 122_246, 122_251, 122_257, 122_208, 122_226
18
+ ].freeze
19
+
20
+ BLAUE_KARTE = 326_798
21
+
22
+ # Robot is the main class of the Buerger::Bot gem.
23
+ class Robot
24
+ def initialize
25
+ @name = "#{NAME} #{VERSION}"
26
+ end
27
+
28
+ def make_url(service = BLAUE_KARTE)
29
+ init_params = PERM_PARAMS
30
+
31
+ with_location_params = DIENSTLEISTER.reduce(init_params) do |query, dl|
32
+ query + "&dienstleister[]=#{dl}"
33
+ end
34
+
35
+ BASE_URL + with_location_params + "&anliegen[]=#{service}"
36
+ end
37
+
38
+ def promt_user
39
+ Notifications.notify 'Appointment found!', open_chrome: true
40
+ Logger.log 'Press y to keep looking for appointments, any other key to exit'
41
+ gets.chomp.downcase != 'y'
42
+ end
43
+
44
+ def found_appointment?(browser, service_url)
45
+ browser.goto service_url
46
+ link = browser.element css: '.calendar-month-table:first-child td.buchbar a'
47
+ if link.exists?
48
+ link.click
49
+ promt_user
50
+ end
51
+ false
52
+ rescue StandardError => e
53
+ Logger.fail(e.inspect)
54
+ false
55
+ end
56
+
57
+ def run
58
+ Logger.log "Starting #{@name}..."
59
+ browser = Watir::Browser.new :chrome
60
+ # Logger.log "Enter Service ID or 0 for default (#{BLAUE_KARTE}):"
61
+ # service = gets.chomp.to_i
62
+ # service = BLAUE_KARTE if service.zero? || service.nil?
63
+ service_url = make_url BLAUE_KARTE
64
+
65
+ until found_appointment?(browser, service_url)
66
+ Logger.log 'No appointment found, retrying in 25 seconds...'
67
+ sleep 25
68
+ Logger.log "#{'-' * 80}\nTrying again"
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BuergerBot
4
+ VERSION = '0.1.0'
5
+ NAME = 'BuergerBot'
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'bot/version'
4
+ require_relative 'bot/notify'
5
+ require_relative 'bot/logger'
6
+ require_relative 'bot/robot'
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buergerbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fahad Hossain
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Find appointments at the Bürgeramt in Berlin
14
+ email:
15
+ - set.name.fahad@gmail.com
16
+ executables:
17
+ - buerger-bot
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".standard.yml"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - buergerbot.gemspec
29
+ - exe/buerger-bot
30
+ - lib/buergerbot/bot.rb
31
+ - lib/buergerbot/bot/logger.rb
32
+ - lib/buergerbot/bot/notify.rb
33
+ - lib/buergerbot/bot/robot.rb
34
+ - lib/buergerbot/bot/version.rb
35
+ homepage: https://github.com/fa7ad/buerger-bot
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/fa7ad/buerger-bot
40
+ source_code_uri: https://github.com/fa7ad/buerger-bot
41
+ changelog_uri: https://github.com/fa7ad/buerger-bot/blob/main/CHANGELOG.md
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.1.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.3.11
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Find appointments at the Bürgeramt in Berlin
61
+ test_files: []