Thursday, 9 April 2020

python Math Function

import math

def sin(x):
    if 2 * x == pi:
        return 0.99999999
    else:
        return None

pi = 3.14

print(sin(pi/2))
print(math.sin(math.pi/2))

Thursday, 26 March 2020

Python Pandas to read excel .csv file and get all values under specific column and skip null value





import os
from selenium import webdriver
import time
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile

df = pd.read_csv(r"xxx.csv")
queue = df["Messages"].dropna().tolist()
print (queue)

Tuesday, 10 March 2020

Python Pandas to read excel .csv file and get all values under specific column




import os
from selenium import webdriver
import time
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile

df = pd.read_csv(r"xxx.csv")
queue = df["Messages"].tolist()
print (queue)

powershell script to trigger message in slack using web hock



    $uriSlack = "URL"
        $body = ConvertTo-Json @{
        pretext = "test"
        text = "test"
        color = "#142954"
}
try {
    Invoke-RestMethod -uri $uriSlack -Method Post -body $body -ContentType 'application/json' | Out-Null
    } catch {
    Write-Error (Get-Date) ": Update to Slack went wrong..."
    }

python script to List Files from a directory created or modified in last 30 min





$path = "Z:\"+(Get-Date).tostring("MM-dd-yyyy")
#$path
$FileList = Get-ChildItem -Path $path
$FileLists = $FileList| Where-Object {$_.LastWriteTime -gt [datetime]::Now.AddMinutes(-30)}
#$FileLists

$currenttime = (Get-Date).ToString('HH:mm')
#$currenttime

$currenttime1 = (Get-Date).AddMinutes(1).ToString('HH:mm')
#$currenttimeplus1

$currenttime2 = (Get-Date).AddMinutes(2).ToString('HH:mm')
#$currenttimeplus2

$currenttime3 = (Get-Date).AddMinutes(3).ToString('HH:mm')
#$currenttimeplus3

$currenttime4 = (Get-Date).AddMinutes(4).ToString('HH:mm')
#$currenttimeplus4

$currenttime5 = (Get-Date).AddMinutes(5).ToString('HH:mm')
#$currenttimeplus5

$currenttime6 = (Get-Date).AddMinutes(6).ToString('HH:mm')
#$currenttimeplus6

$currenttime7= (Get-Date).AddMinutes(7).ToString('HH:mm')
#$currenttimeplus7
$currenttime8 = (Get-Date).AddMinutes(8).ToString('HH:mm')
#$currenttimeplus8
$currenttime9 = (Get-Date).AddMinutes(9).ToString('HH:mm')
#$currenttimeplus9
$currenttime10 = (Get-Date).AddMinutes(10).ToString('HH:mm')
#$currenttimeplus10

#Write-Host "in for loop"
#$filecreatedtime = $tomail.CreationTime.ToString('HH:mm')
#$filecreatedtime

$counter = 0   
foreach ($tomail in $FileLists)
{
<#
Write-Host "in for loop"
Write-Host ($tomail)
Write-Host ("----------------------------------------------------------")
Write-Host ($tomail.CreationTime.ToString('HH:mm'))
Write-Host ($currenttime)
Write-Host ("----------------------------------------------------------")
#>
$counter = 0
if ($tomail.Name -match '')
{
#Write-Host $tomail.Name
if ($([DateTime]$tomail.CreationTime.ToString('HH:mm')) -match $([DateTime]$currenttime) -or $([DateTime]$currenttime1) -or $([DateTime]$currenttime2) -or $([DateTime]$currenttime3) -or $([DateTime]$currenttime4) -or $([DateTime]$currenttime5) -or $([DateTime]$currenttime6) -or $([DateTime]$currenttime7) -or $([DateTime]$currenttime8) -or $([DateTime]$currenttime9) -or $([DateTime]$currenttime10))

    {
        #Write-Host "File  found"

        $counter = $counter + 1

        $tomail.Name + "  Found  " + $tomail.CreationTime >> C:\Users\raghuvel.sekar\Desktop\LOG.txt

}
   
else
{
  #Write-Host "File not found"

  "  FileNotFound  " + $currenttime >> C:\Users\raghuvel.sekar\Desktop\LOG.txt

}
        #$counter
        Remove-Variable counter

python script to send mail using outlook 2016 with multiple attachment




 $Outlook = New-Object -ComObject Outlook.Application
 $createmail = $Outlook.CreateItem(0)
 $createmail.To =  "test@test.com"
 $createmail.Subject = "test"
 $createmail.Body = "test"
 $file = "C:\Users\raghuvel.sekar\Desktopscreenshot3.jpg"
 $file1 = "C:\Users\raghuvel.sekar\Desktop\creenshot4.jpg"
 $createmail.Attachments.Add($file)
 $createmail.Attachments.Add($file1)
 $createmail.Send()

Python to get only digits from a file and append into a list



            f = open('file2.txt', 'r')
            for line in f:
                    words = line.split()
                    for i in words:
                            if(i.isdigit()):
                                mylist.append(i)
            print (mylist)

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...