analitics

Pages

Wednesday, August 16, 2017

The DreamPie - interactive shell .

The DreamPie was designed to bring you a great interactive shell Python experience.
There are two ways to install the DreamPie:
  • cloning the git repository;
  • downloading a release.
You can read about installation and download here.
To run it just try the dreampie.exe with your python shell, I used with my python 2.7 version:
C:\DreamPie>dreampie.exe --hide-console-window c:\Python27\python.exe
Let's see one screenshot of this running command:

Also, I tested with Python 3.6.2 and works well.
The main window is divided into the history box and the code box.
The history box lets you view previous commands and their output.
The code box for writing your code.
Some keys I used:

  • Ctr+Enter - run the code;
  • Ctr+up / down arrow - adds the previous / next source code;
  • Ctr+Space - show code completions;
  • Ctr+T - open a new tab code;
  • Ctr+W - close the tab code;
  • Ctr+S - save your work history into HTML file.

You can set your font, colors and many features.
I make the installation into C:\DreamPie folder, and comes with all these folders and files:
C:\DreamPie>tree
Folder PATH listing for volume free-tutorials
Volume serial number is 000000FF 0EB1:091D
C:.
├───data
│   ├───language-specs
│   ├───subp-py2
│   │   └───dreampielib
│   │       ├───common
│   │       └───subprocess
│   └───subp-py3
│       └───dreampielib
│           ├───common
│           └───subprocess
├───gtk-2.0
│   ├───cairo
│   ├───gio
│   ├───glib
│   ├───gobject
│   ├───gtk
│   └───runtime
│       ├───bin
│       ├───etc
│       │   ├───bash_completion.d
│       │   ├───fonts
│       │   ├───gtk-2.0
│       │   └───pango
│       ├───lib
│       │   ├───gdk-pixbuf-2.0
│       │   │   └───2.10.0
│       │   │       └───loaders
│       │   ├───glib-2.0
│       │   │   └───include
│       │   └───gtk-2.0
│       │       ├───2.10.0
│       │       │   └───engines
│       │       ├───include
│       │       └───modules
│       └───share
│           ├───aclocal
│           ├───dtds
│           ├───glib-2.0
│           │   ├───gdb
│           │   ├───gettext
│           │   │   └───po
│           │   └───schemas
│           ├───gtk-2.0
│           ├───gtksourceview-2.0
│           │   ├───language-specs
│           │   └───styles
│           ├───icon-naming-utils
│           ├───themes
│           │   ├───Default
│           │   │   └───gtk-2.0-key
│           │   ├───Emacs
│           │   │   └───gtk-2.0-key
│           │   ├───MS-Windows
│           │   │   └───gtk-2.0
│           │   └───Raleigh
│           │       └───gtk-2.0
│           └───xml
│               └───libglade
└───share
    ├───applications
    ├───man
    │   └───man1
    └───pixmaps

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