Python snippet to do a weather forecast for 5 days with open-meteo data

This script uses the openmeteo_py library to retrieve meteorological data for the specified latitude and longitude (Thodupuzha, Idukki). The Hourly and Daily classes are used to specify the type of data to be retrieved (hourly or daily). The Options class is used to specify the location by latitude and longitude. The OWmanager class is used to manage data retrieval using the specified options and types of data.

The script then retrieves the meteorological data using mgr.get_data() and stores it in the meteo variable. The data for the next 5 days is then extracted from the meteo dictionary and stored in the five_days_forecast variable.

For each day in the five_days_forecast, the date, weather code, maximum and minimum temperatures, precipitation sum and hours, wind speed and gusts, wind direction, sunrise and sunset times, and shortwave radiation sum are extracted from the meteo dictionary. The weather code is then used to determine the summary of the weather conditions for that day.

Finally, the extracted data is printed out with descriptive labels. If the data is not available, the script will print an error message “Error: Data not available”.

from openmeteo_py import Hourly,Daily,Options,OWmanager

# Latitude, Longitude for Thodupuzha, Idukki
latitude = 9.917773198864504
longitude = 76.74575669934728

hourly = Hourly()
daily = Daily()
options = Options(latitude,longitude)

mgr = OWmanager(options, hourly.all(),daily.all())

# Download data
meteo = mgr.get_data()
#print(meteo)

try:
    five_days_forecast = meteo['daily']['time'][:5]
 
    for day in five_days_forecast:
        date = day
        weather_code = meteo['daily']['weathercode'][five_days_forecast.index(day)]
        temperature_max = meteo['daily']['apparent_temperature_max'][five_days_forecast.index(day)]
        temperature_min = meteo['daily']['apparent_temperature_min'][five_days_forecast.index(day)]
        precipitation_sum = meteo['daily']['precipitation_sum'][five_days_forecast.index(day)]
        precipitation_hours = meteo['daily']['precipitation_hours'][five_days_forecast.index(day)]
        windspeed_10m_max = meteo['daily']['windspeed_10m_max'][five_days_forecast.index(day)]
        windgusts_10m_max = meteo['daily']['windgusts_10m_max'][five_days_forecast.index(day)]
        winddirection_10m_dominant = meteo['daily']['winddirection_10m_dominant'][five_days_forecast.index(day)]
        sunrise = meteo['daily']['sunrise'][five_days_forecast.index(day)]
        sunset = meteo['daily']['sunset'][five_days_forecast.index(day)]
        shortwave_radiation_sum = meteo['daily']['shortwave_radiation_sum'][five_days_forecast.index(day)]

        
        if weather_code == 0:
            summary = "Clear sky"
        elif weather_code in [1, 2, 3]:
            summary = "Mainly clear, partly cloudy, and overcast"
        elif weather_code in [45, 48]:
            summary = "Fog and depositing rime fog"
        elif weather_code in [51, 53, 55]:
            summary = "Drizzle: Light, moderate, and dense intensity"
        elif weather_code in [56, 57]:
            summary = "Freezing Drizzle: Light and dense intensity"
        elif weather_code in [61, 63, 65]:
            summary = "Rain: Slight, moderate and heavy intensity"
        elif weather_code in [66, 67]:
            summary = "Freezing Rain: Light and heavy intensity"
        elif weather_code in [71, 73, 75]:
            summary = "Snow fall: Slight, moderate, and heavy intensity"
        elif weather_code == 77:
            summary = "Snow grains"
        elif weather_code in [80, 81, 82]:
            summary = "Rain showers: Slight, moderate, and violent"
        elif weather_code in [85, 86]:
            summary = "Snow showers slight and heavy"
        elif weather_code in [95, 96, 99]:
            summary = "Thunderstorm: Slight or moderate with slight and heavy"


        print("Date: ", date)
        print("Summary: ", summary)
        print("Temperature (Max): ", temperature_max, "°C")
        print("Temperature (Min): ", temperature_min, "°C")
        print("Precipitation Sum: ", precipitation_sum, "mm")
        print("Precipitation Hours: ", precipitation_hours, "h")
        print("Wind Speed (Max): ", windspeed_10m_max, "km/h")
        print("Wind Gusts (Max): ", windgusts_10m_max, "km/h")
        print("Wind Direction: ", winddirection_10m_dominant, "°")
        print("Sunrise: ", sunrise)
        print("Sunset: ", sunset)
        print("Shortwave Radiation Sum: ", shortwave_radiation_sum, "MJ/m²")
        print("\n")

