Regex to retrieve value from table - regex

We have users replying on an e-mail and we need to retrieve the date mentioned in the table.
For the moment I made the following code to do that for us:
$temp = ($Mail.Body.Text -creplace '(?m)^\s*\r?\n' -split "User name`r`n`tLogon name`r`n`tEnd date`r`n`tNew end date")[1]
(($temp -split "`r`n`t")[3] -split "`r`n")[0]
As you can see, it's quite long and very much relying on -split. Is there an easier way to retrieve the date? With Select-String or a Regex or something?
The table format in the e-mail is always the same, as the users needs to fill in the date in the HTML table. So we need to be able to read that table. In the example below the result would be 01/08/2016.
Example of such an e-mail:
Date added below
From: GBR Service Desk
Sent: Wendesday 29 juni 2016 7:00
To: Bond, James (London) GBR
Subject: REMINDER Expiring user:
Importance: High
Dear James
This is a reminder e-mail to inform you that the following Windows user account will expire soon:
User name
Logon name
End date
New end date
Smith, Jobn (Manchester) GBR
jent
01/07/2016
01/08/2016
Because you are registered as the manager of this user, we would like to ask you to verify if this account is still nee
ded after its end date. More text...
Yours sincerely
Thank you for your help.

You could use Select-String to find date-like patterns and select the last one:
$EndDate = ($Mail.Body.Text |Select-String '\d{2}/\d{2}/\d{4}' -AllMatches).Matches[-1].Value

Related

IBM Cognos Analytics - Multiple rows into single row

I am using Cognos Analytics 11.0.4 and I am trying to concatenate multiple rows into a single row.
ID Department
123456 Front Office
123456 Reception
123456 IT
What I would like to do:
ID Department
123456 Front Office|Reception|IT
I tried creating a repeater with a new query, adding ID, Department to it, then setting up a master detail relationship between query1 ID and query2 ID, finally adding a text item with the | character.
When running the report I only get the below.
ID
123456
Anyone know what might be going wrong? It is like the repeater and | in query2 are ignored for the final output.
I figured it out, as simple as it was, it took me a while to realise.
Exporting my report with the 'Run Excel Data' option couldn't handle the row operations required by the Repeater object.
Switching to 'Run Excel' resolved the issue.

Using RLS on secondary field to UserPrincipalName

So if I have three users: Tom, Dick, and Harry, and they have been assigned group colors. I'd like them to be able to see everyone's data in their own group.
Name Group Email
----- ----- -----
Tom Green t#acme.com
Dick Red d#acme.com
Harry Red h#acme.com
So I create a measure
RLS_SecurityKey = CALCULATE(FIRSTNONBLANK(People[Group],People[Group]),
USERPRINCIPALNAME() = People[Email])
And when I log in as the separate users, I can see in a card visual that I'm getting the expected group.
But when I set row level security on the People table, [Group] = [RLS_SecurityKey], I only get back the one row that matches the email address and not the user that matches his Group.
It seems I'm missing something fairly apparent, but I can't see it. How can I get back all the rows relating to Group and not the email?
Yep, it was pretty straight forward.
RLS_SecurityKey = CALCULATE(FIRSTNONBLANK(People[Group],People[Group]),
FILTER(ALL('PEOPLE'),USERPRINCIPALNAME() = People[Email]))
I adjusted the filter expression and made it a proper filter over the whole table.

Using regex within a case statement to pull out dynamic content

I am working with URL strings that have the following structure:
URL
page/wa/seattle
page/ca/sandiego
page/mi/detroit
I essentially was wondering if it is possible to use Regex in combination with a case statement to create the following:
Page State City
page wa seattle
page ca sandiego
page mi detroit
I currently have the code written that pulls out which pages are state pages and which pages are city pages.
CASE WHEN (regexp_instr(HITSPAGEPAGEPATH::text, '^/page/[a-z]{2}/[a-z]+'::
CHARACTER VARYING::text))
THEN (regexp_instr(HITSPAGEPAGEPATH::text,
'^/page/[a-z]{2}/[a-z]+'::CHARACTER VARYING::text))
ELSE NULL
END AS city
The part that I can't figure out is what I can put after the "then' to have just the city or state displayed. This is for postgres sql on Amazon redshift using sql workbench if that helps with what syntax to answer in.
No need for a regex, just split the string in 3 elements (separated by /) and use each element as a column:
select elements[1] as page,
elements[2] as state,
elements[3] as city
from (
select string_to_array(hitspagepagepath, '/') as elements
from the_table
) t
order by page;
select hitspagepagepath, split_part(hitspagepagepath,'/',2) as root_url,
split_part(hitspagepagepath,'/',3) as State,
split_part(hitspagepagepath,'/',4) as City
from Table

How to add Region / State in opencart checkout?

Please suggest a way to add an extra Region /State in checkout which is not there in Opencart default .
You can add region for any country from admin panel also.
settings->localisation->zone
The region/states are in the oc_zone table. You can add extra entries into this table but make sure you get the right country code and put that into the record too.
The country codes are in the oc_country table.
So, for example, if you wanted to add a new Region called "The People's Republic of Cleckheaton" to the United Kingdom, first look up the country code for the United Kingdom in oc_country. The code is 222.
Then you can add the new zone to oc_zone with something like the following:
INSERT INTO `oc_zone` (`zone_id`, `country_id`, `name`, `code`, `status`) VALUES (NULL, '222', 'The Peoples Republic of Cleckheaton', 'PRC', '1');
Finally there's another slight issue. Opencart actually caches all the country and zone data so if you add a new field like this it probably won't show up because the old data will be cached.
You should probably be able to fix this by clearing your browser's cache but failing that update the following line in \catalog\model\localisation\zone.php Warning: This is in opencart 1.5.6 but should be similar in 2.0
$zone_data = $this->cache->get('zone.' . (int)$country_id);
to
zone_data = false;
Once you've confirmed it's working ok update that line back to it's original content.

Short record query with Django ORM

Can I modify the following query to make it more concise way using Django ORM?
queryset.filter((Q(from_date__lte=from_date) & \
Q(to_date__gt=from_date)) | \
(Q(from_date__lte=to_date) &
Q(to_date__gt=to_date)))
Here are some examples:
"from_date": "2014-05-11 08:00:00",
"to_date": "2014-05-11 10:00:00",
"from_date": "2014-05-12 12:00:00",
"to_date": "2014-05-12 15:00:00",
These are the dates in the database
If you submit
fromDate=2014-05-11 08:00:00
toDate=2014-05-11 13:00:00
should give me only the first date
"from_date": "2014-05-11 08:00:00",
"to_date": "2014-05-11 10:00:00",
Here again, should give me only the first result
fromDate=2014-05-11 09:00:00
toDate=2014-05-11 13:00:00
If I submit the following date
fromDate=2014-05-11 07:00:00
toDate=2014-05-11 09:00:00
Again, only the first result should be taken
If you do so you can get both results
fromDate=2014-05-11 09:00:00
toDate=2014-05-12 13:00:00
I hope you understand what's the idea.
The query should remain the same logic!
queryset.filter(to_date__gt=from_date, from_date__lt=to_date)
That is, to be returned the event must end after the new event starts and must start before the new event ends. Anything that ends before the new from_date is not returned, neither is anything that doesn't start until after it ends.
That does not precisely match your original query, but it does match the behavior described in the comments for when there's a record in the database that is entirely within the range set by the new dates.