chemistry_paradise 1.4.2
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 +7 -0
- data/README.md +657 -0
- data/bin/chemistry_paradise +7 -0
- data/bin/wetter +7 -0
- data/chemistry_paradise.gemspec +46 -0
- data/doc/README.gen +595 -0
- data/doc/bugs/BUGS.md +16 -0
- data/doc/formulas/biochemical_calculations.md +5 -0
- data/doc/todo/todo_for_the_chemistry_paradise_project.md +33 -0
- data/doc/todo/todo_for_the_wetter_project.md +7 -0
- data/lib/chemistry_paradise/base/base.rb +215 -0
- data/lib/chemistry_paradise/base/colours.rb +93 -0
- data/lib/chemistry_paradise/commandline/help.rb +40 -0
- data/lib/chemistry_paradise/commandline/menu.rb +88 -0
- data/lib/chemistry_paradise/commandline/parse_commandline.rb +94 -0
- data/lib/chemistry_paradise/constants/constants.rb +77 -0
- data/lib/chemistry_paradise/constants/constants_for_chemical_formulas.rb +16 -0
- data/lib/chemistry_paradise/constants/file_constants.rb +33 -0
- data/lib/chemistry_paradise/constants/german_names_of_elements_to_element_symbol.rb +157 -0
- data/lib/chemistry_paradise/converters/celsius_to_fahrenheit.rb +143 -0
- data/lib/chemistry_paradise/converters/celsius_to_kelvin.rb +125 -0
- data/lib/chemistry_paradise/converters/fahrenheit_to_celsius.rb +132 -0
- data/lib/chemistry_paradise/converters/shared.rb +21 -0
- data/lib/chemistry_paradise/gui/gtk3/calculate_molecular_weight/calculate_molecular_weight.rb +34 -0
- data/lib/chemistry_paradise/gui/gtk3/show_periodic_table/show_periodic_table.rb +34 -0
- data/lib/chemistry_paradise/gui/gtk3/temperature_converter/temperature_converter.rb +112 -0
- data/lib/chemistry_paradise/gui/gtk3/wetter/wetter.rb +119 -0
- data/lib/chemistry_paradise/gui/libui/temperature_converter/temperature_converter.rb +100 -0
- data/lib/chemistry_paradise/gui/libui/wetter/wetter.rb +47 -0
- data/lib/chemistry_paradise/gui/shared_code/calculate_molecular_weight/calculate_molecular_weight_module.rb +171 -0
- data/lib/chemistry_paradise/gui/shared_code/show_periodic_table/show_periodic_table_module.rb +318 -0
- data/lib/chemistry_paradise/gui/shared_code/temperature_converter/temperature_converter_module.rb +192 -0
- data/lib/chemistry_paradise/gui/shared_code/wetter/wetter_module.rb +349 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter$1.class +0 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter.class +0 -0
- data/lib/chemistry_paradise/gui/swing/TemperatureConverter.java +133 -0
- data/lib/chemistry_paradise/gui/unified_widgets/wetter/wetter.rb +62 -0
- data/lib/chemistry_paradise/images/show_periodic_table.png +0 -0
- data/lib/chemistry_paradise/images/vienna_map.png +0 -0
- data/lib/chemistry_paradise/interactive_chemistry_shell.rb +246 -0
- data/lib/chemistry_paradise/project/project.rb +24 -0
- data/lib/chemistry_paradise/requires/common_external_requires.rb +17 -0
- data/lib/chemistry_paradise/requires/require_the_project.rb +21 -0
- data/lib/chemistry_paradise/requires/require_the_project_including_the_graphical_user_interface.rb +7 -0
- data/lib/chemistry_paradise/requires/require_the_project_including_the_web_interface.rb +4 -0
- data/lib/chemistry_paradise/shared.rb +130 -0
- data/lib/chemistry_paradise/show_electron_configuration.rb +250 -0
- data/lib/chemistry_paradise/show_element.rb +145 -0
- data/lib/chemistry_paradise/sinatra/sinatra.rb +131 -0
- data/lib/chemistry_paradise/sinatra/wetter/app.rb +68 -0
- data/lib/chemistry_paradise/sinatra/wetter/start_sinatra_interface.rb +31 -0
- data/lib/chemistry_paradise/split_molecule_names.rb +228 -0
- data/lib/chemistry_paradise/toplevel_methods/atomgewichte.rb +31 -0
- data/lib/chemistry_paradise/toplevel_methods/convert_parens.rb +64 -0
- data/lib/chemistry_paradise/toplevel_methods/display_where_the_molmasses_are_kept.rb +24 -0
- data/lib/chemistry_paradise/toplevel_methods/e.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/kelvin.rb +34 -0
- data/lib/chemistry_paradise/toplevel_methods/language.rb +50 -0
- data/lib/chemistry_paradise/toplevel_methods/misc.rb +228 -0
- data/lib/chemistry_paradise/toplevel_methods/periodic_table.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/remove_this_molecule_from.rb +63 -0
- data/lib/chemistry_paradise/toplevel_methods/roebe.rb +16 -0
- data/lib/chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb +26 -0
- data/lib/chemistry_paradise/utility_scripts/calculate_atomic_mass.rb +559 -0
- data/lib/chemistry_paradise/utility_scripts/combustion_analysis.rb +207 -0
- data/lib/chemistry_paradise/utility_scripts/electron_negativity_chart.rb +78 -0
- data/lib/chemistry_paradise/utility_scripts/equalize_chemical_formula.rb +84 -0
- data/lib/chemistry_paradise/utility_scripts/equation_solver.rb +130 -0
- data/lib/chemistry_paradise/utility_scripts/orbitals.rb +70 -0
- data/lib/chemistry_paradise/utility_scripts/show_electron_negativity_of_this_element.rb +103 -0
- data/lib/chemistry_paradise/utility_scripts/show_periodic_table.rb +996 -0
- data/lib/chemistry_paradise/verbose_chemical_calculation.rb +21 -0
- data/lib/chemistry_paradise/version/version.rb +19 -0
- data/lib/chemistry_paradise/wetter/wetter.rb +539 -0
- data/lib/chemistry_paradise/www/wetter/embeddable_interface.rb +78 -0
- data/lib/chemistry_paradise/www/wetter/wetter.cgi +28 -0
- data/lib/chemistry_paradise/yaml/atomgewichte.yml +139 -0
- data/lib/chemistry_paradise/yaml/colours_for_the_elements.yml +13 -0
- data/lib/chemistry_paradise/yaml/dichte.yml +21 -0
- data/lib/chemistry_paradise/yaml/electron_negativity_chart.yml +111 -0
- data/lib/chemistry_paradise/yaml/molecular_formula_of_different_molecules.yml +13 -0
- data/lib/chemistry_paradise/yaml/periodic_table_of_the_elements.yml +125 -0
- data/lib/chemistry_paradise.rb +1 -0
- data/test/testing_chemistry_paradise.rb +49 -0
- metadata +175 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# Purpose of this class is to explain what we are doing in a
|
|
6
|
+
# step-by-step wise fashion.
|
|
7
|
+
#
|
|
8
|
+
# Right now this is a stub.
|
|
9
|
+
# =========================================================================== #
|
|
10
|
+
module ChemistryParadise
|
|
11
|
+
|
|
12
|
+
class VerboseChemicalCalculation
|
|
13
|
+
|
|
14
|
+
# ========================================================================= #
|
|
15
|
+
# === initialize
|
|
16
|
+
# ========================================================================= #
|
|
17
|
+
def initialize
|
|
18
|
+
e 'This is currently a stub.'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end; end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'chemistry_paradise/version/version.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module ChemistryParadise
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === VERSION
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
VERSION = '1.4.2'
|
|
13
|
+
|
|
14
|
+
# ========================================================================= #
|
|
15
|
+
# === LAST_UPDATE
|
|
16
|
+
# ========================================================================= #
|
|
17
|
+
LAST_UPDATE = '10.11.2023'
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === ChemistryParadise::Wetter
|
|
6
|
+
#
|
|
7
|
+
# Code pertaining to the Wetter class will be stored here in this file,
|
|
8
|
+
# or in a subdirectory of the base.
|
|
9
|
+
#
|
|
10
|
+
# What is the purpose of this small class?
|
|
11
|
+
#
|
|
12
|
+
# This class will show the local weather in Vienna, by "parsing"
|
|
13
|
+
# a remote website that contains this information.
|
|
14
|
+
#
|
|
15
|
+
# The main regex in use can also be anchored towards "12.2°", if
|
|
16
|
+
# otherwise the dataset is nil.
|
|
17
|
+
#
|
|
18
|
+
# Usage example:
|
|
19
|
+
#
|
|
20
|
+
# ChemistryParadise::Wetter.new(ARGV)
|
|
21
|
+
#
|
|
22
|
+
# =========================================================================== #
|
|
23
|
+
# require 'chemistry_paradise/wetter/wetter.rb'
|
|
24
|
+
# =========================================================================== #
|
|
25
|
+
require 'chemistry_paradise/base/base.rb'
|
|
26
|
+
|
|
27
|
+
module ChemistryParadise
|
|
28
|
+
|
|
29
|
+
class Wetter < ::ChemistryParadise::Base # === ChemistryParadise::Wetter
|
|
30
|
+
|
|
31
|
+
begin
|
|
32
|
+
require 'open-uri'
|
|
33
|
+
rescue LoadError; end
|
|
34
|
+
|
|
35
|
+
begin
|
|
36
|
+
# ======================================================================= #
|
|
37
|
+
# If we want to tap into this functionality here, we only have to
|
|
38
|
+
# use: opn(namespace: namespace?);
|
|
39
|
+
# ======================================================================= #
|
|
40
|
+
require 'opn'
|
|
41
|
+
rescue LoadError; end
|
|
42
|
+
|
|
43
|
+
# ========================================================================= #
|
|
44
|
+
# === NAMESPACE
|
|
45
|
+
# ========================================================================= #
|
|
46
|
+
NAMESPACE = inspect
|
|
47
|
+
|
|
48
|
+
# ========================================================================= #
|
|
49
|
+
# === REMOTE_URL
|
|
50
|
+
#
|
|
51
|
+
# Point to the remote website that holds the information for the
|
|
52
|
+
# local temperature in the city of Vienna.
|
|
53
|
+
# ========================================================================= #
|
|
54
|
+
REMOTE_URL = 'https://www.zamg.ac.at/cms/de/wetter/wetterwerte-analysen/wien'
|
|
55
|
+
|
|
56
|
+
# ========================================================================= #
|
|
57
|
+
# === TRY_TO_MAKE_USE_OF_THE_UNICODE_WEATHER_SYMBOL
|
|
58
|
+
#
|
|
59
|
+
# If the next constant is set to true then class Wetter will try to
|
|
60
|
+
# make use of the unicode symbol for "cloudy weather".
|
|
61
|
+
# ========================================================================= #
|
|
62
|
+
TRY_TO_MAKE_USE_OF_THE_UNICODE_WEATHER_SYMBOL = true
|
|
63
|
+
|
|
64
|
+
# ========================================================================= #
|
|
65
|
+
# === USE_THIS_REGEX
|
|
66
|
+
#
|
|
67
|
+
# This is the regex handling some remote "Temp:" String.
|
|
68
|
+
# ========================================================================= #
|
|
69
|
+
USE_THIS_REGEX = /Temp: (-?\d+.\d+)/ # It also handles negative temperature.
|
|
70
|
+
|
|
71
|
+
# ========================================================================= #
|
|
72
|
+
# === USE_DEGREE_REGEX
|
|
73
|
+
#
|
|
74
|
+
# This second regex can be used when we wish to match against ° values.
|
|
75
|
+
# ========================================================================= #
|
|
76
|
+
USE_DEGREE_REGEX = /\>(\d+.\d+)°\</ # See: https://rubular.com/r/FheegP7Hfg
|
|
77
|
+
|
|
78
|
+
# ========================================================================= #
|
|
79
|
+
# === initialize
|
|
80
|
+
# ========================================================================= #
|
|
81
|
+
def initialize(
|
|
82
|
+
i = ARGV, # The commandline arguments are stored here.
|
|
83
|
+
run_already = true,
|
|
84
|
+
&block
|
|
85
|
+
)
|
|
86
|
+
reset
|
|
87
|
+
set_commandline_arguments(i)
|
|
88
|
+
# ======================================================================= #
|
|
89
|
+
# === Handle blocks next
|
|
90
|
+
# ======================================================================= #
|
|
91
|
+
if block_given?
|
|
92
|
+
yielded = yield
|
|
93
|
+
case yielded
|
|
94
|
+
# ===================================================================== #
|
|
95
|
+
# === :be_silent
|
|
96
|
+
# ===================================================================== #
|
|
97
|
+
when :be_silent
|
|
98
|
+
set_be_quiet
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
run if run_already
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# ========================================================================= #
|
|
105
|
+
# === reset (reset tag)
|
|
106
|
+
# ========================================================================= #
|
|
107
|
+
def reset
|
|
108
|
+
super()
|
|
109
|
+
initialize_the_internal_hash
|
|
110
|
+
# ======================================================================= #
|
|
111
|
+
# === :debug
|
|
112
|
+
# ======================================================================= #
|
|
113
|
+
@internal_hash[:debug] = false
|
|
114
|
+
# ======================================================================= #
|
|
115
|
+
# === :data
|
|
116
|
+
# ======================================================================= #
|
|
117
|
+
@internal_hash[:data] = nil
|
|
118
|
+
# ======================================================================= #
|
|
119
|
+
# === :match
|
|
120
|
+
# ======================================================================= #
|
|
121
|
+
@internal_hash[:match] = nil
|
|
122
|
+
# ======================================================================= #
|
|
123
|
+
# === :shall_we_report_openssl_errors
|
|
124
|
+
# ======================================================================= #
|
|
125
|
+
@internal_hash[:shall_we_report_openssl_errors] = false
|
|
126
|
+
# ======================================================================= #
|
|
127
|
+
# === @namespace
|
|
128
|
+
# ======================================================================= #
|
|
129
|
+
@namespace = NAMESPACE
|
|
130
|
+
be_verbose
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# ========================================================================= #
|
|
134
|
+
# === menu (menu tag)
|
|
135
|
+
# ========================================================================= #
|
|
136
|
+
def menu(
|
|
137
|
+
i = commandline_arguments?
|
|
138
|
+
)
|
|
139
|
+
if i.is_a? Array
|
|
140
|
+
i.each {|entry| menu(entry) }
|
|
141
|
+
else
|
|
142
|
+
case i # case tag
|
|
143
|
+
# ===================================================================== #
|
|
144
|
+
# === help
|
|
145
|
+
# ===================================================================== #
|
|
146
|
+
when /^-?-?help$/i
|
|
147
|
+
show_help
|
|
148
|
+
exit
|
|
149
|
+
# ===================================================================== #
|
|
150
|
+
# === --URL
|
|
151
|
+
# ===================================================================== #
|
|
152
|
+
when /^-?-?URL$/i
|
|
153
|
+
show_the_remote_url
|
|
154
|
+
exit
|
|
155
|
+
# ===================================================================== #
|
|
156
|
+
# === debug
|
|
157
|
+
# ===================================================================== #
|
|
158
|
+
when /debug/
|
|
159
|
+
enable_debug_mode
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# ========================================================================= #
|
|
165
|
+
# === match?
|
|
166
|
+
# ========================================================================= #
|
|
167
|
+
def match?
|
|
168
|
+
@internal_hash[:match]
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# ========================================================================= #
|
|
172
|
+
# === enable_debug_mode
|
|
173
|
+
# ========================================================================= #
|
|
174
|
+
def enable_debug_mode
|
|
175
|
+
@internal_hash[:debug] = true
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# ========================================================================= #
|
|
179
|
+
# === debug?
|
|
180
|
+
# ========================================================================= #
|
|
181
|
+
def debug?
|
|
182
|
+
@internal_hash[:debug]
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# ========================================================================= #
|
|
186
|
+
# === show_help
|
|
187
|
+
# ========================================================================= #
|
|
188
|
+
def show_help
|
|
189
|
+
e
|
|
190
|
+
e ' --URL # show the remote URL'
|
|
191
|
+
e ' --sinatra # start the sinatra-interface of this gem'
|
|
192
|
+
e
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# ========================================================================= #
|
|
196
|
+
# === show_the_remote_url
|
|
197
|
+
#
|
|
198
|
+
# To invoke this method, do:
|
|
199
|
+
#
|
|
200
|
+
# wetter --URL
|
|
201
|
+
#
|
|
202
|
+
# ========================================================================= #
|
|
203
|
+
def show_the_remote_url
|
|
204
|
+
e
|
|
205
|
+
e sfancy(" #{REMOTE_URL}")
|
|
206
|
+
e
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# ========================================================================= #
|
|
210
|
+
# === try_to_make_use_of_the_unicode_weather_symbol?
|
|
211
|
+
# ========================================================================= #
|
|
212
|
+
def try_to_make_use_of_the_unicode_weather_symbol?
|
|
213
|
+
TRY_TO_MAKE_USE_OF_THE_UNICODE_WEATHER_SYMBOL
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# ========================================================================= #
|
|
217
|
+
# === data?
|
|
218
|
+
# ========================================================================= #
|
|
219
|
+
def data?
|
|
220
|
+
@internal_hash[:data]
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# ========================================================================= #
|
|
224
|
+
# === remote_URL?
|
|
225
|
+
# ========================================================================= #
|
|
226
|
+
def remote_URL?
|
|
227
|
+
REMOTE_URL
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# ========================================================================= #
|
|
231
|
+
# === local_file?
|
|
232
|
+
# ========================================================================= #
|
|
233
|
+
def local_file?
|
|
234
|
+
File.absolute_path(File.basename(remote_URL?)+'.html')
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# ========================================================================= #
|
|
238
|
+
# === try_to_download_the_remote_webpage
|
|
239
|
+
#
|
|
240
|
+
# This method was specifically added in February 2023, to bypass any
|
|
241
|
+
# issue we may have had when openssl is not available. It will rely
|
|
242
|
+
# on "wget" to download the webpage.
|
|
243
|
+
# ========================================================================= #
|
|
244
|
+
def try_to_download_the_remote_webpage(
|
|
245
|
+
remote_URL = remote_URL?,
|
|
246
|
+
be_verbose = be_verbose?
|
|
247
|
+
)
|
|
248
|
+
base_dir = '/home/x/Temp/wetter/'
|
|
249
|
+
if is_on_roebe? and !File.directory?(base_dir)
|
|
250
|
+
require 'fileutils'
|
|
251
|
+
FileUtils.mkdir_p(base_dir)
|
|
252
|
+
end
|
|
253
|
+
cd(base_dir) if File.directory?(base_dir)
|
|
254
|
+
local_file = File.absolute_path(File.basename(remote_URL)+'.html')
|
|
255
|
+
if File.exist?(local_file)
|
|
256
|
+
File.delete(local_file) # Remove any old file first.
|
|
257
|
+
end
|
|
258
|
+
if File.exist?(local_file.delete_suffix('.html'))
|
|
259
|
+
File.delete(local_file.delete_suffix('.html')) # Remove any old file first.
|
|
260
|
+
end
|
|
261
|
+
# ======================================================================= #
|
|
262
|
+
# Next, download the remote file.
|
|
263
|
+
# ======================================================================= #
|
|
264
|
+
esystem(
|
|
265
|
+
"wget #{remote_URL}", :silence_output_from_system
|
|
266
|
+
) { :be_quiet }
|
|
267
|
+
unless File.exist?(local_file)
|
|
268
|
+
require 'fileutils'
|
|
269
|
+
if File.exist? local_file.delete_suffix('.html')
|
|
270
|
+
FileUtils.mv(
|
|
271
|
+
local_file.delete_suffix('.html'),
|
|
272
|
+
local_file
|
|
273
|
+
)
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
if File.exist? local_file and
|
|
277
|
+
be_verbose and
|
|
278
|
+
shall_we_report_openssl_errors?
|
|
279
|
+
opn; e "The remote file was downloaded into `#{sfile(local_file)}`."
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# ========================================================================= #
|
|
284
|
+
# === read_in_the_dataset_from_the_remote_webpage
|
|
285
|
+
#
|
|
286
|
+
# This method has to catch OpenSSL errors.
|
|
287
|
+
# ========================================================================= #
|
|
288
|
+
def read_in_the_dataset_from_the_remote_webpage
|
|
289
|
+
begin
|
|
290
|
+
@internal_hash[:data] = URI.open(remote_URL?).read
|
|
291
|
+
rescue OpenSSL::SSL::SSLError => _error
|
|
292
|
+
# ===================================================================== #
|
|
293
|
+
# Here we know that an OpenSSL connection error occurred.
|
|
294
|
+
# We will notify the user about this but only one sentence.
|
|
295
|
+
# ===================================================================== #
|
|
296
|
+
_ = local_file?
|
|
297
|
+
if File.exist? _
|
|
298
|
+
if be_verbose and shall_we_report_openssl_errors?
|
|
299
|
+
opn; e 'An OpenSSL-error occurred. Trying to read from the'
|
|
300
|
+
opn; e 'local file at '+sfile(_)+' next.'
|
|
301
|
+
end
|
|
302
|
+
internal_hash[:data] = File.read(_)
|
|
303
|
+
else
|
|
304
|
+
e 'An OpenSSL-error occurred. Can not continue.' if be_verbose
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
if debug?
|
|
308
|
+
opn; e 'Now showing @internal_hash[:data], as we run in debug-mode.'
|
|
309
|
+
e cliner
|
|
310
|
+
e data?
|
|
311
|
+
e cliner
|
|
312
|
+
end
|
|
313
|
+
return @internal_hash[:data]
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# ========================================================================= #
|
|
317
|
+
# === shall_we_report_openssl_errors?
|
|
318
|
+
# ========================================================================= #
|
|
319
|
+
def shall_we_report_openssl_errors?
|
|
320
|
+
@internal_hash[:shall_we_report_openssl_errors]
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# ========================================================================= #
|
|
324
|
+
# === sanitize_the_dataset
|
|
325
|
+
# ========================================================================= #
|
|
326
|
+
def sanitize_the_dataset
|
|
327
|
+
splitted = data?.split(N)
|
|
328
|
+
splitted.reject! {|line|
|
|
329
|
+
! (line.include?('title="Wien Innere Stadt') and line.include?('Temp: '))
|
|
330
|
+
}
|
|
331
|
+
splitted = splitted.first if splitted.is_a? Array
|
|
332
|
+
if debug?
|
|
333
|
+
opn; e 'Now showing the sanitized dataset, as we run in debug-mode.'
|
|
334
|
+
pp splitted
|
|
335
|
+
end
|
|
336
|
+
@internal_hash[:data] = splitted # Re-assign it here.
|
|
337
|
+
if data?.nil?
|
|
338
|
+
@internal_hash[:data] =~ USE_DEGREE_REGEX
|
|
339
|
+
unless $1.to_s.dup.empty?
|
|
340
|
+
@internal_hash[:data] = $1.to_s.dup
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# ========================================================================= #
|
|
346
|
+
# === find_the_appropriate_match
|
|
347
|
+
#
|
|
348
|
+
# This will find the current degree, in Celsius.
|
|
349
|
+
# ========================================================================= #
|
|
350
|
+
def find_the_appropriate_match
|
|
351
|
+
@internal_hash[:data] =~ USE_THIS_REGEX # Apply the appropriate regex here.
|
|
352
|
+
@internal_hash[:match] = $1.to_s.dup
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
# ========================================================================= #
|
|
356
|
+
# === report_the_result
|
|
357
|
+
# ========================================================================= #
|
|
358
|
+
def report_the_result
|
|
359
|
+
if be_verbose?
|
|
360
|
+
n_degrees_celsius = match?.to_f
|
|
361
|
+
result = "#{olivedrab('The current temperature in Vienna is: ')}"\
|
|
362
|
+
"#{sfancy(n_degrees_celsius)} #{gold('°C')}".dup
|
|
363
|
+
# ===================================================================== #
|
|
364
|
+
# Next we have to check if we use a fancy unicode weather symbol:
|
|
365
|
+
# ===================================================================== #
|
|
366
|
+
if try_to_make_use_of_the_unicode_weather_symbol?
|
|
367
|
+
begin
|
|
368
|
+
require 'roebe/toplevel_methods/unicode/popular_unicode_symbols.rb'
|
|
369
|
+
case n_degrees_celsius
|
|
370
|
+
when 16 .. 50 # Should be clear weather most of the time.
|
|
371
|
+
result << " #{tomato(Roebe.clear_weather)}"
|
|
372
|
+
when 5 .. 15 # Medium-temperature; usually cloudy.
|
|
373
|
+
result << " #{royalblue(Roebe.cloudy_weather_symbol)}"
|
|
374
|
+
when -35 .. 4 # It's really quite cold.
|
|
375
|
+
result << " #{royalblue(Roebe.snowman)}"
|
|
376
|
+
end
|
|
377
|
+
rescue LoadError
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
# ===================================================================== #
|
|
381
|
+
# Next display which class reports the output as well:
|
|
382
|
+
# ===================================================================== #
|
|
383
|
+
opn; e result
|
|
384
|
+
end
|
|
385
|
+
end; alias report report_the_result # === report
|
|
386
|
+
|
|
387
|
+
# ========================================================================= #
|
|
388
|
+
# === run (run tag)
|
|
389
|
+
# ========================================================================= #
|
|
390
|
+
def run
|
|
391
|
+
menu
|
|
392
|
+
try_to_download_the_remote_webpage
|
|
393
|
+
read_in_the_dataset_from_the_remote_webpage
|
|
394
|
+
sanitize_the_dataset
|
|
395
|
+
find_the_appropriate_match
|
|
396
|
+
report
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
# ========================================================================= #
|
|
400
|
+
# === ChemistryParadise::Wetter.menu (menu tag)
|
|
401
|
+
# ========================================================================= #
|
|
402
|
+
def self.menu(i)
|
|
403
|
+
if i.is_a? Array
|
|
404
|
+
if i.empty?
|
|
405
|
+
new(i)
|
|
406
|
+
else
|
|
407
|
+
i.each {|entry| menu(entry) }
|
|
408
|
+
end
|
|
409
|
+
else
|
|
410
|
+
case i
|
|
411
|
+
# ===================================================================== #
|
|
412
|
+
# === wetter --libui
|
|
413
|
+
# ===================================================================== #
|
|
414
|
+
when /^-?-?libui$/i
|
|
415
|
+
puts 'Starting the libui wetter (aka "weather") application next.'
|
|
416
|
+
require 'chemistry_paradise/gui/libui/wetter/wetter.rb'
|
|
417
|
+
ChemistryParadise::GUI::LibUI::Wetter.new
|
|
418
|
+
exit
|
|
419
|
+
# ===================================================================== #
|
|
420
|
+
# === wetter --sinatra
|
|
421
|
+
#
|
|
422
|
+
# This entry point starts the sinatra-interface of the wetter
|
|
423
|
+
# project.
|
|
424
|
+
#
|
|
425
|
+
# Invocation example:
|
|
426
|
+
#
|
|
427
|
+
# wetter --sinatra
|
|
428
|
+
#
|
|
429
|
+
# ===================================================================== #
|
|
430
|
+
when /^-?-?sinatra$/i,
|
|
431
|
+
/^-?-?www$/i
|
|
432
|
+
require 'chemistry_paradise/sinatra/wetter/start_sinatra_interface.rb'
|
|
433
|
+
ChemistryParadise::Wetter.start_sinatra_interface
|
|
434
|
+
# ===================================================================== #
|
|
435
|
+
# === wetter --gtk3
|
|
436
|
+
# ===================================================================== #
|
|
437
|
+
when /^-?-?gtk3?$/i,
|
|
438
|
+
/^-?-?gui$/i # === wetter --gui
|
|
439
|
+
puts 'Starting the ruby-gtk3 wetter (aka "weather") application next.'
|
|
440
|
+
require 'chemistry_paradise/gui/gtk3/wetter/wetter.rb'
|
|
441
|
+
ChemistryParadise::GUI::Gtk::Wetter.run
|
|
442
|
+
exit
|
|
443
|
+
# ===================================================================== #
|
|
444
|
+
# === wetter --temperature-only
|
|
445
|
+
# ===================================================================== #
|
|
446
|
+
when /^-?-?temperature(-|_)?only$/i,
|
|
447
|
+
/^-?-?temperature\??$/i
|
|
448
|
+
puts Wetter.temperature?
|
|
449
|
+
exit
|
|
450
|
+
# ===================================================================== #
|
|
451
|
+
# === wetter --gtk2
|
|
452
|
+
# ===================================================================== #
|
|
453
|
+
when /^-?-?gtk2$/i
|
|
454
|
+
e 'Support for ruby-gtk2 has been removed in November 2021.'
|
|
455
|
+
e 'Please use the ruby-gtk3 variant instead.'
|
|
456
|
+
exit
|
|
457
|
+
else
|
|
458
|
+
Wetter.new(i)
|
|
459
|
+
end
|
|
460
|
+
end
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
# ========================================================================= #
|
|
464
|
+
# === ChemistryParadise::Wetter.project_base_directory?
|
|
465
|
+
# ========================================================================= #
|
|
466
|
+
def self.project_base_directory?
|
|
467
|
+
"#{ChemistryParadise.project_base_directory?}wetter/"
|
|
468
|
+
end; self.instance_eval { alias project_base_dir? project_base_directory? } # === RBT.project_base_dir?
|
|
469
|
+
self.instance_eval { alias project_dir? project_base_directory? } # === RBT.project_dir?
|
|
470
|
+
|
|
471
|
+
# ========================================================================= #
|
|
472
|
+
# === ChemistryParadise::Wetter.is_on_roebe?
|
|
473
|
+
# ========================================================================= #
|
|
474
|
+
def self.is_on_roebe?
|
|
475
|
+
ChemistryParadise.send(__method__)
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
# ========================================================================= #
|
|
479
|
+
# === ChemistryParadise::Wetter.current_degrees
|
|
480
|
+
#
|
|
481
|
+
# This method will simply return a Float number, the current temperature
|
|
482
|
+
# in Vienna by default.
|
|
483
|
+
#
|
|
484
|
+
# Usage examples:
|
|
485
|
+
#
|
|
486
|
+
# ChemistryParadise::Wetter.current_degrees
|
|
487
|
+
# ChemistryParadise::Wetter.simplified_current_degrees
|
|
488
|
+
#
|
|
489
|
+
# ========================================================================= #
|
|
490
|
+
def self.current_degrees
|
|
491
|
+
new { :be_silent }.match?.to_f
|
|
492
|
+
end; self.instance_eval { alias n_degrees_celsius? current_degrees } # === ChemistryParadise::Wetter.n_degrees_celsius?
|
|
493
|
+
self.instance_eval { alias temperature? current_degrees } # === ChemistryParadise::Wetter.temperature?
|
|
494
|
+
self.instance_eval { alias return_temperature current_degrees } # === ChemistryParadise::Wetter.return_temperature
|
|
495
|
+
self.instance_eval { alias return_current_temperature_in_vienna current_degrees } # === ChemistryParadise::Wetter.return_current_temperature_in_vienna
|
|
496
|
+
self.instance_eval { alias simplified_current_degrees current_degrees } # === ChemistryParadise::Wetter.simplified_current_degrees
|
|
497
|
+
self.instance_eval { alias return_current_degrees current_degrees } # === ChemistryParadise::Wetter.return_current_degrees
|
|
498
|
+
|
|
499
|
+
# ========================================================================= #
|
|
500
|
+
# === ChemistryParadise::Wetter.run
|
|
501
|
+
# ========================================================================= #
|
|
502
|
+
def self.run(
|
|
503
|
+
i = ARGV
|
|
504
|
+
)
|
|
505
|
+
new(i)
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
# ========================================================================= #
|
|
509
|
+
# === ChemistryParadise::Wetter.gtk3_widget
|
|
510
|
+
#
|
|
511
|
+
# Simpler toplevel-method to obtain a new gtk-widget instance for the
|
|
512
|
+
# wetter project. It will only work if the gtk3 code has been
|
|
513
|
+
# required prior to calling this method.
|
|
514
|
+
# ========================================================================= #
|
|
515
|
+
def self.gtk3_widget
|
|
516
|
+
::Wetter::GUI::Wetter.gtk3_widget
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
# =========================================================================== #
|
|
522
|
+
# === ChemistryParadise.simplified_current_degrees
|
|
523
|
+
# =========================================================================== #
|
|
524
|
+
def self.simplified_current_degrees
|
|
525
|
+
ChemistryParadise::Wetter.simplified_current_degrees
|
|
526
|
+
end; self.instance_eval { alias current_temperature_in_vienna? simplified_current_degrees } # === ChemistryParadise.current_temperature_in_vienna?
|
|
527
|
+
self.instance_eval { alias n_degrees_celsius? simplified_current_degrees } # === ChemistryParadise.n_degrees_celsius?
|
|
528
|
+
self.instance_eval { alias return_current_degrees simplified_current_degrees } # === ChemistryParadise.return_current_degrees
|
|
529
|
+
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
if __FILE__ == $PROGRAM_NAME
|
|
533
|
+
alias e puts
|
|
534
|
+
ChemistryParadise::Wetter.new(ARGV)
|
|
535
|
+
e ChemistryParadise.project_base_dir?
|
|
536
|
+
e ChemistryParadise::Wetter.project_base_dir?
|
|
537
|
+
e 'Are we on roebe: '+ChemistryParadise::Wetter.is_on_roebe?.to_s
|
|
538
|
+
# rb wetter.rb --help
|
|
539
|
+
end # wetterrb
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === ChemistryParadise::Wetter::EmbeddableInterface
|
|
6
|
+
#
|
|
7
|
+
# The code in this file can be used to "embed" the functionality of
|
|
8
|
+
# Wetter in web-applications, in particular in sinatra.
|
|
9
|
+
#
|
|
10
|
+
# This depends on the cyberweb project.
|
|
11
|
+
# =========================================================================== #
|
|
12
|
+
# require 'chemistry_paradise/www/www/embeddable_interface.rb'
|
|
13
|
+
# include ChemistryParadise/Wetter::EmbeddableInterface
|
|
14
|
+
# =========================================================================== #
|
|
15
|
+
require 'chemistry_paradise/base/base.rb'
|
|
16
|
+
|
|
17
|
+
module ChemistryParadise
|
|
18
|
+
|
|
19
|
+
class Wetter < ::ChemistryParadise::Base # === ChemistryParadise::Wetter
|
|
20
|
+
|
|
21
|
+
module EmbeddableInterface # === Wetter::EmbeddableInterface
|
|
22
|
+
|
|
23
|
+
require 'chemistry_paradise/wetter/wetter.rb'
|
|
24
|
+
|
|
25
|
+
begin
|
|
26
|
+
require 'html_tags'
|
|
27
|
+
include HtmlTags::BaseModule
|
|
28
|
+
rescue LoadError; end
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
require 'cyberweb/sinatra/custom_extensions.rb'
|
|
32
|
+
include Cyberweb::Sinatra::CustomExtensions
|
|
33
|
+
rescue LoadError; end
|
|
34
|
+
|
|
35
|
+
begin
|
|
36
|
+
require 'cyberweb/html_template/html_template.rb'
|
|
37
|
+
rescue LoadError; end
|
|
38
|
+
|
|
39
|
+
# ========================================================================= #
|
|
40
|
+
# === return_root_string
|
|
41
|
+
# ========================================================================= #
|
|
42
|
+
def return_root_string
|
|
43
|
+
current_temperature = ChemistryParadise.n_degrees_celsius?.to_s.dup
|
|
44
|
+
append_this = ''.dup
|
|
45
|
+
if current_temperature.to_f > 12
|
|
46
|
+
append_this << '°C</b><br><style>'+
|
|
47
|
+
Cyberweb.return_css_for_sunny_weather+
|
|
48
|
+
"</style>\n"+
|
|
49
|
+
'<div class="weather_container"><div class="weather_sunny"></div></div>'
|
|
50
|
+
else
|
|
51
|
+
append_this << '°C</b><br>'
|
|
52
|
+
end
|
|
53
|
+
Cyberweb::HtmlTemplate[
|
|
54
|
+
title: 'The weather/temperature in Vienna',
|
|
55
|
+
body: div('The current temperature in Vienna is: <br><br>'\
|
|
56
|
+
'<b style="padding:1em; margin:0.5em; font-size: larger">'+
|
|
57
|
+
current_temperature+
|
|
58
|
+
append_this,'','',
|
|
59
|
+
'font-size: 1.8em'
|
|
60
|
+
)
|
|
61
|
+
].to_s
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end; end
|
|
65
|
+
|
|
66
|
+
# =========================================================================== #
|
|
67
|
+
# === ChemistryParadise::Wetter.embeddable_interface
|
|
68
|
+
#
|
|
69
|
+
# This method can be used to "embed" a fake-object that implements the
|
|
70
|
+
# module defined above.
|
|
71
|
+
# =========================================================================== #
|
|
72
|
+
def self.embeddable_interface
|
|
73
|
+
object = Object.new
|
|
74
|
+
object.extend(ChemistryParadise::Wetter::EmbeddableInterface)
|
|
75
|
+
return object
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# http://localhost/programming/ruby/src/chemistry_paradise/lib/chemistry_paradise/www/wetter/wetter.cgi
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
require 'cyberweb/autoinclude'
|
|
8
|
+
require 'chemistry_paradise/wetter/wetter.rb'
|
|
9
|
+
|
|
10
|
+
german('Wetter') {
|
|
11
|
+
created_on '27.07.2022' # Wednesday.
|
|
12
|
+
autoextend
|
|
13
|
+
ruby_favicon
|
|
14
|
+
default_template Cyberweb.return_css_for_sunny_weather
|
|
15
|
+
body_css_class 'mar0px pad0px VERDANAs'
|
|
16
|
+
font_size '1.2em'
|
|
17
|
+
|
|
18
|
+
doc('mar0px pad0px s0_6em') {
|
|
19
|
+
h1 dot(106, 'marr8px')+
|
|
20
|
+
'Wetter',
|
|
21
|
+
'mart1px marb0_5em'
|
|
22
|
+
current_temperature = ChemistryParadise.n_degrees_celsius?.to_s.dup
|
|
23
|
+
div {
|
|
24
|
+
e 'The current temperature is: <b>'+
|
|
25
|
+
current_temperature.to_s+'</b>'
|
|
26
|
+
}
|
|
27
|
+
ee '<div class="weather_container"><div class="weather_sunny"></div></div>'
|
|
28
|
+
}}
|