except KeyError:
    print("Error: Data not available")

Output Sample:-

Date:  2023-02-12
Summary:  Mainly clear, partly cloudy, and overcast
Temperature (Max):  37.7 °C
Temperature (Min):  18.8 °C
Precipitation Sum:  0.0 mm
Precipitation Hours:  0.0 h
Wind Speed (Max):  10.9 km/h
Wind Gusts (Max):  26.3 km/h
Wind Direction:  288 °
Sunrise:  2023-02-12T01:12
Sunset:  2023-02-12T13:02
Shortwave Radiation Sum:  24.54 MJ/m²

Lorenz attractor

The Lorenz attractor is a mathematical model that describes the behaviour of certain dynamical systems that are highly sensitive to initial conditions, also known as the butterfly effect. The equations that define the Lorenz attractor were developed by Edward Lorenz in the 1960s, and they have been used to model a wide range of physical systems, including weather patterns, atmospheric circulation, and chemical reactions.

The Lorenz attractor is defined by a system of three non-linear ordinary differential equations:

dx/dt = σ(y – x) dy/dt = x(ρ – z) – y dz/dt = xy – βz

where x, y, and z are the state variables, σ, ρ, and β are the parameters of the system, and t is time.

The solutions to these equations describe the behaviour of the system over time, and they are typically visualized as a three-dimensional plot in which the x, y, and z variables are represented by the x, y, and z axes, respectively. The solutions typically form a complex, fractal-like shape that is often referred to as the Lorenz attractor.

It’s worth noting that the Lorenz attractor is a chaotic system, meaning that it is highly sensitive to initial conditions. This is why small differences in the initial conditions can lead to vastly different solutions over time, the butterfly effect.

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# Define the Lorenz equations
def lorenz(y, t, sigma, beta, rho):
    x, y, z = y
    dydt = [sigma*(y-x), x*(rho-z)-y, x*y-beta*z]
    return dydt

# Set the initial conditions and parameters
y0 = [1, 1, 1]
sigma = 10
beta = 8/3
rho = 28

# Define the time range for the solution
t = np.linspace(0, 30, 1000)

# Solve the Lorenz equations using odeint
sol = odeint(lorenz, y0, t, args=(sigma, beta, rho))

# Extract the solutions for x, y, and z
x = sol[:, 0]
y = sol[:, 1]
z = sol[:, 2]

# Create a 3D plot of the solutions
fig = plt.figure()
ax = fig.gca(projection='3d')

Bash script to find all broken links or a wesite

#/bin/bash
#Usage find_broken_links.sh URL

if [ $# -eq 0 ];
then
printf “Usage $0 URL \n Example http://mydomain.com \n”;
exit -1;
fi

mkdir -v /tmp/$$.lynx;
cd /tmp/$$.lynx;

lynx -traversal $1 >/dev/null
sort -u reject.dat >all_rejected_links.txt

count=0;
echo “Broken links are :”

while read link;
do
flag=`curl -I $link -s | grep “HTTP/.*OK”`;
if [[ -z $flag ]]; then
echo $link;
[[count++]];
fi

done < all_rejected_links.txt

if [ $count -eq 0 ]; then
echo “No broken links !”
fi

Fun with Linux Terminal :)

Working Linux is really fun and you can make impression on windows kids wit the below commands and applications !

1) Have a train on your terminal

yum install sl

Than use the command sl on terminal.

Train

2) A telnet movie

 

telnet towel.blinkenlights.nl

                                           /~\
                                          |oo )
                                          _\=/_
                          ___        #   /  _  \  #
                         / ()\        \\//|/.\|\\//
                       _|_____|_       \/  \_/  \/
                      | | === | |         |\ /|
                      |_|  O  |_|         \_ _/
                       ||  O  ||          | | |
                       ||__*__||          | | |
                      |~ \___/ ~|         []|[]
                      /=\ /=\ /=\         | | |
      ________________[_]_[_]_[_]________/_]_[_\_________________________^]

