Event Extractor

Extracting time information from plain text such as emails is a very useful functionality, but still remains as a challenge. You can see examples in Gmail. Gmail underlines date and time in attempt to create calendar events automatically. As you can see, the result is often mixed. There are many scenarios that Gmail cannot handle well. Your task here is to write a script to achieve similar and even better performance than Gmail event extractor.

Two JSON files are provided with this assignment. JSON stands for JavaScript Object Notation. It is a lightweight data-interchange format, which is much easier to read and write comparing with XML.
The first file “emails.json” contains several emails. Below is an example email which shows send date/time, subject, time zone and the body:
{ "sent": "2016-02-01T19:03:02.00Z",
"subject": "Upcoming events: Orientation 2016", "timeZone":

"content": "We're pleased to ......"

-Your script is expected to accept any JSON files in that format. It should be able to extract information related to time and date. You can assume the email file is always in correct format. Hence there is no need to validate data. However usual file handling practice should not be omitted.
-Your script will be tested on unseen email files.
-Your script is expected to produce an output file, which clearly shows time info of events in JSON. The
second file “events.json” is the example of such output file that your script should be generating.
Note “datetime” and “date” are different. Attribute “date” is to represent all-day event. One event cannot have both date & datetime attributes.

Each event has a start time and an end time. The default duration of a “datetime” event is 1 hour (when the end time is unspecified).
You are required to write a brief report to explain your implementation and discuss your ideas. Marks will be given to good discussions even if the coding is relatively primitive.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

use strict;
use warnings;

use DateTime;
use LWP::Simple;
use JSON;
use List::Util qw(first);
use POSIX qw(strftime);
use EventExtractor;

my $filename = "emails.json";
my $mail_list = parse_mails($filename);

#events_list - used to record events
my $output_file = "events2.json";
my @events_list = ($output_file);

my %event_times;
my ($start_time,$end_time);

foreach my $item( @$mail_list ) {

my $sent_time = $item->{'sent'};
my $time_zone = 'GMT';
if ( exists($item->{'timeZone'}) ){
$time_zone = $item->{'timeZone'};
my $default_datetime = init_datetime($sent_time,$time_zone);

my $content = $item->{'content'};

%event_times = parse_content($default_datetime,$content);
$start_time = $event_times{'start'};
$end_time = $event_times{'end'};

print "= " . $sent_time . " =\n";
print $start_time->strftime('%Y-%m-%dT%H:%M:%S%Z') . "\n";
print $end_time->strftime('%Y-%m-%dT%H:%M:%S%Z') . "\n";

if ($start_time->strftime('%Y-%m-%d') ne '0000-01-01') {...
$45.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Perl Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats