<commit_before><?php
/*
Authentication to Netatmo Server with the authorization grant
This script has to be hosted by your web server in order to make it work
*/

require_once 'NAApiClient.php';
require_once 'Config.php';

$client = new NAApiClient(array("client_id" => $client_id, "client_secret" => $client_secret));


//Test if code is provided in get parameters (that means user has already accepted the app and has been redirected here)
if(isset($_GET["code"]))
{
    try
    {
    // Get the token for later usage.
        $tokens = $client->getAccessToken();        
    $helper = new NAApiHelper();
        
    $user = $client->api("getuser", "POST");
    $devicelist = $client->api("devicelist", "POST");
    $devicelist = $helper->SimplifyDeviceList($devicelist);
    $mesures = $helper->GetLastMeasures($client,$devicelist);
?>
        <html><body><pre><code>
<?php
        echo json_format(json_encode($mesures, true));
?>
        </code></pre></body></html>
<?php

    }
    catch(NAClientException $ex)
    {
        echo "An error happend while trying to retrieve your tokens\n";<commit_msg>proper try catch block<commit_after><?php
/*
Authentication to Netatmo Server with the authorization grant
This script has to be hosted by your web server in order to make it work
*/

require_once 'NAApiClient.php';
require_once 'Config.php';

$client = new NAApiClient(array("client_id" => $client_id, "client_secret" => $client_secret));


//Test if code is provided in get parameters (that means user has already accepted the app and has been redirected here)
if(isset($_GET["code"]))
{
    try
    {
	    // Get the token for later usage.(you can store $tokens["refresh_token"] for retrieving a new access_token next time)
	    $tokens = $client->getAccessToken();       
    } 
    catch(NAClientException $ex)
    {
        echo "An error happend while trying to retrieve your tokens\n";
        die();
    }
    try
    {
        $helper = new NAApiHelper();
        
        $user = $client->api("getuser", "POST");
        $devicelist = $client->api("devicelist", "POST");
        $devicelist = $helper->SimplifyDeviceList($devicelist);
        $mesures = $helper->GetLastMeasures($client,$devicelist);
?>
        <html><body><pre><code>
<?php
        echo json_format(json_encode($mesures, true));
?>
        </code></pre></body></html>
<?php

    }
    catch(NAClientException $ex)
    {
        echo "An error happend while trying to retrieve your last measures\n";
        echo $ex->getMessage()."\n";
{'fraction_non_alphanumeric': 0.13605712019040064, 'fraction_numerical': 0.0, 'mean_word_length': 3.311111111111111, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 38, 'https://': 0, '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': '1189840', 'n_tokens_mistral': 770, 'n_tokens_neox': 747, 'n_words': 225}