3) Reverse texts

[root@nopanel ~]# rev
Deepak
kapeeD

 

4) ASCII cow 

You can install this from EPEL repository

saycow

 

5)  Create your own Matrix Hack with cmatrix

Installation :-

yum install gcc make autoconf automake ncurses-devel

wget http://www.asty.org/cmatrix/dist/cmatrix-1.2a.tar.gz

tar xvzf ~/cmatrix-1.2a.tar.gz

cd ~/cmatrix-1.2a
aclocal
autoconf
automake -a
./configure
make
sudo make install

Just type command cmatrix  and have fun with matrix

cmatrix

 

6) banner cimmand

banner – prints a short string to the console in very large letters

banner

7) Ascii art with “figlet” 

rpm -Uvh http://pkgs.repoforge.org/figlet/figlet-2.2.2-1.el6.rf.x86_64.rpm

figlet

 

8) cowsay/cowthink – configurable speaking/thinking cow

cowsay

9) fortune – print a random, hopefully interesting, adage

fortune

10) aafire displays burning ascii art flames

Installation :-

Will get from rpmforge
# yum install aalib

Just type aafire to bring fire on your terminal

aafire

11) espeak – A multi-lingual software speech synthesizer.

espeak “Linux is Cool”

12) Factor, Print the prime factors of each specified integer NUMBER
[root@nopanel ~]# factor
5
5: 5
10
10: 2 5
11
11: 11

12) Clock with figlet and while loop

Use the oneliner:  while true; do echo “$(date ‘+%D %T’ | figlet)”; sleep 1; done

Clock

 

13) ASCIIquarium : Have a live ASCII aquarium

Installation :-

cpan Term::Animation

wget http://www.robobunny.com/projects/asciiquarium/asciiquarium.tar.gz
tar -zxvf asciiquarium.tar.gz
cd asciiquarium_1.1/
cp asciiquarium /usr/local/bin
chmod 0755 /usr/local/bin/asciiquarium

Just type command “asciiquarium” and have an aquarium on your terminal

aquarium

Enable HTML Editor in Horde (cPanel)

1) Open the file /usr/local/cpanel/base/horde/imp/config/mime_drivers.php

2) Change “‘inline’ => falce,” to “‘inline’ => true,” as below and save the file.
$mime_drivers[‘imp’][‘html’] = array(
‘inline’ => true,
:
:
3) Restart cPanel service : /etc/init.d/cpanel restart

4) Restart IMAP : /scripts/restartsrv courier

 

 

 

PHP script to take Database backup

<?php
$datestamp = date(“Y-m-d”);     // Current date to append to filename of backup file in format of YYYY-MM-DD

/* CONFIGURE THE FOLLOWING FOUR VARIABLES TO MATCH YOUR SETUP */
$dbuser = “database_username”;     // Database username
$dbpwd = “database_password”;     // Database password
$dbname = “database_name”;     // Database name. Use –all-databases if you have more than one
$filename = “backup-$datestamp.sql.gz”;     // The name (and optionally path) of the dump file

$command = “mysqldump -u $dbuser –password=$dbpwd $dbname | gzip > $filename”;
$result = passthru($command);
?>

 

 

Get mail statistics from your postfix mail logs

pflogsumm is designed to provide an over-view of postfix activity, with just enough detail to give the administrator a “heads up” for potential trouble spots.

1) wget http://pkgs.fedoraproject.org/repo/pkgs/postfix/pflogsumm-1.1.1.tar.gz/2f570477b2e205f9dfc1df13f00b5c0d/pflogsumm-1.1.1.tar.gz
tar xzvf pflogsumm-1.1.1.tar.gz
cd pflogsumm-1.1.1

2) Just pass the mail log to the perl script 🙂

cat /usr/local/psa/var/log/maillog | ./pflogsumm.pl

 

 

Convert UNIX Epoch Time on *NIX Log files

This is very simple with Perl, the part “([\d.]+)” is matching and then converting to localtime, then replacing the previous match, did 🙂

 

#cat input.txt;

