I'm writing a validation and I have an hash with this structure
elements.map{ |e| [e.id,e.coverable.published_at] }.to_h
=> {305=>Fri, 17 Apr 2020 15:23:00 CEST +02:00,
306=>Fri, 17 Apr 2020 13:00:00 CEST +02:00,
307=>Fri, 17 Apr 2020 09:20:00 CEST +02:00,
308=>Fri, 17 Apr 2020 12:59:00 CEST +02:00,
309=>Fri, 17 Apr 2020 11:39:00 CEST +02:00}
I have a reference date...
published_at
=> Mon, 04 May 2020 23:51:00 CEST +02:00
I have to check if any of the element has a published_at datetime value bigger than my published_at.
Is there a short way to do that?
Try something like this
elements.any? { |e| e.coverable.published_at > your_published_at }
In case you need the element which passes the condition use find
element = elements.find { |e| e.coverable.published_at > your_published_at }
# if element is not nil such element is present
I have a collection as:
content [Collection]
[0] [Content]
creationDate Thu Aug 22 11:50:37 GMT 2019
[1] [Content]
creationDate Thu Aug 22 11:45:37 GMT 2019
[2] [Content]
creationDate Thu Aug 22 11:54:37 GMT 2019
How can I sort this collection by date value?
i.e.
content [Collection]
[0] [Content]
creationDate Thu Aug 22 11:45:37 GMT 2019
[1] [Content]
creationDate Thu Aug 22 11:50:37 GMT 2019
[2] [Content]
creationDate Thu Aug 22 11:54:37 GMT 2019
Create a DateComparator for sorting.
class DateComparator implements Comparator<Date> {
public int compare(Date d1, Date d2) {
if (d1.before(d2)) {
return -1;
} else if (d1.after(d2)) {
return 1;
} else {
return 0;
}
}
}
and call content.sort(new DateComparator())
My rethinkdb stores data in the following format.
data = [{
'appName': "app1",
'startTime': "Mon, 14 Feb 2017 05:10:00 GMT",
'endTime': "Mon, 14 Feb 2017 05:15:00 GMT",
'status': "SUCCESS"
},
{
'appName': "app1",
'startTime': "Mon, 13 Feb 2017 05:10:00 GMT",
'endTime': "Mon, 13 Feb 2017 05:15:00 GMT",
'status': "FAILED"
},
{
'appName': "app2",
'startTime': "Mon, 13 Feb 2017 05:10:00 GMT",
'endTime': "Mon, 13 Feb 2017 05:15:00 GMT",
'status': "RUNNING"
}]
I need to fetch the latest information for all apps.
r.table('apps').group('appName').max('startTime').run()
But since my startTime is stored as a string, I can not do a max operation.
I tried updating the values in the table as follows,
r.table('apps').update({'startTimeDate': pytz.timezone('Europe/Rome').localize(datetime.strptime(r.row['startTime'], '%a, %d %b %Y %H:%M:%S GMT'))}).run()
I receive an error:
TypeError: must be string, not Bracket
How do I persist startTime and endTime as date in rethinkdb from string?
RethinkDB only supports dates formatted as ISO8601 or as a number of seconds since the UNIX epoch.
Your update query has the right idea, but it tries to use python functions inside the update, where row['startTime'] is a query fragment and not a string.
Something like this might work instead:
for app in r.table('apps').run():
date = (pytz.timezone('Europe/Rome')
.localize(datetime.strptime(app['startTime'],
'%a, %d %b %Y %H:%M:%S GMT'))
(r.table('apps')
.get(app['id'])
.update({'startTimeDate': date},
durability='soft')
).run()
r.table('apps').sync()
According to the documentation, we should be looking at a parameter called "message", which doesn't not come in. What does come in is a parameter called "mandrill_events".
require 'mail'
class InboxController < ApplicationController
skip_before_filter :verify_authenticity_token, only: :create
def create
mail = Mail.new(params[:message])
....
No dice, but I do see this in the console log when I use the following syntax (note, it's so much JSON that SO has trouble viewing it with formatting):
puts JSON.parse(params[:mandrill_events])
{"mandrill_events"=>"[{\"event\":\"inbound\",\"ts\":1426188360,\"msg\":{\"raw_msg\":\"Received: from mail-ob0-f181.google.com (unknown [209.85.214.181])\\n\\tby ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509\\n\\tfor <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\\nReceived: by obcvb8 with SMTP id vb8so16123307obc.10\\n for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed\\/relaxed;\\n d=gmail.com; s=20120113;\\n h=mime-version:date:message-id:subject:from:to:content-type;\\n bh=jyd6a9aMNBrnuDpbsOEokXnACKw\\/lLnh72zkG7LCs3c=;\\n b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK\\/XFw6ZjIfhp6\\n LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb\\n bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy\\/EBjdOngcgk4Fsp8u11\\/eeB2xqBPUcrR\\n JYeu\\/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i\\n ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP\\/GexVfQzN\\n SAKA==\\nMIME-Version: 1.0\\nX-Received: by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432;\\n Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nReceived: by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nDate: Thu, 12 Mar 2015 12:25:59 -0700\\nMessage-ID: <CAMf1_47jvgW6QMwDx8R9JU6C5YiUMaPjvFz3muxhM5v4HJyoSg#mail.gmail.com>\\nSubject: Subject FTW?\\nFrom: Dee diabetic <Deediabetic#gmail.com>\\nTo: test#inbound.diabetesdelivery.com\\nContent-Type: multipart\\/alternative; boundary=001a113d39288bfe8505111c5a88\\n\\n--001a113d39288bfe8505111c5a88\\nContent-Type: text\\/plain; charset=UTF-8\\n\\nBody here\\n\\n--001a113d39288bfe8505111c5a88\\nContent-Type: text\\/html; charset=UTF-8\\n\\n<div dir=\\\"ltr\\\">Body here<\\/div>\\n\\n--001a113d39288bfe8505111c5a88--\",\"headers\":{\"Received\":[\"from mail-ob0-f181.google.com (unknown [209.85.214.181]) by ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509 for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\",\"by obcvb8 with SMTP id vb8so16123307obc.10 for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\",\"by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\"],\"Dkim-Signature\":\"v=1; a=rsa-sha256; c=relaxed\\/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=jyd6a9aMNBrnuDpbsOEokXnACKw\\/lLnh72zkG7LCs3c=; b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK\\/XFw6ZjIfhp6 LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy\\/EBjdOngcgk4Fsp8u11\\/eeB2xqBPUcrR JYeu\\/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP\\/GexVfQzN SAKA==\",\"Mime-Version\":\"1.0\",\"X-Received\":\"by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\",\"Date\":\"Thu, 12 Mar 2015 12:25:59 -0700\",\"Message-Id\":\"<CAMf1_47jvgW6QMwDx8R9JU6C5YiUMaPjvFz3muxhM5v4HJyoSg#mail.gmail.com>\",\"Subject\":\"Subject FTW?\",\"From\":\"Dee diabetic <Deediabetic#gmail.com>\",\"To\":\"test#inbound.diabetesdelivery.com\",\"Content-Type\":\"multipart\\/alternative; boundary=001a113d39288bfe8505111c5a88\"},\"text\":\"Body here\\n\\n\",\"text_flowed\":false,\"html\":\"<div dir=\\\"ltr\\\">Body here<\\/div>\\n\\n\",\"from_email\":\"Deediabetic#gmail.com\",\"from_name\":\"Dee diabetic\",\"to\":[[\"test#inbound.diabetesdelivery.com\",null]],\"subject\":\"Subject FTW?\",\"spf\":{\"result\":\"pass\",\"detail\":\"sender SPF authorized\"},\"spam_report\":{\"score\":0.5,\"matched_rules\":[{\"name\":\"RCVD_IN_DNSWL_LOW\",\"score\":-0.7,\"description\":\"RBL: Sender listed at http:\\/\\/www.dnswl.org\\/, low\"},{\"name\":null,\"score\":0,\"description\":null},{\"name\":\"listed\",\"score\":0,\"description\":\"in list.dnswl.org]\"},{\"name\":\"FREEMAIL_FROM\",\"score\":0,\"description\":\"Sender email is commonly abused enduser mail provider\"},{\"name\":\"HTML_MESSAGE\",\"score\":0,\"description\":\"BODY: HTML included in message\"},{\"name\":\"DKIM_VALID_AU\",\"score\":-0.1,\"description\":\"Message has a valid DKIM or DK signature from author's\"},{\"name\":\"DKIM_SIGNED\",\"score\":0.1,\"description\":\"Message has a DKIM or DK signature, not necessarily valid\"},{\"name\":\"DKIM_VALID\",\"score\":-0.1,\"description\":\"Message has at least one valid DKIM or DK signature\"},{\"name\":\"RDNS_NONE\",\"score\":1.3,\"description\":\"Delivered to internal network by a host with no rDNS\"}]},\"dkim\":{\"signed\":true,\"valid\":true},\"email\":\"test#inbound.diabetesdelivery.com\",\"tags\":[],\"sender\":null,\"template\":null}}]"}
Mar 12 12:26:046666 app/web.1: {"event"=>"inbound", "ts"=>1426188360, "msg"=>{"raw_msg"=>"Received: from mail-ob0-f181.google.com (unknown [209.85.214.181])\n\tby ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509\n\tfor ; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\nReceived: by obcvb8 with SMTP id vb8so16123307obc.10\n for ; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20120113;\n h=mime-version:date:message-id:subject:from:to:content-type;\n bh=jyd6a9aMNBrnuDpbsOEokXnACKw/lLnh72zkG7LCs3c=;\n b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK/XFw6ZjIfhp6\n LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb\n bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy/EBjdOngcgk4Fsp8u11/eeB2xqBPUcrR\n JYeu/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i\n ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP/GexVfQzN\n SAKA==\nMIME-Version: 1.0\nX-Received: by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432;\n Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nReceived: by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nDate: Thu, 12 Mar 2015 12:25:59 -0700\nMessage-ID: \nSubject: Subject FTW?\nFrom: Dee diabetic \nTo: test#inbound.diabetesdelivery.com\nContent-Type: multipart/alternative; boundary=001a113d39288bfe8505111c5a88\n\n--001a113d39288bfe8505111c5a88\nContent-Type: text/plain; charset=UTF-8\n\nBody here\n\n--001a113d39288bfe8505111c5a88\nContent-Type: text/html; charset=UTF-8\n\nBody here\n\n--001a113d39288bfe8505111c5a88--", "headers"=>{"Received"=>["from mail-ob0-f181.google.com (unknown [209.85.214.181]) by ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509 for ; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)", "by obcvb8 with SMTP id vb8so16123307obc.10 for ; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)", "by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)"], "Dkim-Signature"=>"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=jyd6a9aMNBrnuDpbsOEokXnACKw/lLnh72zkG7LCs3c=; b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK/XFw6ZjIfhp6 LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy/EBjdOngcgk4Fsp8u11/eeB2xqBPUcrR JYeu/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP/GexVfQzN SAKA==", "Mime-Version"=>"1.0", "X-Received"=>"by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)", "Date"=>"Thu, 12 Mar 2015 12:25:59 -0700", "Message-Id"=>"", "Subject"=>"Subject FTW?", "From"=>"Dee diabetic ", "To"=>"test#inbound.diabetesdelivery.com", "Content-Type"=>"multipart/alternative; boundary=001a113d39288bfe8505111c5a88"}, "text"=>"Body here\n\n", "text_flowed"=>false, "html"=>"Body here\n\n", "from_email"=>"Deediabetic#gmail.com", "from_name"=>"Dee diabetic", "to"=>[["test#inbound.diabetesdelivery.com", nil]], "subject"=>"Subject FTW?", "spf"=>{"result"=>"pass", "detail"=>"sender SPF authorized"}, "spam_report"=>{"score"=>0.5, "matched_rules"=>[{"name"=>"RCVD_IN_DNSWL_LOW", "score"=>-0.7, "description"=>"RBL: Sender listed at http://www.dnswl.org/, low"}, {"name"=>nil, "score"=>0, "description"=>nil}, {"name"=>"listed", "score"=>0, "description"=>"in list.dnswl.org]"}, {"name"=>"FREEMAIL_FROM", "score"=>0, "description"=>"Sender email is commonly abused enduser mail provider"}, {"name"=>"HTML_MESSAGE", "score"=>0, "description"=>"BODY: HTML included in message"}, {"name"=>"DKIM_VALID_AU", "score"=>-0.1, "description"=>"Message has a valid DKIM or DK signature from author's"}, {"name"=>"DKIM_SIGNED", "score"=>0.1, "description"=>"Message has a DKIM or DK signature, not necessarily valid"}, {"name"=>"DKIM_VALID", "score"=>-0.1, "description"=>"Message has at least one valid DKIM or DK signature"}, {"name"=>"RDNS_NONE", "score"=>1.3, "description"=>"Delivered to internal network by a host with no rDNS"}]}, "dkim"=>{"signed"=>true, "valid"=>true}, "email"=>"test#inbound.diabetesdelivery.com", "tags"=>[], "sender"=>nil, "template"=>nil}}
So I am getting a JSON string, but how exactly is the best way to grab the TO, FROM, and SUBJECT?
Update: I just tried the following:
tester = JSON.parse(params[:mandrill_events])
puts tester[:msg][:subject]
#and even this
puts tester["msg"]["subject"]
Did not work. Got an error: **TypeError (no implicit conversion of String into Integer): **
After a day of banging my head, I came up with the solution. By the way, accessing the values directly doesn't work. I had to loop into it.
incomingMail = params[:mandrill_events]
mail_from = "Cannot read From"
mail_originally_to = "Cannot read To"
mail_subject = "No subject"
mail_date = ""
mail_body = "No email body"
if incomingMail != nil
incomingMail = JSON.parse(incomingMail)
incomingMail.each do |item|
mail_from = item["msg"]["from_email"]
mail_originally_to = item["msg"]["headers"]["To"]
mail_subject = item["msg"]["subject"]
mail_date = item["msg"]["headers"]["Date"]
mail_body = item["msg"]["text"]
mail_body_html = item["msg"]["html"]
end
#Confirm
else
puts "Email not sent. Parameter invalid."
end
I've just started on Oozie. Hoping someone here can offer some useful advice.
Here is a snippet of the coordinator.xml
<coordinator-app name="weeklyABCFacts" frequency="${coord:days(7)}" start="${start}T00:00Z" end="${end}" timezone="CET" xmlns="uri:oozie:coordinator:0.1">
<controls>
<timeout>-1</timeout>
<concurrency>1</concurrency>
<execution>FIFO</execution>
</controls>
<datasets>
<dataset name="weekly-f_stats-flag" frequency="${coord:days(7)}" initial-instance="2013-07-01T00:00Z" timezone="CET">
<uri-template>${nameNode}/warehouse/hive/f_stats/dt=${YEAR}W${WEEK} </uri-template>
</dataset>
</datasets>
...
</coordinator-app>
The part where my question will relate to is in within the tag. They are normally expressed in the following: "...revenue_feed/${YEAR}/${MONTH}/${DAY}/${HOUR}..."
Can this part be expressed in WEEK? i.e. the last column in table rep below.
Reason for the question is that our date table has a field column called 'iso_week' (e.g. 28, or its corresponding date range is 8 July - 14 July 2013). It looks like the following:
-----------------------------------+
|date_field |iso_week|iso_week_date|
-----------------------------------+
'2013-07-08', '28', '2013W28'
'2013-07-09', '28', '2013W28'
'2013-07-10', '28', '2013W28'
'2013-07-11', '28', '2013W28'
'2013-07-12', '28', '2013W28'
'2013-07-13', '28', '2013W28'
'2013-07-14', '28', '2013W28'
I hope this is clear enough, otherwise, please let me know how else I can be more clear.
There is not (in the 3.3.2 source i'm looking at), but there's nothing stopping you from downloading the source and amending the core/java/org/apache/oozie/coord/CoordELEvaluator.java file, specifically the createURIELEvaluator(String) method:
public static ELEvaluator createURIELEvaluator(String strDate) throws Exception {
ELEvaluator eval = new ELEvaluator();
Calendar date = Calendar.getInstance(DateUtils.getOozieProcessingTimeZone());
// always???
date.setTime(DateUtils.parseDateOozieTZ(strDate));
eval.setVariable("YEAR", date.get(Calendar.YEAR));
eval.setVariable("MONTH", make2Digits(date.get(Calendar.MONTH) + 1));
eval.setVariable("DAY", make2Digits(date.get(Calendar.DAY_OF_MONTH)));
eval.setVariable("HOUR", make2Digits(date.get(Calendar.HOUR_OF_DAY)));
eval.setVariable("MINUTE", make2Digits(date.get(Calendar.MINUTE)));
// add the following line:
eval.setVariable("WEEK", make2Digits(date.get(Calendar.WEEK_OF_YEAR)));
return eval;
}
You should then be able to follow the instructions to recompile oozie
I would note that you should be weary of how week numbers and years don't always fit together nicely - for example week 1 of 2013 actually starts in 2012:
Tue Dec 25 11:11:52 EST 2012 : 2012 W 52
Wed Dec 26 11:11:52 EST 2012 : 2012 W 52
Thu Dec 27 11:11:52 EST 2012 : 2012 W 52
Fri Dec 28 11:11:52 EST 2012 : 2012 W 52
Sat Dec 29 11:11:52 EST 2012 : 2012 W 52
Sun Dec 30 11:11:52 EST 2012 : 2012 W 1 <= Here's your problem
Mon Dec 31 11:11:52 EST 2012 : 2012 W 1
Tue Jan 01 11:11:52 EST 2013 : 2013 W 1 <= 'Fixed' from here
Wed Jan 02 11:11:52 EST 2013 : 2013 W 1
Thu Jan 03 11:11:52 EST 2013 : 2013 W 1
Fri Jan 04 11:11:52 EST 2013 : 2013 W 1
Sat Jan 05 11:11:52 EST 2013 : 2013 W 1
Sun Jan 06 11:11:52 EST 2013 : 2013 W 2
Mon Jan 07 11:11:52 EST 2013 : 2013 W 2
Tue Jan 08 11:11:52 EST 2013 : 2013 W 2
As produced by the following test snippet:
#Test
public void testDates() {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.set(2012, 11, 25);
for (int x = 0; x < 15; x++) {
System.err.println(cal.getTime() + " : " + cal.get(Calendar.YEAR)
+ " W " + cal.get(Calendar.WEEK_OF_YEAR));
cal.add(Calendar.DAY_OF_YEAR, 1);
}
}