Friday, 18 November 2022

Python program to check atleast two vowels matching words and word count from paragraph or string



def vowels_count(string):
    vowels=['a','e','i','o','u','A','E','I','O','U']
    var1 =  string.split(" ")
    var = [vowel for vowel in var1 if sum(ch in vowels for ch in vowel) >= 2 ]
    var2 = len(var)

    print (var)
    print (var2)


string="Horse knows when he is going to race. How does he know? His breakfast was scanty. (He is angry about that.) He does not have saddle on his back. He is being led, not ridden, to grandstand. He is led under grandstand into unusual, special stall. Horse is nervous. Sometimes he does not know what to do when starting gate flies open and track is before him. If he does not begin to run instantly, other horses are already ahead of him. During race, when he sees another horse just ahead of him,"


vowels_count(string)

Labels: , ,

Saturday, 12 November 2022

perl rest client crud tutorial example using REST::Client

# packages

#######################################

#REST CLIENT API ENDPOINTS EXAMPLE

#Author@kaavannan.k\@solution4u.com

#######################################


use REST::Client;

use MIME::Base64;

use JSON;

use Data::Dumper;


#The basic use case Rest cient

my $client = REST::Client->new();


#TO-DO load all this configuration from configuaration file like YAML, JSON

my $auth_req_url = 'https://xxxxxxxxxx';

my $base_url = 'https://xxxxxxxxxxx';

my $auth_data = "{ \"accessKeyId\": "xxxxxxxxxxx", 

\"accessKeySecret\":\"xxxxxxxxxxx\"}";


# Autherization request

$client->POST($auth_req_url, $auth_data, { "Content-type" => 'application/json'});

my $response = from_json ($client->responseContent());

my $access_token = $response->{'access_token'};


sub GetList {

#============================

#GET() Method for Callinglist

#============================


    my $endpoint = shift;    

    my $headers = {Accept => 'application/json', Authorization => 'Bearer ' . $access_token};

    $client -> GET($base_url . $endpoint, $headers);

    print $client->responseContent(), "\n"; 

}


sub CreatePost 

{

    my $body_data= {

    "listName" => "test11",

"externalIdColumn" => "Ref",

"customer1Column" => "ID",


  "destinationMappings" => [

{

  "fieldName"=> "PhoneNumber",

  "fieldValue"=> "PhoneNumber1"

}

  ],

  "FieldMappings" => [

{

  "fieldName"=> "AccountNumber",

  "fieldValue" => "AccountNumber"

},

{

  "fieldName" => "PhoneNum2",

  "fieldValue" => "PhoneNumber2"

},

{

  "fieldName" => "PhoneNum3",

  "fieldValue" => "PhoneNumber3"

},

{

  "fieldName" => "PhoneNum4",

  "fieldValue" => "PhoneNumber4"

},

{

  "fieldName" => "PhoneNum5",

  "fieldValue" => "PhoneNumber5"

},

{

  "fieldName" => "PhoneNum6",

  "fieldValue" => "PhoneNumber6"

}

  ]

    };


    my $endpoint="/lists/";

    my $req_header = { 'Authorization' => 'Bearer ' . $access_token, 'content-Type'=> 'application/json', 'Accept' => 'application/json, text/javascript, */*'};

    

    # Calling server

    $client->POST( $base_url . $endpoint, encode_json $body_data, $req_header );

    if ( $client->responseCode() eq '200' ) {

        print "Response Content : " . $client->responseContent() . "\n";

return from_json ($client->responseContent())->{'Id'};

    } else {

        print "Response Code : " . $client->responseCode()."\n";

        foreach ( $client -> responseHeaders() ) {

            print 'Header: ' . $_ . '=' . $client->responseHeader($_) . "\n+";

}

        return undef;

    }

}


sub PostList {

#===========================================

#POST() Method for Upload call-list details from csv file

#===========================================


    $req_body{Id} = shift;

    $req_body{Id2} = shift;

    $req_body{TimeZone} = shift;

    $req_body{expirationDate} = shift;

    $req_body{fileName} = shift;

    $endpoint = "/lists/$Id/upload";

    $req_body{'File'} = encode_base64 $file_content;  

                         

    # header formation

    my $upl_header = { 'Authorization' => 'Bearer ' . $access_token, 'content-Type'=> 'application/json', 

    'Accept' => 'application/json, text/javascript, */*; q=0.01'};

    

    # Calling server

    $client->POST( $base_url . $endpoint, encode_json \%req_body, $upl_header );


    if ( $client->responseCode() eq '200' || $client->responseCode() eq '202' ) {

        print "Response Code : " . $client->responseCode();

    } else {

        print "Response Code : " . $client->responseCode()."\n";

        foreach ( $client -> responseHeaders() ) {

            print 'Header: ' . $_ . '=' . $client->responseHeader($_) . "\n+";

}

        print "\n";

    }

print "\nResponse : " . $client->responseContent() . "\n";

}


sub DeleteList

{

#============================

#DELETE() Method for list

#============================


    my $endpoint = shift;    

    my $headers = {Accept => 'application/json', Authorization => 'Bearer ' . $access_token};

    $client -> DELETE($base_url . $endpoint, $headers);

    print $client->responseContent(), "\n"; 

}


#function calling

print "\n-------- Create list --------\n";

$id = CreatePost();

print "\n------- Getting list detail by id -------\n";

GetList("/lists/$id"); #Using list ID to fetch list

print "\n ------- upload file -------\n";

PostList($Id, 242, 'GMT', true, '30/07/2021', false, 'data.csv');

print "\n-------- Delete list --------\n";

$id = DeleteList();


Labels: , ,