How can I pass php code as a content while publishing a post

I will give you a simple example, which you can modify for your purpose.

save_weather_field
This function will add/update/delete any post meta (in case you will decide to add more weather fields). We will use it inside post save action below.

function save_weather_field($post_id, $key, $value)
{
    //new value we pass in this function
    $new_meta_value = ( isset( $value ) ? sanitize_text_field( $value ) : false );

    //old value from database
    $meta_value = get_post_meta( $post_id, $key, true );

    //if new value exists and old value not - we add post meta
    if ( $new_meta_value && false == $meta_value )
        add_post_meta( $post_id, $key, $new_meta_value, true );

    //if old value exists but we have new value - update post meta
    elseif ( $new_meta_value && $new_meta_value != $meta_value )
        update_post_meta( $post_id, $key, $new_meta_value );

    //if old value exists but new value is empty - delete post meta
    elseif ( false == $new_meta_value && $meta_value )
        delete_post_meta( $post_id, $key, $meta_value );

}

weather_metadata_save
This function fires on post save (“post” post type).

function weather_metadata_save($post_id, $post, $update){

    //return if user don't have permissions to edit post
    if(!current_user_can("edit_post", $post_id))
        return $post_id;

    //return if post submitted with XHR
    if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
        return $post_id;

    //your code
    $url = "http://metaweather.com/api/location/2379574";
    $json = file_get_contents($url);
    $json_data = json_decode($json, true);
    $weather_sate=$json_data['consolidated_weather'][0]['weather_state_name'];
    $temperature=$json_data['consolidated_weather'][0]['the_temp'];

    /save weather sate if it exists
    if( !empty($weather_sate) ):
        save_weather_field($post_id, 'weather-sate', $weather_sate);
    endif;

    //save temperature if exists
    if( !empty($temperature) ):
        save_weather_field($post_id, 'temperature', $temperature);
    endif;
    
}

add_action("save_post_post", "weather_metadata_save", 10, 3);

I used temperature as post meta name for temperature and weather-state for weather state. So, you can get them as any other post meta:

$temperature = get_post_meta($post->ID, 'temperature', true);
$weather_state = get_post_meta($post->ID, 'weather-state', true);

P.S. I tried this code on my localhost, and I’ve got 27.195 and Showers, so I guess it works well 😉