analitics

Pages

Saturday, August 12, 2017

The flickrapi python module .

Flickr is one of the most popular photo hosting websites.
The development team let us test the API and with a plenty of opportunities to use Flickr.
Today I tested the flickrapi python module.
I used the python 2.7 version and pip to install it.
C:\>cd Python27

C:\Python27>cd Scripts

C:\Python27\Scripts>pip install flickrapi
Collecting flickrapi
  Downloading flickrapi-2.3-py2-none-any.whl
...
  Running setup.py install for oauthlib ... done
Successfully installed flickrapi-2.3 oauthlib-2.0.2 requests-oauthlib-0.8.0 requests-toolbelt-0.8.0
You need to have/make an API key into Account Settings, see my API key:
Your API keys You have 1 API key registered to this account.
Then you need to know your user_id.
This can be done by asking api online with your username and the result will be something like this: xxxxxxxx@Nxx.
The example I used is from documentation and I change with my API key to test this python module.


>>>import flickrapi
>>>
>>>api_key = u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
>>>api_secret = u'YYYYYYYYYYYYYYYYYYYYYYY'
>>>
>>>flickr = flickrapi.FlickrAPI(api_key, api_secret)
>>>photos = flickr.photos.search(user_id='xxxxxxxx@Nxx', per_page='10')
>>>sets = flickr.photosets.getList(user_id='xxxxxxxx@Nxx')
>>> dir(sets)
['__class__', '__contains__', '__copy__', '__deepcopy__', '__delattr__', '__delitem__', '__doc__',
 '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', 
'__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__',
 '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '_init', 'addnext', 'addprevious', 
'append', 'attrib', 'base', 'clear', 'cssselect', 'extend', 'find', 'findall', 'findtext', 'get', 
'getchildren', 'getiterator', 'getnext', 'getparent', 'getprevious', 'getroottree', 'index', 'insert',
 'items', 'iter', 'iterancestors', 'iterchildren', 'iterdescendants', 'iterfind', 'itersiblings', 
'itertext', 'keys', 'makeelement', 'nsmap', 'prefix', 'remove', 'replace', 'set', 'sourceline', 
'tag', 'tail', 'text', 'values', 'xpath']
>>> print sets.attrib['stat']
ok
>>> sets.find('photosets').attrib
{'total': '4', 'perpage': '4', 'page': '1', 'pages': '1'}
>>> print "upload a photo via browser - set permisions"
upload a photo via browser - set permisions
>>> flickr.authenticate_via_browser(perms='write')
127.0.0.1 - - [12/Aug/2017 22:05:00] "GET /?oauth_token=xxxxxx-xxxxx&oauth_verifier=xxxxxxxxx HTTP/1.1" 200 -
>>> flickr.upload("0001.gif")

>>> print "try show title of my photos and id"
try show title of my photos and id
for child in photos:
  for i in child:
    photo_set = []
    try:
      title = i.attrib['title']
      print title
    except Exception, e:
      print e
    sets = flickr.photos_getAllContexts(photo_id = i.attrib["id"])
    for j in sets:
      if j.tag == "set":
        photo_set.append(j.attrib["id"])
        print photo_set
The result is my photos title and id:
painting_world
DSC_0112
['72157632077721715']
DSC_0111
['72157632077721715']
DSC_0113
['72157632077721715']
DSC_0110
['72157632077721715']
DSC_0094
['72157632077721715']
DSC_0091
['72157632077721715']
DSC_0108
I tested wit Python 362 version:
C:\Python27>cd ..

C:\>cd Python362

C:\Python362>cd Scripts

C:\Python362\Scripts>pip install flickrapi
Collecting flickrapi
  Downloading flickrapi-2.3-py3-none-any.whl
Collecting requests>=2.2.1 (from flickrapi)
  Downloading requests-2.18.3-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 1.4MB/s
Collecting six>=1.5.2 (from flickrapi)
  Using cached six-1.10.0-py2.py3-none-any.whl
...
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 flickrapi-2.3 idna-2.5 oauthlib-2.0.2 requests-2.18.3
 requests-oauthlib-0.8.0 requests-toolbelt-0.8.0 six-1.10.0 urllib3-1.22

Thursday, August 10, 2017

The pysolar - python module.

Today I tested another python module named pysolar with python 2.7 and 3.6.2 versions.
You can read more about this python module here:
Pysolar is a collection of Python libraries for simulating the irradiation of any point on earth by the sun. It includes code for extremely precise ephemeris calculations and more.
Using pip under Windows OS to install this python module:
C:\Python27\Scripts>pip install pysolar
...
Successfully built pysolar
Installing collected packages: pysolar
Successfully installed pysolar-0.7
I try also with python 3.6.2 version:
C:\Python362\Scripts>pip install pysolar
Collecting pysolar
  Using cached pysolar-0.7.tar.gz
Installing collected packages: pysolar
  Running setup.py install for pysolar ... done
Successfully installed pysolar-0.7
Let's start with a simple example to calculate the angle between the sun and a plane tangent to the earth where
you are:
C:\Python362>python.exe
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysolar.solar import *
>>> import datetime
>>> my_data = datetime.datetime.now()
>>> print (my_data)
2017-08-10 18:12:01.997373
>>> get_altitude_fast(47.4616,26.3015,datetime.datetime.now())
-6.393190003993212
Let's try the scattering of light by the atmosphere, though it uses an
atmospheric model based on data taken in the United States:
>>> latitude_deg =47.2741
>>> longitude_deg = 26.185
>>> my_data = datetime.datetime.now()
>>> altitude_deg = get_altitude(latitude_deg, longitude_deg,my_data)
C:\Python362\lib\site-packages\pysolar\time.py:105: UserWarning: I don't know about leap seconds after 2015
  (leap_seconds_base_year + len(leap_seconds_adjustments) - 1)
>>> azimuth_deg = get_azimuth(latitude_deg, longitude_deg,  my_data)
>>> radiation.get_radiation_direct(my_data, altitude_deg)
634.4916522219954
About this issue:I don't know about leap seconds after 2015 read here.