Skip to content

Instantly share code, notes, and snippets.

@robhammond
Last active June 26, 2018 10:58
Show Gist options
  • Save robhammond/8800607 to your computer and use it in GitHub Desktop.
Save robhammond/8800607 to your computer and use it in GitHub Desktop.
Get date and chart x-axis values from the JSON created when generating a SEO visibility chart in SearchMetrics. Makes it easier to plot YoY growth etc.
#!/usr/bin/env perl
use strict;
use Modern::Perl;
use Mojo::JSON qw(decode_json);
# seo-paid-visibility
my $raw = <<EOF;
{"data":{...}}
EOF
$raw =~ s!,\s?\"wrapper\"\:.*?$!}!s;
my $data = decode_json($raw);
my @dates;
for my $d (@{$data->{'data'}->{'chart'}->{'xAxis'}->{'categories'}}) {
push @dates, $d;
}
my $i = 0;
say $data->{'data'}->{'chart'}->{'series'}->[0]->{'name'};
for my $d (@{$data->{'data'}->{'chart'}->{'series'}->[0]->{'data'}}) {
# next unless $d->{'y'};
my $date = $dates[$i];
$date =~ s!^(..)/(..)/(....)$!$3-$1-$2!;
say $date . "\t" . $d->{'y'};
$i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment