Need IronPython Code to output Filtering Scheme in Spotfire - filtering

I want to print the "name" of the filtering scheme that is specific for each page of my dashboard.
For instance, page 1 of the dashboard may have a filtering scheme named "Filter Scheme 1" and page 2 has "Filter Scheme 2". I have code that outputs ALL of the Filtering Schemes but I cannot figure out how to associate a specific scheme to the page it sits on.
for pg in Document.Pages:
print pg.Title # the page name
myPanel = pg.FilterPanel
print myPanel.Title # output is the word: Filters
# THIS IS WHERE I WOULD WANT THE FILTERING SCHEME NAME TO APPEAR
print myPanel.Visible # output: True
print myPanel.Context # output: Spotfire.Dxp.Application.Filters.FilterPanel
print myPanel.TypeId # TypeIdentifier:Spotfire.FilterPanel
print myPanel.FilteringSchemeReference
for i in range(myPanel.TableGroups.Count):
for gcObj in myPanel.TableGroups[i].FilterCollectionReference:
myFilter= myPanel.TableGroups[i].GetFilter(gcObj.Name)
if myFilter.Visible:
szCanSee = ' <Visible>'
else:
szCanSee = ' <Hidden>'
print myFilter.FilterReference.ToString() + szCanSee

You are looking for the DataFilteringSelection class which you can find in the api here: http://stn.spotfire.com/dxp/html/AllMembers_T_Spotfire_Dxp_Data_DataFilteringSelection.htm
I've trimmed down your code to just the section asked about as you may need to revise the rest a little as 'myPanel' will no longer be a FilterPanel.
for pg in Document.Pages:
print pg.Title # the page name
myPanel = pg.ActiveFilteringSelectionReference
print myPanel.Name # output is the filter name
To test this I created a file with 4 pages: Introduction, Solution 1, Solution 2 and Page; and 2 filters: Filtering scheme (1) and Filtering scheme (2). Everything used Filtering scheme (1) except Solution 2 which used Filtering scheme (2).
Here is my output:
> Introduction
> Filtering scheme (1)
> Solution 1
> Filtering scheme (1)
> Solution 2
> Filtering scheme (2)
> Page
> Filtering scheme (1)

Related

Why doesn't GitHub display results for package search in code tab?

I want to search on GitHub: "#angular-architects/ddd" but I got no results on Code tab:
It is obvious that there are many results, and this is one of them:
https://github.com/mikezks/20220920/blob/main/package.json#L53
Did I use the search wrong, or is it a known bug on GitHub?
Because, per the search docs:
You can't use the following wildcard characters as part of your search query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ] #. The search will simply ignore these symbols.
The forward slash and at sign are ignored, and there are no hits for angular-architectsddd. If you search for the scope and package name separately instead, you get some results: https://github.com/search?q=%22angular-architects%22+ddd&type=Code (currently 304 hits)
Note if you're looking for usages of this package in other NPM-based repositories, you can scope the search to package files: https://github.com/search?q=%22angular-architects%22+ddd+filename%3Apackage.json&type=Code
(currently 204 hits)

Search for a match, after the match is found take the number after the match and add 4 to it, it is posible in perl?

