Get people from Highrise by Highrise API, which have tags: tag1 OR tag2 - highrise

I mean I need info of people from Highrise with tags: tag1 OR tag2
"OR" is very important.
For example:
GET people.xml?tag_id=2123123 //how i get people w tag1
GET people.xml?tag_id=5656622 //how i get people w tag2
but there are people, who have both tags and I don't what to duplicate them after merge to xml file.

Related

Filter list in ansible with a string (from variable)

I have a list in ansible for which I want to apply a filter with variable (string).
Here is the list example
ok: [localhost] => {
"list1": [
"aXYZb",
"bbbb",
"ccccXYZdsasd"
]
}
variable is a match with XYZ, and I want to filter the list with it to get
aXYZb
ccccXYZdsasd
I tried with union, but this works only in case string in the list is exact as the variable (it works for XYZ, not for aXYZb).
I'm also trying to filter it with regexp that use this variable for search, but something is not right. Here is what I tried:
- name: Filter a list with variable
set_fact:
list2: "{{ list1 | regex_search('variable1') }}"
loop: "{{ list1 }}"
loop_control:
loop_var: item5
or the other way:
list2: "{{ list1 | map('regex_search',some_regular_expression_with_variable) | list }}"
This is not getting me expected result.
Does anyone knows how to achieve this, either with union, regex or maybe some other filtering solution)?
Thanks.
++++
Here is an answer for Vladimir
Hi, I figured out why it's not working in my case. The thing is that for my var1 (which is I.E. abcdef), it cannot find the match for it because in the list I have strings like abcXYZdef. That is why union didn't work and also select from Vladimir. I believe we need to add REGEXP that checks only for particular characters (I know exactly which one). The REGEXP I used for extracting XYZ (in the task before this one) where:
'regex_replace', '(?:^.*(?=.{7})|\\d+)', '')
and/or
'regex_search', '\\D(?=.{0,6}$)'
so I guess I need to add one of these, but the the question is where and how to combine it in this select? Maybe something like this:
list2: "{{ list1| select('search', REGEXP) | select ('search, var1) }}"
+++
Given the list1 and var1
list1: [aXYZb, bbbb, ccccXYZdsasd]
var1: XYZ
Q: "The variable is a match with XYZ. Filter the list with it to get list2."
list2: [aXYZb, ccccXYZdsasd]
A: Use the test search. For example,
list2: "{{ list1|select('search', var1) }}"
Example of a complete playbook
- hosts: localhost
vars:
list1: [aXYZb, bbbb, ccccXYZdsasd]
var1: XYZ
list2: "{{ list1|select('search', var1) }}"
tasks:
- debug:
var: list2

Processing a List in a Dictionary

I am trying to process a dictionary of tags to produce a command line that will be passed to a python program that will apply tags to an object. Tags can be either single cardinality (i.e. the "key" can appear only once on the tagged element) or multi-cardinality (i.e. the "key" can appear multiple times on the element). Single Cardinality tagging is fine, my problem is with multi-cardinality.
The dictionary in the ansible host_vars file would be:
multi_tags:
multi_tag1: value1
multi_tag2: mvalue1
multi_tag2: mvalue2
multi_tag3: value3
But ansible will replace "multi_tag2" with "mvalue2" only because you can't have 2 variables with the same name. Therefore the dictionary actually looks like:
multi_tags:
multi_tag1: value1
multi_tag2: ["mvalue1", "mvalue2"]
multi_tag3: value3
At the end of this I need to produce the following list:
multi_tag1:value1, multi_tag2:mvalue1, multi_tag2:mvalue2, multi_tag3:value3
So far i've been able to get multi_tag1:value1, multi_tag2:[mvalue1, mvalue2], multi_tag3:value3, and I can detect that mutli_tag2 is a list, but I cannot figure out how to pull "multi_tag2", separate from the multi_tags dict and then expand that list into it's individual key:value components?
NOTE: "multi_tag2" may be any name and there may be any number of lists like this in the dictionary. The challenge is in reading the dictionary, finding all of the list keys and spinning each list key into its own expanded key:value set.
I can detect and capture list name keys with:
- name: Caputre Lists for Processing
vars:
multilist: []
set_fact:
multilist: "{{ multilist + [item] }}"
with_items: '{{ multi_tags.keys() }}'
when: ( multi_tags[item] is defined ) and ( multi_tags[item] | type_debug == "list" )
But once I have the "list of lists" I don't know how to then spin that to generate/expand each key:value pair in each list to create the final consolidated group of key:value pairs.
This does not need to be done in one step, i'm happy to add the expanded key:value pairs to additional set-facts and then combine the single facts with the "list" facts to create the final key:value list if that's needed.
I've been racking my brain over this for hours now. Any advice would be helpful!
Create a list of products first. The challenge is converting a string to a list where this string is a single item. Simply item|list won't work because a string is iterable. Hence, it must be closed in brackets [item]. This would create a nested list, if the item is already a list, which must be flattened, e.g.
- set_fact:
mtl: "{{ mtl|d([]) + [item.key]|product([item.value]|flatten) }}"
loop: "{{ multi_tags|dict2items }}"
gives
mtl:
- - multi_tag1
- value1
- - multi_tag2
- mvalue1
- - multi_tag2
- mvalue2
- - multi_tag3
- value3
Then, join the items, e.g.
- debug:
msg: "{{ mtl|map('join', ':')|join(', ') }}"
gives
msg: multi_tag1:value1, multi_tag2:mvalue1, multi_tag2:mvalue2, multi_tag3:value3

How to loop n times, one level per loop in an xml file

