Errors occur in the following conditions.
Running on local server (ubuntu on windows).
I deployed these files.
Token is minted.
The yaml file is generated via Django.
The generated file is then used to run the API request formatter to generate Json.
Template:
code:
(marmalade.ledger.sale
(read-msg 'token-id)
(read-msg 'account)
(read-decimal 'amount)
(read-integer 'timeout)
)
data:
token-id: "${token_id}"
account: "${account}"
amount: ${amount}
timeout: ${timeout}
quote:
price: "${price}"
recipient-guard:
keys:
[ "${recipient_key}", ]
recipient: ${recipient}
keyPairs:
- public: ${marmalade_pub}
secret: ${marmalade_sec}
caps:
- name: "marmalade.ledger.SALE"
args: ["${token_id}", "${account}", ${amount}, ${timeout}]
Generated File:
code:
(marmalade.ledger.sale
(read-msg 'token-id)
(read-msg 'account)
(read-decimal 'amount)
(read-integer 'timeout)
)
data:
token-id: "92496e13-4414-4c58-aceb-0c7d77120af2"
account: "a0fc037522ae0202052775f773e3cf823e3bd7640a12e80694b2dd76"
amount: 1.0
timeout: 100
quote:
price: "1.0"
recipient-guard:
keys:
[ "52d9d996e6cc77f48a1ff1b734224a2ce6cee3af84c3f6e1720047645e9c2c31", ]
recipient: a0fc037522ae0202052775f773e3cf823e3bd7640a12e80694b2dd76
keyPairs:
- public: b63680e667576818b713d5d398ad395610b522fbc53e08afe46a719a0a128fb5
secret: 4242d66fac539660702ce4f9c01a39bb16f1d6b6c7110c6647010cb4dd041dd8
caps:
- name: "marmalade.ledger.SALE"
args: ["92496e13-4414-4c58-aceb-0c7d77120af2", "a0fc037522ae0202052775f773e3cf823e3bd7640a12e80694b2dd76", 1.0, 100]
JSON:
b'{"cmds":[{"hash":"cD5gqQVmRj08xqOdqfKwLLL2eb76_j_eZDdzV4Xdkjg","sigs":[{"sig":"2fb4bbb496271a138c33a4c8b94cf4511c8ad494b5c0cca94a2d1f98a37025e865b1414116fe77e841fbe71c6430e
5da72209123a63e958b992f4e8ba1770103"}],"cmd":"{\\"networkId\\":null,\\"payload\\":{\\"exec\\":{\\"data\\":{\\"amount\\":1.0,\\"token-id\\":\\"92496e13-4414-4c58-aceb-0c7d7712
0af2\\",\\"account\\":\\"a0fc037522ae0202052775f773e3cf823e3bd7640a12e80694b2dd76\\",\\"quote\\":{\\"recipient-guard\\":{\\"keys\\":[\\"52d9d996e6cc77f48a1ff1b734224a2ce6cee3
af84c3f6e1720047645e9c2c31\\"]},\\"price\\":\\"1.0\\",\\"recipient\\":\\"a0fc037522ae0202052775f773e3cf823e3bd7640a12e80694b2dd76\\"},\\"timeout\\":100},\\"code\\":\\"(marmal
ade.ledger.sale (read-msg \'token-id) (read-msg \'account) (read-decimal
\'amount) (read-integer \'timeout)
)\\"}},\\"signers\\":[{\\"pubKey\\":\\"b63680e667576818b713d5d398a
d395610b522fbc53e08afe46a719a0a128fb5\\",\\"clist\\":[{\\"args\\":[\\"92496e13-4414-4c58-aceb-0c7d77120af2\\",\\"a0fc037522ae0202052775f773e3cf823e3bd7640a12e80694b2dd76\\",1
,100],\\"name\\":\\"marmalade.ledger.SALE\\"}]}],\\"meta\\":{\\"creationTime\\":0,\\"ttl\\":0,\\"gasLimit\\":0,\\"chainId\\":\\"\\",\\"gasPrice\\":0,\\"sender\\":\\"\\"},\\"n
once\\":\\"2022-07-20 09:53:05.975872 UTC\\"}"}]}\n'
The following error occurred when I posted the Json data to request.post on 'localhost:8080/api/v1/poll'.
{'cD5gqQVmRj08xqOdqfKwLLL2eb76_j_eZDdzV4Xdkjg': {'gas': 0, 'result': {'status': 'failure', 'error': {'callStack': [], 'type': 'EvalError', 'message': 'Managed capability not installed: (marmalade.ledger.OFFER "92496e13-4414-4c58-aceb-0c7d77120af2" "a0fc037522ae0202052775f773e3cf823e3bd7640a12e80694b2dd76" 1.0 100)', 'info': ''}}, 'reqKey': 'cD5gqQVmRj08xqOdqfKwLLL2eb76_j_eZDdzV4Xdkjg', 'logs': None, 'metaData': None,
'continuation': None, 'txId': None}}
How do I get these to work properly?
P.S. I am Japanese and not an English speaker. I used a translation site to ask this question. Sorry if the description is missing.
My script prints data on separate lines in terminal output, it looks like this:
Name: Paul Surname: Doe Age:34
Name: Paulo Surname: Doeson Age:28
Name: Paulinho Surname: Docsone Age:5
Name: Paulmen Surname: Doee Age:12
Name: Paulchen Surname: Dooe Age:31
And I would like all data to be divided into columns and displayed equally in bars, as below:
Name: Paul Surname: Doe Age:34
Name: Paulo Surname: Doeson Age:28
Name: Paulinho Surname: Docsone Age:5
Name: Paulmen Surname: Doee Age:12
Name: Paulchen Surname: Dooe Age:31
I note that the output can not be buffered or stored. I would like to achieve this in real time while running the script. Are there any tricks to achieve this? Something like specifying the width of a cell in an HTML table?
EDIT
Really EXAMPLE code:
#arr = q(Name: Paul Surname: Doe Age:34, Name: Paulo Surname: Doeson Age:28, Name: Paulinho Surname: Docsone Age:5, Name: Paulmen Surname: Doee Age:12, Name: Paulchen Surname: Dooe Age:31);
foreach (#arr) {
# here should be our trick to creating columns
print $_ # should be print element in columns (without buffering). print now, not after loop end.
}
First thing that comes into my mind are Perl formats. It's built-in and give's you a whole bunch of means for formatting output. Have a look at it.
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.
I'm new on perl and still learning by doing some case. I've some case on parsing a log with perl.
There is a data log :
Physical interface: ge-1/0/2, Unit: 101, Vlan-id: 101, Address: 10.187.132.3/27
Index: 353, SNMP ifIndex: 577, VRRP-Traps: enabled
Interface state: up, Group: 1, State: backup, VRRP Mode: Active
Priority: 190, Advertisement interval: 1, Authentication type: none
Advertisement threshold: 3, Delay threshold: 100, Computed send rate: 0
Preempt: yes, Accept-data mode: yes, VIP count: 1, VIP: 10.187.132.1
Dead timer: 2.715s, Master priority: 200, Master router: 10.187.132.2
Virtual router uptime: 5w5d 12:54
Tracking: disabled
Physical interface: ge-1/0/2, Unit: 102, Vlan-id: 102, Address: 10.187.132.35/27
Index: 354, SNMP ifIndex: 580, VRRP-Traps: enabled
Interface state: up, Group: 2, State: master, VRRP Mode: Active
Priority: 200, Advertisement interval: 1, Authentication type: none
Advertisement threshold: 3, Delay threshold: 100, Computed send rate: 0
Preempt: yes, Accept-data mode: yes, VIP count: 1, VIP: 10.187.132.33
Advertisement Timer: 0.816s, Master router: 10.187.132.35
Virtual router uptime: 5w5d 12:54, Master router uptime: 5w5d 12:54
Virtual Mac: 00:00:5e:00:01:02
Tracking: disabled
Physical interface: ge-1/0/2, Unit: 103, Vlan-id: 103, Address: 10.187.132.67/27
Index: 355, SNMP ifIndex: 581, VRRP-Traps: enabled
Interface state: up, Group: 3, State: backup, VRRP Mode: Active
Priority: 190, Advertisement interval: 1, Authentication type: none
Advertisement threshold: 3, Delay threshold: 100, Computed send rate: 0
Preempt: yes, Accept-data mode: yes, VIP count: 1, VIP: 10.187.132.65
Dead timer: 2.624s, Master priority: 200, Master router: 10.187.132.66
Virtual router uptime: 5w5d 12:54
Tracking: disabled
I curious how we can retrieve some value and store it to array. I've tried grep it but I'm confuse how to take a spesific value.
Expected Value on Array of Hashes:
$VAR1 = {
'interface' => 'ge-1/0/2.101',
'address' => '10.187.132.3/27',
'State' => 'backup'
'Master-router' => '10.187.132.2'
};
$VAR2 = {
'interface' => 'ge-1/0/2.102',
'address' => '10.187.132.35/27',
'State' => 'master'
'Master-router' => '10.187.132.35'
};
$VAR3 = {
'interface' => 'ge-1/0/2.103',
'address' => '10.187.132.67/27',
'State' => 'backup'
'Master-router' => '10.187.132.66'
};
You could use regex to split each paragraph up. Something like this might work:
/((\w|\s|-)+):\s([^,]+)/m
The matching groups would then look something like:
Match 1
1. Physical interface
2. e
3. ge-1/0/2
Match 2
1. Unit
2. t
3. 101
Match 3
1. Vlan-id
2. d
3. 101
As you can see 1. corresponds to a key whereas 3. is the corresponding value. You can store the set of pairs any way you like.
For this to work each attribute in the log would need to be comma-seperated, which the example you have listed isn't. Assuming the example you have listed is correct, you would have to adjust the regex a little to make it work. You can test it online at rubular until it works. If it is comma seperated you might just want to split each paragraph by "," and then split each result on ":".
EDIT:
It seems to me like each line is comma seperated so the methods mentioned above might work perfectly well if you use them on a single line at a time.
To parse the data:
Obtain a section from the file by reading lines into a section while the lines start with whitespace.
Split the sections at the item separators which are either commas or linebreaks
Split each item at the first colon into a key and value
Case-fold the key and store the pair into a hash
A sketch of an implementation:
my #hashes;
while (<>) {
push #hashes, {} if /\A\S/;
for my $item (split /,/) {
my ($k, $v) = split /:/, $item, 2;
$hashes[-1]{fc $k} = $v;
}
}
Then you can extract those pieces of information from the hash which you are interested in.
Since each record is a paragraph, you can have Perl read the file in those chunks by local $/ = ''; (paragraph mode). Then, use a regex to capture each value that you want within that paragraph, pair that value with a hash key, and then push a reference to that hash onto an array to form an array of hashes (AoH):
use strict;
use warnings;
use Data::Dumper;
my #arr;
local $/ = '';
while (<DATA>) {
my %hash;
( $hash{'interface'} ) = /interface:\s+([^,]+)/;
( $hash{'address'} ) = /Address:\s+(\S+)/;
( $hash{'State'} ) = /State:\s+([^,]+)/;
( $hash{'Master-router'} ) = /Master router:\s+(\S+)/;
push #arr, \%hash;
}
print Dumper \#arr;
__DATA__
Physical interface: ge-1/0/2, Unit: 101, Vlan-id: 101, Address: 10.187.132.3/27
Index: 353, SNMP ifIndex: 577, VRRP-Traps: enabled
Interface state: up, Group: 1, State: backup, VRRP Mode: Active
Priority: 190, Advertisement interval: 1, Authentication type: none
Advertisement threshold: 3, Delay threshold: 100, Computed send rate: 0
Preempt: yes, Accept-data mode: yes, VIP count: 1, VIP: 10.187.132.1
Dead timer: 2.715s, Master priority: 200, Master router: 10.187.132.2
Virtual router uptime: 5w5d 12:54
Tracking: disabled
Physical interface: ge-1/0/2, Unit: 102, Vlan-id: 102, Address: 10.187.132.35/27
Index: 354, SNMP ifIndex: 580, VRRP-Traps: enabled
Interface state: up, Group: 2, State: master, VRRP Mode: Active
Priority: 200, Advertisement interval: 1, Authentication type: none
Advertisement threshold: 3, Delay threshold: 100, Computed send rate: 0
Preempt: yes, Accept-data mode: yes, VIP count: 1, VIP: 10.187.132.33
Advertisement Timer: 0.816s, Master router: 10.187.132.35
Virtual router uptime: 5w5d 12:54, Master router uptime: 5w5d 12:54
Virtual Mac: 00:00:5e:00:01:02
Tracking: disabled
Physical interface: ge-1/0/2, Unit: 103, Vlan-id: 103, Address: 10.187.132.67/27
Index: 355, SNMP ifIndex: 581, VRRP-Traps: enabled
Interface state: up, Group: 3, State: backup, VRRP Mode: Active
Priority: 190, Advertisement interval: 1, Authentication type: none
Advertisement threshold: 3, Delay threshold: 100, Computed send rate: 0
Preempt: yes, Accept-data mode: yes, VIP count: 1, VIP: 10.187.132.65
Dead timer: 2.624s, Master priority: 200, Master router: 10.187.132.66
Virtual router uptime: 5w5d 12:54
Tracking: disabled
Output:
$VAR1 = [
{
'Master-router' => '10.187.132.2',
'interface' => 'ge-1/0/2',
'address' => '10.187.132.3/27',
'State' => 'backup'
},
{
'Master-router' => '10.187.132.35',
'interface' => 'ge-1/0/2',
'address' => '10.187.132.35/27',
'State' => 'master'
},
{
'Master-router' => '10.187.132.66',
'interface' => 'ge-1/0/2',
'address' => '10.187.132.67/27',
'State' => 'backup'
}
];
Hope this helps!
in user_history collection
user_name: john
eat : [{food:'apple', timestamp:123}, {food:'cheese', timestamp:80}]
user_name: paul
eat : [{food:'melon', timestamp:125}, {food:'bread', timestamp:60}]
user_name: mattew
eat : [{food:'water', timestamp:90}, {food:'pizza', timestamp:91}]
I need to get food which has timestamp over 100
my code:
db.user_history.find({"eat.timestamp":{$gte:100}},{"eat.food":1})
result:
{'_id': ObjectId('......'),'eat':[{food:'apple'},{food:'cheeza'}]},
{'_id': ObjectId('......'),'eat':[{food:'melon'},{food:'bread'}]}
result I want to get:
{'_id': ObjectId('......'), 'eat':{food:apple}},
{'_id': ObjectId('......'), 'eat':{food:melon}}
how could I get this?
I dont think its possible,see the ticket: https://jira.mongodb.org/browse/SERVER-828.
Looks like this question is already asked