I am a beginer in perl and I need to modify a txt file by keeping all the previous data in it and only modify the file by adding 4 to every number related to a specific tag (< COMPRESSED-SIZE >). The file have many lines and tags and looks like below, I need to find all the < COMPRESSED-SIZE > tags and add 4 to the number specified near the tag:
< SOURCE-START-ADDRESS >01< /SOURCE-START-ADDRESS >
< COMPRESSED-SIZE >132219< /COMPRESSED-SIZE >
< UNCOMPRESSED-SIZE >229376< /UNCOMPRESSED-SIZE >
So I guess I need to do something like: search for the keyword(match) and store the number 132219 in a variable and add the second number (4) to it, replace the result 132219 with 132223, the rest of the file must remain unchanged, only the numbers related to this tag must change. I cannot search for the number instead of the tag because the number could change while the tag will remain always the same. I also need to find all the tags with this name and replace the numbers near them by adding 4 to them. I already have the code for finding something after a keyword, because I needed to search also for another tag, but this script does something else, adds a number in front of a keyword. I think I could use this code for what i need, but I do not know how to make the calculation and keep the rest of the file intact or if it is posible in perl.
while (my $row = <$inputFileHandler>)
{
if(index($row,$Data_Pattern) != -1){
my $extract = substr($row, index($row,$Data_Pattern) + length($Data_Pattern), length($row));
my $counter_insert = sprintf "%08d", $counter;
my $spaces = " " x index($row,$Data_Pattern);
$data_to_send ="what i need to add" . $extract;
print {$outs} $spaces . $Data_Pattern . $data_to_send;
$counter = $counter + 1;
}
else
{
print {$outs} $row;
next;
}
}
Maybe you could help me with a block of code for my needs, $Data_Pattern is the match. Thank you very much!
This is a classic one-liner Perl task. Basically you would do something like
$ perl -i.bak -pe's/^< COMPRESSED-SIZE >\K(\d+)/$1 + 4/e' yourfile.txt
Which will in essence copy and replace your file with a new, edited file. This can be very dangerous, especially if you are a Perl newbie. The -i switch is here used with the .bak extension which saves a backup in yourfile.txt.bak. This does not make this operation safe, however, as running the command twice will overwrite the backup.
It is advisable to make a separate backup of the target file before using this command.
-i.bak edit "in-place", the file is overwritten, a backup of the original is created with extension .bak.
-p argument is treated as a file name, which is read, and printed back.
s/ // the substitution operator, which is applied to all lines of the file.
^ inside the regex looks for beginning of line.
\K keep the match that is to the left.
(\d+) capture () 1 or more digits \d+ and store them in $1
/e treat the right hand side of the substitution operator as an expression and use the result as the replacement string. In this case it will increase your number and return the sum.
The long version of this command is
while (<>) {
s/^< COMPRESSED-SIZE >\K(\d+)/$1 + 4/e
}
Which can be placed in a file and run with the -i switch.

perl - Net::Whois::Raw not stripping whois disclaimers