This is something that I feel should be easy, but after many hours I still can't figure it out. I tried googling it but it would seem the only way my brain wants to ask the question is in 3 lines of explanation, which doesn't really work with google. Feel free to edit if you have a better way to phrase it.
I have an xml file, say this:
<tag1>
<tag2>
<tag3>
...
</tag3>
</tag2>
</tag1>
The document may have many tag1, tag2 and tag3 per parent.
Using pugixml for c++, I want to perform an action on the selected node. Here's pseudo-code of what I'd like to accomplish, but in a way that I know is wrong and not really doable.
for(pugi::xml_node tag1 : doc->child("tag1").children()){
//Do something with tag1
for(pugi::xml_node tag2 : doc->child("tag1").child("tag2").children()){
//Do something with tag2
for(pugi::xml_node tag3 : doc->child("tag1").child("tag2").child("tag3").children()){
//Do something with tag3
}
}
}
Just looking at this, it's pretty simple to find what won't work... I need to be able to interact with the doc.child().child().child().child()..... inside the loop. Having to add the .child() for each iteration prevents me from doing something of the recursive style, such as:
void loopXNestedTimes(int n){
if(n==0) return;
// Do my stuff
loopXNestedTimes(n-1);
}
Any clue how I'd go about it? I'm using Qt and c++, but am still learning both, so there might be language features I'm missing that allow this.
Use tag1 to get tag2 elements (and not doc) and use tag2 to get tag3 elements, which I think is the crucial point that you're missing.
Your code snippet should look like this:
for (pugi::xml_node tag1 : doc->child("tag1").children()){
//Do something with tag1
for (pugi::xml_node tag2 : tag1.child("tag2").children()){
//Do something with tag2
for (pugi::xml_node tag3 : tag2.child("tag3").children()){
//Do something with tag3
}
}
}

XML find and delete all text in doc not within a specified tag

I have an XML doc which is massive - a short example is below to illustrate formatting. What I want to do is find all the text in the doc which is not within a tag and delete it - so I am left with just a list of the data...
So here is the original:
51.639973121-2.161205923
112.0
<time>2017-02-19T11:26:45Z</time>
51.639902964-2.161258059
111.6
<time>2017-02-19T11:26:46Z</time>
51.639834484-2.161310529
111.6
<time>2017-02-19T11:26:47Z</time>
51.639765501-2.161366101
111.6
<time>2017-02-19T11:26:48Z</time>
51.639697859-2.161426451
111.8
<time>2017-02-19T11:26:49Z</time>
And once formatted - it will become:
<time>2017-02-19T11:26:45Z</time>
<time>2017-02-19T11:26:46Z</time>
<time>2017-02-19T11:26:47Z</time>
<time>2017-02-19T11:26:48Z</time>
<time>2017-02-19T11:26:49Z</time>
How is this possible???
The following expression will select all text but time tags:
^(?!<time>[^<]+<\/time>).*\R
It works only if the tags are on a new line, like in you example input.
See the demo

pig - parsing string with regex

I'm stuck on string parsing in Pig.
I have looked at the documentation around regex_extract and regex_extract_all and hoped to use one of those functions.
I have file '/logs/test.log':
cat '/logs/test.log'
user=242562&friend=6226&friend=93856&age=35&friend=35900
I want to extract the friend tags from the url, and in this case, I have 3 identical tags. regex_extract seems to only work for the first instance, which is what I expected, and for regex_extract_all, it seems like I have know the whole string pattern, which changes on each row of the source file.
It looked ok with regex_extract, but this option only gives me the first one.
[root#test]# pig -x local
A = LOAD './test.log';
B = FOREACH A GENERATE REGEX_EXTRACT($0, 'friend=([0-9]*)',1);
dump B;
(6226)
The examples I see for regex_extract_all show regex where you seek out all the tags:
B = FOREACH A GENERATE FLATTEN(REGEX_EXTRACT_ALL($0, 'user=([0-9]+?)&friend=([0-9]+?)&friend=([0-9]+?)&.+?'));
dump B;
(242562,6226,93856)
That seems to work, but I really just want to extract the friends - (6226,93856,35900). I also have cases where there might be more-than or less-than 3 friends per user.
Any ideas?
Also looking at using something like FLATTEN(TOKENIZE($0,'&')) and then somehow only filtering on the SUBSTRING($0,0,INDEXOF($0,'=')) == 'friend' or something like that, but wanted to see if anyone knew a good regex approach.
This can be achieved by simple string manipulations:
inputs = LOAD 'input' AS (line: chararray);
tokenized = FOREACH inputs GENERATE FLATTEN(TOKENIZE(line, '&')) AS parameter;
filtered = FILTER tokenized BY INDEXOF(parameter, 'friend=') != -1;
result = FOREACH filtered GENERATE SUBSTRING(parameter, 7, (int)SIZE(parameter)) AS friend_number;
DESCRIBE tokenized;
DUMP tokenized;
DESCRIBE filtered;
DUMP filtered;
DESCRIBE result;
DUMP result;
result:
tokenized: {parameter: chararray}
(user=242562)
(friend=6226)
(friend=93856)
(age=35)
(friend=35900)
filtered: {parameter: chararray}
(friend=6226)
(friend=93856)
(friend=35900)
result: {friend_number: chararray}
(6226)
(93856)
(35900)
Try this:
a = LOAD '/logs/test.log' USING PigStorage('&') as (f1, f2, f3, f4, f5);
b = FOREACH a GENERATE REGEX_EXTRACT(f2,'friend=([0-9]*)', 1),
REGEX_EXTRACT(f3,'friend=([0-9]*)', 1),
REGEX_EXTRACT(f5,'friend=([0-9]*)', 1);
DUMP b;