[ 1393157883 ] [ alphacub_kjuy7f8 ] [ 925734 ] [ 133 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393163641 ] [ alphacub_kjuy7f8 ] [ 1001850 ] [ 62 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [  ] [  ]
[ 1393163821 ] [ alphacub_kjuy7f8 ] [ 797986 ] [ 147 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [  ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 1110922 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 1108704 ] [ 103 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 934769 ] [ 104 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 798257 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 798129 ] [ 104 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 797548 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 797086 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]

#cat input.txt | perl -ne ‘use POSIX; s/([\d.]+)/strftime “%Y-%m-%d %H:%M:%S”, localtime $1/e,print if /./’

[ 2014-02-23 06:18:03 ] [ alphacub_kjuy7f8 ] [ 925734 ] [ 133 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 07:54:01 ] [ alphacub_kjuy7f8 ] [ 1001850 ] [ 62 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ] [ ]
[ 2014-02-23 07:57:01 ] [ alphacub_kjuy7f8 ] [ 797986 ] [ 147 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 1110922 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 1108704 ] [ 103 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 934769 ] [ 104 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 798257 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 798129 ] [ 104 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 797548 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 797086 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]

Fun with BASH

# make fire
make: *** No rule to make target `fire’.  Stop.

# \(-
bash: (-: command not found

# sh
sh-4.1# PATH=pretending! /usr/bin/which sense
/usr/bin/which: no sense in (pretending!)

# nice man woman
No manual entry for woman

# [ Where is Deepak Tom?
bash: [: missing `]’

# make love
make: *** No rule to make target `love’.  Stop.

# touch /pussy
touch: cannot touch `/pussy’: Permission denied

WPScan – WordPress Security Scanner

WPScan is wonderful and super fast wordpress vulnerability scanner written in ruby language, sponsored by RandomStorm and hosted by Googlecode. It provides you an easy way to penetrate WordPress blogs using blackbox techniques.

1) If Ruby 1.9.2 or above is not there :-

curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm install 1.9.3
rvm use 1.9.3 –default

2) Installation
yum install gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel libcurl-devel
git clone https://github.com/wpscanteam/wpscan.git
gem install bundler && bundle install –without test development

3) Running

# ruby wpscan.rb –help
_______________________________________________________________
__          _______   _____
\ \        / /  __ \ / ____|
\ \  /\  / /| |__) | (___   ___  __ _ _ __
\ \/  \/ / |  ___/ \___ \ / __|/ _` | ‘_ \
\  /\  /  | |     ____) | (__| (_| | | | |
\/  \/   |_|    |_____/ \___|\__,_|_| |_|

WordPress Security Scanner by the WPScan Team
Version v2.3r997f4d3
Sponsored by the RandomStorm Open Source Initiative
@_WPScan_, @ethicalhack3r, @erwan_lr, pvdl, @_FireFart_
_______________________________________________________________

Help :

Some values are settable in conf/browser.conf.json :
user-agent, proxy, proxy-auth, threads, cache timeout and request timeout

–update   Update to the latest revision
–url   | -u <target url>  The WordPress URL/domain to scan.
–force | -f Forces WPScan to not check if the remote site is running WordPress.
–enumerate | -e [option(s)]  Enumeration.
option :
u        usernames from id 1 to 10
u[10-20] usernames from id 10 to 20 (you must write [] chars)
p        plugins
vp       only vulnerable plugins
ap       all plugins (can take a long time)
tt       timthumbs
t        themes
vt       only vulnerable themes
at       all themes (can take a long time)
Multiple values are allowed : “-e tt,p” will enumerate timthumbs and plugins
If no option is supplied, the default is “vt,tt,u,vp”

:
:

How to use this :-

1) Do ‘non-intrusive’ checks

ruby wpscan.rb –url http://www.example.com

2) Do wordlist password brute force on enumerated users using 50 threads

ruby wpscan.rb –url http://www.example.com –wordlist darkc0de.lst –threads 50

3) Do wordlist password brute force on the ‘admin’ username only

ruby wpscan.rb –url http://www.example.com –wordlist darkc0de.lst –username admin

4) Enumerate installed plugins

ruby wpscan.rb –url http://www.example.com –enumerate p

5) Run all enumeration tools

ruby wpscan.rb –url http://www.example.com –enumerate

6) Update WPScan

ruby wpscan.rb –update

7) Generate plugin list

ruby wpstools.rb –generate_plugin_list 150 up to 150 pages