My goal is move my C++ scripts to yaml and use esphome. I´ve started with something easy, esp8266+dht22+mqtt, really easy, but if i want to add also the timestamp in addition to temperature and humidity. I guess to use lambda?, text_sensor?. Any help will be appreciated.
This is my code:
sensor:
- platform: dht
pin: D5
model: AM2302
temperature:
name: "temperature_test"
filters:
- multiply: 0.92
humidity:
name: "humidity_test"
id: tempdht22
update_interval: 10s
mqtt:
#discovery_prefix: esphome_test
broker: 192.168.1.185
id: mqtt_client
I've got an YAML file that contains information from a Powerbi file. we need to add some of the metadata like Tags (we're talking here about tens of dosens if not hundreds.
what I thought is to extract this in an excel - write it there and then inject it back to yaml.
Any way to do that automatically?
here's a sample:
processTime: 08-06-22
report:
reportId: 34lkn34l5k
reportVersion: '1'
reportDeveloper: dev1
reportDomain: ''
linkedDataset: dataset
filters:
filterId: Filtera1
table: DIM_E
column: CLIENT
type: Categorical
metadata:
label: Company
tags: []
filterId: Filter2
table: DIM_E
column: DEPARTMENT
type: Categorical
metadata:
label: Department
tags: []
pages:
pageId: ReportSection
displayName: test
visuals:
visualId: 9dc8
visualType: donutChart
measures: Headcount
columns: - EMPLO
title: Headcount
metadata:
label: ''
tags: []
domain: diversity
hierarchy: []
I am working on the VST3 preset format. This is what I managed till now:
meta:
id: vstpreset
file-extension: vstpreset
endian: le
seq:
- id: magic
contents: 'VST3'
- id: version
type: u4
- id: class_id
type: str
size: 32
encoding: ASCII
- id: ofs_chunk_list
type: u8
instances:
chunk_list:
pos: ofs_chunk_list
type: chunk_list
size-eos: true
types:
chunk:
seq:
- id: blob
size-eos: true
chunk_list:
seq:
- id: magic
contents: 'List'
- id: len_entries
type: u4
- id: entries
repeat: expr
repeat-expr: len_entries
type: entry
types:
entry:
seq:
- id: id
type: u4
- id: offset
type: u8
- id: length
type: u8
instances:
chunk:
io: _root._io
pos: offset
size: length
This kind of works; however, I cannot figure out how to implement the section labelled DATA AREA in the illustration shown in the link above. Isn't it kinda unintuitive to store the CHUNK LIST after the DATA AREA?
Using this gem: whois (3.6.5)
Doing this:
Whois::Client.new(timeout: 2).lookup('miaz.ca')
And then trying to call .properties on the result of the call (pasted below)
"Domain name: miaz.ca\nDomain status: registered\nCreation date: 2014/03/12\nExpiry date:
2018/03/12\nUpdated date: 2017/03/02\nDNSSEC:
Unsigned\n\nRegistrar:\n Name: Go Daddy Domains
Canada, Inc\n Number: 2316042\n\nName servers:\n
ns61.domaincontrol.com\n ns62.domaincontrol.com\n\n% WHOIS look-up
made at 2017-08-15 20:13:15 (GMT)\n%\n% Use of CIRA's WHOIS service is
governed by the Terms of Use in its Legal\n% Notice, available at
http://www.cira.ca/legal-notice/?lang=en \n%\n% (c) 2017 Canadian
Internet Registration Authority, (http://www.cira.ca/) \n"
But then calling Whois::Client.new(timeout: 2).lookup('childrenandco.qa')
gives this response and .properties gives a undefined method 'zip' for "shops.myshopify.com":String:
"Domain Name: childrenandco.qa\r\nLast Modified: 15-Aug-2017 14:06:49 UTC\r\nRegistrar
Name: W3INFOTECH W.L.L\r\nStatus:
inactive\r\n\r\nRegistrant Contact ID: W3R2736\r\nRegistrant
Contact Name: Ibrahim alobaidan\r\nRegistrant Contact Email:
Visit www.domains.qa\r\n\r\nTech Contact ID:
W3T2736\r\nTech Contact Name: Ibrahim alobaidan\r\nTech
Contact Email: Visit www.domains.qa\r\n\r\nName Server:
shops.myshopify.com\r\n"
I have a text file where I have to read the content and append to it. i.e. make a copy of the file and append to it. I wrote the following code
#!/usr/bin/perl
use strict;
use warnings;
my $line;
open FILL, ">> fred"
or warn "Cannot open : $!";
while(<FILL>){
# s/^Author:.*/Author: Randal L. Schwartz/;
# s/^Phone:.*\n//;
# s/^Date:.*/Date: $date/;
$line.=$_;
print $line;
}
select FILL;
print $line;
But it doesn't enter the while loop at all and when I open a filehandle for the same file in read mode and select the file handle in append mode to print it works.
Input :
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Version: 2.1
Size: 21k
Status: Final beta
Output :
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Version: 2.1
Size: 21k
Status: Final beta
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Version: 2.1
Size: 21k
Status: Final beta
This program works correctly
#!/usr/bin/perl
use strict;
use warnings;
my $line;
open FIL, "fred"
or warn "Cannot open : $!";
open FILL, ">> fred"
or warn "Cannot open : $!";
while(<FIL>){
# s/^Author:.*/Author: Randal L. Schwartz/;
# s/^Phone:.*\n//;
# s/^Date:.*/Date: $date/;
$line.=$_;
print $line;
}
select FILL;
print $line;
It appends correctly in file but the terminal output is
Program name: granite
Program name: granite
Author: Gilbert Bates
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Version: 2.1
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Version: 2.1
Size: 21k
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Version: 2.1
Size: 21k
Status: Final beta
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Version: 2.1
Size: 21k
Status: Final beta
Why does it print so many times?
$line is the variable in which you accumulate everything read so far. So within the loop, you probably wanted to do
print $_;
or just
print;
instead of
print $line;
To answer your original question... You will want to open the file in both read and write (append) mode.
open FILL, '>>+', 'fred';
(Please don't use the 2-argument version of open. It's unsafe.)
But this places the file pointer at the end of the file, so you'll have to do a
seek FILL, 0, 0;
before reading. Since you read before writing, it makes no difference whether or not you open the file in append mode.
You should even be able to add another seek after reading the file, but I am not sure whether this is going to be portable across Unix and Windows.