Friday, March 24, 2017

Take weather data with pyowm from openweathermap .

This tutorial shows you how to download and install the pyowm python module.
One of the great things about using this python module let you to provide data from openweathermap website (need to have one account).
PyOWM runs on Python 2.7 and Python 3.2+, and integrates with Django 1.10+ models.
All documentation can be found here.

The install is simple with pip , python 2.7 and Fedora 25.
[root@localhost mythcat]# pip install pyowm
Collecting pyowm
  Downloading pyowm-2.6.1.tar.gz (3.6MB)
    100% |████████████████████████████████| 3.7MB 388kB/s 
Building wheels for collected packages: pyowm
  Running bdist_wheel for pyowm ... done
  Stored in directory: /root/.cache/pip/wheels/9a/91/17/bb120c765f08df77645cf70a16aa372d5a297f4ae2be749e81
Successfully built pyowm
Installing collected packages: pyowm
Successfully installed pyowm-2.6.1
The source code is very simple just connect with API key and print data.
#/usr/bin/env python
#" -*- coding: utf-8 -*-
import pyowm

print " Have a account to and use with api key free or pro"
print " owm = pyowm.OWM(API_key='your-API-key', subscription_type='pro')"

owm = pyowm.OWM("327407589df060c7f825b63ec1d9a096")  
forecast = owm.daily_forecast("Falticeni,ro")
tomorrow = pyowm.timeutils.tomorrow()

observation = owm.weather_at_place('Falticeni,ro')
w = observation.get_weather()
print (w)                     
print " Weather details"
print " =============== "
print " Get cloud coverage"
print w.get_clouds() 
print " ----------------"                                     
print " Get rain volume"
print w.get_rain() 
print " ----------------"
print " Get snow volume"
print w.get_snow()                                       

print " Get wind degree and speed"
print w.get_wind() 
print " ----------------"                                      
print " Get humidity percentage"
print w.get_humidity()    
print " ----------------"                               
print " Get atmospheric pressure"
print w.get_pressure()                                   
print " ----------------"
print " Get temperature in Kelvin degs"
print w.get_temperature() 
print " ----------------"                              
print " Get temperature in Celsius degs"
print w.get_temperature(unit='celsius')
print " ----------------"                 
print " Get temperature in Fahrenheit degs"
print w.get_temperature('fahrenheit')                    
print " ----------------"
print " Get weather short status"
print w.get_status()                                     
print " ----------------"
print " Get detailed weather status"
print w.get_detailed_status()                           
print " ----------------"
print " Get OWM weather condition code"
print w.get_weather_code()                               
print " ----------------"
print " Get weather-related icon name"
print w.get_weather_icon_name()                          
print " ----------------"
print " Sunrise time (ISO 8601)"
print w.get_sunrise_time('iso')    
print " Sunrise time (GMT UNIXtime)"
print w.get_sunrise_time()                               
print " ----------------"
print " Sunset time (ISO 8601)"
print w.get_sunset_time('iso')  
print " Sunset time (GMT UNIXtime)"
print w.get_sunset_time()                          
print " ----------------"
print " Search current weather observations in the surroundings of"
print " Latitude and longitude coordinates for Fălticeni, Romania:"
observation_list = owm.weather_around_coords(47.46, 26.30)

Let's see and the result of running the python script for one random location:
[root@localhost mythcat]# python 
 Have a account to and use with api key free or pro
 owm = pyowm.OWM(API_key='your-API-key', subscription_type='pro')

 Weather details
 Get cloud coverage
 Get rain volume
 Get snow volume
 Get wind degree and speed
{u'speed': 5.7, u'deg': 340}
 Get humidity percentage
 Get atmospheric pressure
{'press': 1021, 'sea_level': None}
 Get temperature in Kelvin degs
{'temp_max': 287.15, 'temp_kf': None, 'temp': 287.15, 'temp_min': 287.15}
 Get temperature in Celsius degs
{'temp_max': 14.0, 'temp_kf': None, 'temp': 14.0, 'temp_min': 14.0}
 Get temperature in Fahrenheit degs
{'temp_max': 57.2, 'temp_kf': None, 'temp': 57.2, 'temp_min': 57.2}
 Get weather short status
 Get detailed weather status
few clouds
 Get OWM weather condition code
 Get weather-related icon name
 Sunrise time (ISO 8601)
2017-03-24 04:08:33+00
 Sunrise time (GMT UNIXtime)
 Sunset time (ISO 8601)
2017-03-24 16:33:59+00
 Sunset time (GMT UNIXtime)
 Search current weather observations in the surroundings of
 Latitude and longitude coordinates for Fălticeni, Romania:

Thursday, March 16, 2017

The tensorflow python module - part 003.

This short tutorial come to fix your work and help you with examples and tutorials.
You can look to the internet and you can search many examples and tutorials but you can get errors.
How to fix that:
The first step is to know what tensorflow version of you use.
[mythcat@localhost ~]$ python -c "import tensorflow; print(tensorflow.__version__)"
Then yo need to know what parts from tensorflow old version is deprecated from the last version.
One superannuated method is to fix old source code with this:
import tensorflow as tf
tf.scalar_summary = tf.summary.scalar
tf.merge_all_summaries = tf.summary.merge_all
tf.train.SummaryWriter = tf.summary.FileWriter
A better method is to fix your source code and read the documentation.

Have a better day possible.