I'm trying to write a Perl script that displays whois information for various servers. The whois servers, however return all types of disclaimers and other text within the replies. Net::Whois::Raw does have options to strip these disclaimers, but I can't get it to work.
Here's how I tried it:
#!/usr/bin/perl
use strict;
use warnings;
my $OMIT_MSG = 2;
my $CHECK_FAIL = 2;
my $USE_CNAMES = 1;
use Net::Whois::Raw qw(whois $OMIT_MSG $CHECK_FAIL $USE_CNAMES);
die "Incorrect arguments\n" unless (#ARGV);
for (my $i = 0; $i < #ARGV; $i++)
{
print "\nWhois info : " . $ARGV[$i] . "\n\n\n";
eval
{
my $whoisinfo = whois($ARGV[$i]);
print $whoisinfo;
};
if ($#)
{
print "Error while retrieving whois details.";
}
print "\n";
}
I'm sorry if this is probably a dumb question, but can anyone point out what I'm doing wrong here?
Thanks in advance.
May not be exactly what your looking for, but I'm currently doing some work parsing the RAW whois database files (Which you can download in their complete form, from ftp://ftp.ripe.net/ in the 'ripe/database' directory)
Like you I wanted to filter out the disclaimers, but I have different needs, mostly the fact that I'm preprocessing the files before feeding them to a database script to be inserted into a database.
Anyway, I'm using the following command line to pre filter the plain text database files:
cat ripe.db.as-block | grep -v '^\s*#' | grep -v '^remarks:\s*\*'
I guess following from that, you could pipe the output into your perl script, or write it to a new file using the > operator, then process that new file with your perl script.
This will also work on windows using the GnuWin32 toolset from sourceforge, which gives you windows compatible command line binaries that mirror their linux counter parts, but you will need to tweak the quotes, mostly from ' to "
as an example of what it strips:
this....
#
# The contents of this file are subject to
# RIPE Database Terms and Conditions
#
# http://www.ripe.net/db/support/db-terms-conditions.pdf
#
as-block: AS1877 - AS1901
descr: RIPE NCC ASN block
remarks: These AS Numbers are further assigned to network
remarks: operators in the RIPE NCC service region. AS
remarks: assignment policy is documented in:
remarks: <http://www.ripe.net/ripe/docs/asn-assignment.html>
remarks: RIPE NCC members can request AS Numbers using the
remarks: form available in the LIR Portal or at:
remarks: <http://www.ripe.net/ripe/docs/asnrequestform.html>
org: ORG-NCC1-RIPE
admin-c: DUMY-RIPE
tech-c: DUMY-RIPE
mnt-by: RIPE-DBM-MNT
mnt-lower: RIPE-NCC-HM-MNT
changed: unread#ripe.net 20000101
source: RIPE
remarks: ****************************
remarks: * THIS OBJECT IS MODIFIED
remarks: * Please note that all data that is generally regarded as personal
remarks: * data has been removed from this object.
remarks: * To view the original object, please query the RIPE Database at:
remarks: * http://www.ripe.net/whois
remarks: ****************************
Ends up as this:
as-block: AS1877 - AS1901
descr: RIPE NCC ASN block
remarks: These AS Numbers are further assigned to network
remarks: operators in the RIPE NCC service region. AS
remarks: assignment policy is documented in:
remarks: <http://www.ripe.net/ripe/docs/asn-assignment.html>
remarks: RIPE NCC members can request AS Numbers using the
remarks: form available in the LIR Portal or at:
remarks: <http://www.ripe.net/ripe/docs/asnrequestform.html>
org: ORG-NCC1-RIPE
admin-c: DUMY-RIPE
tech-c: DUMY-RIPE
mnt-by: RIPE-DBM-MNT
mnt-lower: RIPE-NCC-HM-MNT
changed: unread#ripe.net 20000101
source: RIPE
The trick to the filtering is using a reverse grep that's the '-v' in the command line, what it essentially says is let every line pass EXCEPT for those that match the pattern, as opposed to it's normal invocation, where it's used to select wanted lines.
If you have extra criteria you want to filter out before processing, then all you need to do is just pipe more inverted grep commands onto the end using the pipe character.
I may be completely wrong, because I don't use Perl very often, and don't really understand the mechanics of use, but since $OMIT_MSGS is being exported from the module, I would have thought you don't want to pre-declare it with my, you want to assign to it after the module is loaded (but before you make any function calls):
use Net::Whois::Raw qw(whois $OMIT_MSG $CHECK_FAIL $USE_CNAMES);
$OMIT_MSG = 2;
$CHECK_FAIL = 2;
$USE_CNAMES = 1;
use Net::Whois::Raw;
$Net::Whois::Raw::OMIT_MSG = 1;
my $domain_info = whois('perl.com');
This works. It strips for Perl.com and Funet.fi - domains used as examples in documentation. But, as documentation says, it will not work for all domains.

Perl: pattern match a string and then print next line/lines

I am using Net::Whois::Raw to query a list of domains from a text file and then parse through this to output relevant information for each domain.
It was all going well until I hit Nominet results as the information I require is never on the same line as that which I am pattern matching.
For instance:
Name servers:
ns.mistral.co.uk 195.184.229.229
So what I need to do is pattern match for "Name servers:" and then display the next line or lines but I just can't manage it.
I have read through all of the answers on here but they either don't seem to work in my case or confuse me even further as I am a simple bear.
The code I am using is as follows:
while ($record = <DOMAINS>) {
$domaininfo = whois($record);
if ($domaininfo=~ m/Name servers:(.*?)\n/){
print "Nameserver: $1\n";
}
}
I have tried an example of Stackoverflow where
<DOMAINS>;
will take the next line but this didn't work for me and I assume it is because we have already read the contents of this into $domaininfo.
EDIT: Forgot to say thanks!
how rude.
So, the $domaininfo string contains your domain?
What you probably need is the m parameter at the end of your regular expression. This treats your string as a multilined string (which is what it is). Then, you can match on the \n character. This works for me:
my $domaininfo =<<DATA;
Name servers:
ns.mistral.co.uk 195.184.229.229
DATA
$domaininfo =~ m/Name servers:\n(\S+)\s+(\S+)/m;
print "Server name = $1\n";
print "IP Address = $2\n";
Now, I can match the \n at the end of the Name servers: line and capture the name and IP address which is on the next line.
This might have to be munged a bit to get it to work in your situation.
This is half a question and perhaps half an answer (the question's in here as I am not yet allowed to write comments...). Okay, here we go:
Name servers:
ns.mistral.co.uk 195.184.229.229
Is this what an entry in the file you're parsing looks like? What will follow immediately afterwards - more domain names and IP addresses? And will there be blank lines in between?
Anyway, I think your problem may (in part?) be related to your reading the file line by line. Once you get to the IP address line, the info about 'Name servers:' having been present will be gone. Multiline matching will not help if you're looking at your file line by line. Thus I'd recommend switching to paragraph mode:
{
local $/ = ''; # one paragraph instead of one line constitutes a record
while ($record = <DOMAINS>) {
# $record will now contain all consecutive lines that were NOT separated
# by blank lines; once there are >= 1 blank lines $record will have a
# new value
# do stuff, e.g. pattern matching
}
}
But then you said
I have tried an example of Stackoverflow where
<DOMAINS>;
will take the next line but this didn't work for me and I assume it is because we have already read the contents of this into $domaininfo.
so maybe you've already tried what I have just suggested? An alternative would be to just add another variable ($indicator or whatever) which you'll set to 1 once 'Name servers:' has been read, and as long as it's equal to 1 all following lines will be treated as containing the data you need. Whether this is feasible, however, depends on you always knowing what else your data file contains.
I hope something in here has been helpful to you. If there are any questions, please ask :)

Reading custom values in Ebay RSS feed (XML::RSS module)

I've spent entirely way too long trying to figure this out. I'm using XML: RSS and Perl to read / parse an Ebay RSS feed. Within the <item></item> area, I see these entries:
<rx:BuyItNowPrice xmlns:rx="urn:ebay:apis:eBLBaseComponents">1395</rx:BuyItNowPrice>
<rx:CurrentPrice xmlns:rx="urn:ebay:apis:eBLBaseComponents">1255</rx:CurrentPrice>
However, I can't figure out how to grab the details during the loop. I wrote a regex to grab them:
#current_price = $item =~ m/\<rx\:CurrentPrice.*\>(\d+)\<\/rx\:CurrentPrice\>/g;
Which works if you place the above 'CurrentPrice' entry into a standalone string, but not while the script is reading through the RSS feed.
I can grab most of the information I want out of the item->description area (# bids, auction end time, BIN price, thumbnail image, etc.), but it would be nicer if I could grab the info from the feed without me having to deal with grabbing all that information manually.
How to grab custom fields from an RSS feed (short of writing regexes to parse the entire feed w/o a module)?
Here's the code I'm working with:
$my_limit = 0;
use LWP::Simple;
use XML::RSS;
$rss = XML::RSS->new();
$data = get( $mylink );
$rss->parse( $data );
$channel = $rss->{channel};
$NumItems = 0;
foreach $item (#{$rss->{'items'}}) {
if($NumItems > $my_limit){
last;
}
#current_price = $item =~ m/\<rx\:CurrentPrice.*\>(\d+)\<\/rx\:CurrentPrice\>/g;
print "$current_price[0]";
}
If you have the rss/xml document and want specific data you could use XPATH:
Perl CPAN XPATH
XPath Introduction
What is the way in which "it doesn't work" from an RSS feed? Do you mean no matches when there should be matches? Or one match where there should be several matches?
One thing that jumps out at me about your regular expression is that you use .*, which can sometimes be greedier than you want. That is, if $item contained the expression
<rx:BuyItNowPrice xmlns:rx="urn:...nts">1395</rx:BuyItNowPrice>
<rx:CurrentPrice xmlns:rx="urn:...nts">1255</rx:CurrentPrice>
<rx:BuyItNowPrice xmlns:rx="urn:...nts">1395</rx:BuyItNowPrice>
<rx:SomeMoreStuff xmlns:rx="urn:...nts">zzz</rx:BuyItNowPrice>
<rx:CurrentPrice xmlns:rx="urn:...nts">1255</rx:CurrentPrice>
then the first part of your regular expression (\<rx\:CurrentPrice.*\>) will wind up matching everything on lines 2, 3, and 4, plus the first part of line 5 (up to the >). Instead, you might want to use the regular expression1
m/\<rx:CurrentPrice[^>]*>(\d+)\<\/rx:CurrentPrice\>/
which will only match up to the closing </rx:CurrentPrice> tag after a single instance of an opening <rx:CurrentPrice> tag.
1 The other obvious answer is that you really don't want to use a regular expression at all, that regular expressions are inferior tools for parsing XML compared to customized parsing modules, and that all the special cases you will have to deal with using regular expressions will eventually render you unconscious from having repeatedly beaten your head against your desk. See Salgar's answer, for example.