<commit_before>#!/usr/bin/perl
use LWP::UserAgent;

sub build_endpoint {
	$_[1] =~ s/[\%]/%25/g; #this must be done first

	$_[1] =~ s/[\ ]/%20/g;
	$_[1] =~ s/[\!]/%21/g;
	$_[1] =~ s/[\"]/%22/g;
	$_[1] =~ s/[\#]/%23/g;
	$_[1] =~ s/[\$]/%24/g;
	$_[1] =~ s/[\&]/%26/g;
	$_[1] =~ s/[\']/%27/g;
	$_[1] =~ s/[\(]/%28/g;
	$_[1] =~ s/[\)]/%29/g;
	$_[1] =~ s/[\*]/%2A/g;
	$_[1] =~ s/[\+]/%2B/g;
	$_[1] =~ s/[\,]/%2C/g;
	$_[1] =~ s/[\-]/%2D/g;
	$_[1] =~ s/[\.]/%2E/g;
	$_[1] =~ s/[\/]/%2F/g;
	$_[1] =~ s/[\:]/%3A/g;
	$_[1] =~ s/[\;]/%3B/g;
	$_[1] =~ s/[\<]/%3C/g;
	$_[1] =~ s/[\=]/%3D/g;
	$_[1] =~ s/[\>]/%3E/g;
	$_[1] =~ s/[\?]/%3F/g;
	$_[1] =~ s/[\@]/%40/g;

	return sprintf("%s?q=%s&format=%s&diagnostics=%s&env=%s&callback=%s", @_); 
}

my $ua = LWP::UserAgent->new;
my $query    = "SELECT Bid, Ask FROM yahoo.finance.quotes WHERE symbol=\"TSLA\"";
my $env      = "store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
my $endpoint = build_endpoint( "https://query.yahooapis.com/v1/public/yql", 
							   $query,   #YQL query
							   "json",   #format of response
							   "false",  #boolean to include diagnostic info
							   $env,     #no idea
							   "" );     #probably callback function?

# set custom HTTP request header fields
my $req = HTTP::Request->new(GET => $endpoint);
$req->header('content-type' => 'application/json');
$req->header('x-auth-token' => '<PASSWORD>');

my $resp = $ua->request($req);
if ($resp->is_success) {
    my $message = $resp->decoded_content;
    print "Received reply: $message\n";
}
else {
    print "HTTP GET error code: ", $resp->code, "\n";
    print "HTTP GET error message: ", $resp->message, "\n";
}<commit_msg>Parse JSON<commit_after>#!/usr/bin/perl
use strict;
use warnings;
use JSON qw( decode_json );
use LWP::UserAgent;

sub build_endpoint {
	$_[1] =~ s/[\%]/%25/g; #this must be done first

	$_[1] =~ s/[\ ]/%20/g;
	$_[1] =~ s/[\!]/%21/g;
	$_[1] =~ s/[\"]/%22/g;
	$_[1] =~ s/[\#]/%23/g;
	$_[1] =~ s/[\$]/%24/g;
	$_[1] =~ s/[\&]/%26/g;
	$_[1] =~ s/[\']/%27/g;
	$_[1] =~ s/[\(]/%28/g;
	$_[1] =~ s/[\)]/%29/g;
	$_[1] =~ s/[\*]/%2A/g;
	$_[1] =~ s/[\+]/%2B/g;
	$_[1] =~ s/[\,]/%2C/g;
	$_[1] =~ s/[\-]/%2D/g;
	$_[1] =~ s/[\.]/%2E/g;
	$_[1] =~ s/[\/]/%2F/g;
	$_[1] =~ s/[\:]/%3A/g;
	$_[1] =~ s/[\;]/%3B/g;
	$_[1] =~ s/[\<]/%3C/g;
	$_[1] =~ s/[\=]/%3D/g;
	$_[1] =~ s/[\>]/%3E/g;
	$_[1] =~ s/[\?]/%3F/g;
	$_[1] =~ s/[\@]/%40/g;

	return sprintf("%s?q=%s&format=%s&diagnostics=%s&env=%s&callback=%s", @_); 
}

my $ua       = LWP::UserAgent->new;
my $query    = "SELECT Bid, Ask, LastTradePriceOnly FROM yahoo.finance.quotes WHERE symbol=\"TSLA\"";
my $env      = "store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
my $endpoint = build_endpoint( "https://query.yahooapis.com/v1/public/yql", 
							   $query,   #YQL query
							   "json",   #format of response
							   "false",  #boolean to include diagnostic info
							   $env,     #
							   "" );     #callback

# set custom HTTP request header fields
my $req = HTTP::Request->new(GET => $endpoint);
$req->header('content-type' => 'application/json');
$req->header('x-auth-token' => '<PASSWORD>');

my $resp = $ua->request($req);
if ($resp->is_success) {
    my $response = decode_json($resp->decoded_content);
    my $quote = $response->{'query'}{'results'}{'quote'};
	print "Bid: ". $quote->{'Bid'}."\n";
	print "Ask: ". $quote->{'Ask'}."\n";  
} 
else {
    print "HTTP GET error code: ", $resp->code, "\n";
    print "HTTP GET error message: ", $resp->message, "\n"; 
}
{'fraction_non_alphanumeric': 0.313561762165275, 'fraction_numerical': 0.03570400230348402, 'mean_word_length': 2.898989898989899, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 34, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2160204', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1647, 'n_words': 287}