This is a good online editor for python and google.
Like any online editor, some python modules are not available for online security reasons.
I do not know what python modules are implemented in this online editor.
I tested just sys and math python modules.
The Google Apps come with this tool integration like application for Google drive:
Edit your python file directly in your browser:
- Save it to Google Drive integrated with Google Drive
- Test it in your browser with Skulpt
- Use autocompletion code (CTRL+SPACE)
- No registration required and totally free
- Export your file
- Work offline
New python libraries partially supported: numpy, matplotlib.
Is a blog about python programming language. You can see my work with python programming language, tutorials and news.
Tuesday, October 10, 2017
Sunday, October 1, 2017
The capstone python module - disassembly framework.
The official python module comes with this info about this python module:
Capstone is a disassembly framework with the target of becoming the ultimate
the disasm engine for binary analysis and reversing in the security community.
Created by Nguyen Anh Quynh, then developed and maintained by a small community,
Capstone offers some unparalleled features:
- Support multiple hardware architectures: ARM, ARM64 (ARMv8), Mips, PPC & X86.
- Having clean/simple/lightweight/intuitive architecture-neutral API.
- Provide details on disassembled instruction (called “decomposer” by others).
- Provide semantics of the disassembled instruction, such as list of implicit
registers read & written.
- Implemented in pure C language, with lightweight wrappers for C++, Python,
Ruby, OCaml, C#, Java and Go available.
- Native support for Windows & *nix platforms (with OSX, Linux, *BSD & Solaris
have been confirmed).
- Thread-safe by design.
- Distributed under the open source BSD license.
Today I tested this python module with python version 2.7.
First I need to use a build of this python module from the official website.
I used binaries 32 bits like my python 2.7 and I tested with pip 2.7:
Capstone is a disassembly framework with the target of becoming the ultimate
the disasm engine for binary analysis and reversing in the security community.
Created by Nguyen Anh Quynh, then developed and maintained by a small community,
Capstone offers some unparalleled features:
- Support multiple hardware architectures: ARM, ARM64 (ARMv8), Mips, PPC & X86.
- Having clean/simple/lightweight/intuitive architecture-neutral API.
- Provide details on disassembled instruction (called “decomposer” by others).
- Provide semantics of the disassembled instruction, such as list of implicit
registers read & written.
- Implemented in pure C language, with lightweight wrappers for C++, Python,
Ruby, OCaml, C#, Java and Go available.
- Native support for Windows & *nix platforms (with OSX, Linux, *BSD & Solaris
have been confirmed).
- Thread-safe by design.
- Distributed under the open source BSD license.
Today I tested this python module with python version 2.7.
First I need to use a build of this python module from the official website.
I used binaries 32 bits like my python 2.7 and I tested with pip 2.7:
C:\Python27\Scripts>pip install capstone
Requirement already satisfied: capstone in c:\python27\lib\site-packages
Let's make a simple test with this python module:
C:\Python27>python.exe
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from capstone import (
... Cs,
... CS_ARCH_X86,
... CS_MODE_32,
... CS_OPT_SYNTAX_ATT,
... )
>>> mode=Cs(CS_ARCH_X86, CS_MODE_32)
>>> mode.syntax = CS_OPT_SYNTAX_ATT
>>> def D_ASM(code):
... for address, size, mnemonic, op_str in mode.disasm_lite(code, offset=0x08048060):
... print("0x{0:x}\t{1:d}\t{2:s}\t{3:s}".format(address, size,mnemonic, op_str))
...
>>> D_ASM(b"\xe1\x0b\x40\xb9\x20\x04\x81\xda\x20\x08\x02\x8b")
0x8048060 2 loope 0x804806d
0x8048062 1 incl %eax
0x8048063 5 movl $0xda810420, %ecx
0x8048068 2 andb %cl, (%eax)
It seems to work very well.
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
capstone,
python,
python modules,
tutorial,
tutorials
Friday, September 22, 2017
The python-vlc python module.
The python module for vlc is named python-vlc.
This python module let you test libvlc API like the VLC video player.
You can install it easily with pip python tool.
Another simple example:
This python module let you test libvlc API like the VLC video player.
You can install it easily with pip python tool.
C:\Python27\Scripts>pip2.7.exe install python-vlc
Collecting python-vlc
Downloading python-vlc-1.1.2.tar.gz (201kB)
100% |################################| 204kB 628kB/s
Installing collected packages: python-vlc
Running setup.py install for python-vlc ... done
Successfully installed python-vlc-1.1.2
Let's see a simple example with this python module:import os
import sys
import vlc
import pygame
def call_vlc(self, player):
player.get_fps()
player.get_time()
if len( sys.argv )< 2 or len( sys.argv )> 3:
print 'Help: python vlc_001.py your_video.mp4'
else:
pygame.init()
screen = pygame.display.set_mode((800,600),pygame.RESIZABLE)
pygame.display.get_wm_info()
pygame.display.get_driver()
# get path to movie specified as command line argument
movie = os.path.expanduser(sys.argv[1])
# see if movie is accessible
if not os.access(movie, os.R_OK):
print('Error: %s wrong read file: ' % movie)
sys.exit(1)
# make instane of VLC and create reference to movie.
vlcInstance = vlc.Instance()
media = vlcInstance.media_new(movie)
# make new instance of vlc player
player = vlcInstance.media_player_new()
# start with a callback
em = player.event_manager()
em.event_attach(vlc.EventType.MediaPlayerTimeChanged, \
call_vlc, player)
# set pygame window id to vlc player
win_id = pygame.display.get_wm_info()['window']
if sys.platform == "win32": # for Windows
player.set_hwnd(win_id)
# load movie into vlc player instance
player.set_media(media)
# quit pygame mixer to allow vlc full access to audio device
pygame.mixer.quit()
# start movie play
player.play()
while player.get_state() != vlc.State.Ended:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(2)
The base of this python script is to make an instance of vlc and put into the pygame display.Another simple example:
C:\Python27>python.exe
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vlc
>>> inst = vlc.Instance()
Warning: option --plugin-path no longer exists.
Warning: option --plugin-path no longer exists.
>>> med = inst.media_new('rain.mp4')
>>> p = med.player_new_from_media()
>>> p.play()
0
>>>
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
python,
python modules,
python-vlc,
tutorial,
tutorials,
vlc
Tuesday, September 19, 2017
The numba python module - part 002 .
Today I tested how fast is jit from numba python and fibonacci math function.
You will see strange output I got for some values.
First example:
The jit - just-in-time compile is very fast.
Let's see if the python source code may slow down.
Let's see the new source code with jit will not work well:
The first problem is:
The problem is that numba can't intuit the type of lookup. If you put a print nb.typeof(lookup) in your method, you'll see that numba is treating it as an object, which is slow.
The second problem is the output but can be from the same reason.
I test with value 5 and the result is :
You will see strange output I got for some values.
First example:
import numba
from numba import jit
from timeit import default_timer as timer
def fibonacci(n):
a, b = 1, 1
for i in range(n):
a, b = a+b, a
return a
fibonacci_jit = jit(fibonacci)
start = timer()
fibonacci(100)
duration = timer() - start
startnext = timer()
fibonacci_jit(100)
durationnext = timer() - startnext
print(duration, durationnext)
The result of this run is:C:\Python27>python numba_test_003.py
(0.00018731270733896962, 0.167499256682878)
C:\Python27>python numba_test_003.py
(1.6357787798437412e-05, 0.1683614083221368)
C:\Python27>python numba_test_003.py
(2.245186560569841e-05, 0.1758382003097716)
C:\Python27>python numba_test_003.py
(2.3093347480146938e-05, 0.16714964906130353)
C:\Python27>python numba_test_003.py
(1.5395564986764625e-05, 0.17471143739730277)
C:\Python27>python numba_test_003.py
(1.5074824049540363e-05, 0.1847134227837042)
As you can see the fibonacci function is not very fast.The jit - just-in-time compile is very fast.
Let's see if the python source code may slow down.
Let's see the new source code with jit will not work well:
import numba
from numba import jit
from timeit import default_timer as timer
def fibonacci(n):
a, b = 1, 1
for i in range(n):
a, b = a+b, a
return a
fibonacci_jit = jit(fibonacci)
start = timer()
print fibonacci(100)
duration = timer() - start
startnext = timer()
print fibonacci_jit(100)
durationnext = timer() - startnext
print(duration, durationnext)
The result is this:C:\Python27>python numba_test_003.py
927372692193078999176
1445263496
(0.0002334994022992635, 0.17628787910376)
C:\Python27>python numba_test_003.py
927372692193078999176
1445263496
(0.0006886307922204926, 0.17579169287387408)
C:\Python27>python numba_test_003.py
927372692193078999176
1445263496
(0.0008105123483657127, 0.18209553525407973)
C:\Python27>python numba_test_003.py
927372692193078999176
1445263496
(0.00025466830415606486, 0.17186550306131188)
C:\Python27>python numba_test_003.py
927372692193078999176
1445263496
(0.0007348174871807866, 0.17523103771560608)
The result for value 100 is not the same: 927372692193078999176 and 1445263496.The first problem is:
The problem is that numba can't intuit the type of lookup. If you put a print nb.typeof(lookup) in your method, you'll see that numba is treating it as an object, which is slow.
The second problem is the output but can be from the same reason.
I test with value 5 and the result is :
C:\Python27>python numba_test_003.py
13
13
13
13
(0.0007258367409385072, 0.17057997338491704)
C:\Python27>python numba_test_003.py
13
13
(0.00033709872502270044, 0.17213235952108247)
C:\Python27>python numba_test_003.py
13
13
(0.0004836773333341886, 0.17184433415945508)
C:\Python27>python numba_test_003.py
13
13
(0.0006854233828482501, 0.17381272129120037)
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
numba,
python,
python modules,
tutorial,
tutorials
Monday, September 18, 2017
The numba python module - part 001 .
Today I tested the numba python module.
This python module allows us to speed up applications with high-performance functions written directly in Python.
The numba python module works by generating optimized machine code using the LLVM compiler infrastructure at import time, runtime, or statically.
The code can be just-in-time compiled to native machine instructions, similar in performance to C, C++ and Fortran.
For the installation I used the pip tool:
The example source code is:
First, compiling takes time, but will work especially for small functions.
The Numba python module tries to do its best by caching compilation as much as possible though.
Another note: not all code is compiled equally.
This python module allows us to speed up applications with high-performance functions written directly in Python.
The numba python module works by generating optimized machine code using the LLVM compiler infrastructure at import time, runtime, or statically.
The code can be just-in-time compiled to native machine instructions, similar in performance to C, C++ and Fortran.
For the installation I used the pip tool:
C:\Python27>cd Scripts
C:\Python27\Scripts>pip install numba
Collecting numba
Downloading numba-0.35.0-cp27-cp27m-win32.whl (1.4MB)
100% |################################| 1.4MB 497kB/s
...
Installing collected packages: singledispatch, funcsigs, llvmlite, numba
Successfully installed funcsigs-1.0.2 llvmlite-0.20.0 numba-0.35.0 singledispatch-3.4.0.3
C:\Python27\Scripts>pip install numpy
Requirement already satisfied: numpy in c:\python27\lib\site-packages
The example test from official website working well:The example source code is:
from numba import jit
from numpy import arange
# jit decorator tells Numba to compile this function.
# The argument types will be inferred by Numba when function is called.
@jit
def sum2d(arr):
M, N = arr.shape
result = 0.0
for i in range(M):
for j in range(N):
result += arr[i,j]
return result
a = arange(9).reshape(3,3)
print(sum2d(a))
The result of this run python script is:C:\Python27>python.exe numba_test_001.py
36.0
Another example using just-in-time compile is used with Numba’s jit function:import numba
from numba import jit
def fibonacci(n):
a, b = 1, 1
for i in range(n):
a, b = a+b, a
return a
print fibonacci(10)
fibonacci_jit = jit(fibonacci)
print fibonacci_jit(14)
Also, you can use jit is as a decorator:@jit
def fibonacci_jit(n):
a, b = 1, 1
for i in range(n):
a, b = a+b, a
return a
Numba is a complex python module because use compiling.First, compiling takes time, but will work especially for small functions.
The Numba python module tries to do its best by caching compilation as much as possible though.
Another note: not all code is compiled equally.
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
numba,
python,
python modules,
tutorial,
tutorials
YARA another python module - part 002 .
This is another part of YARA python tutorial and the goal of this part is to install the Yara modules.
This is another python module about Yara named yara-python from VirusTotal.
The last tutorial uses the Yara python module.
The YARA modules provide extending features to allow us to define data structures and functions which can be used in your rules to express more complex conditions.
You can also write your own modules.
Some known modules used by YARA are:
I will solve this problem in the future.
You can also write your own modules ( see this webpage ).
This is another python module about Yara named yara-python from VirusTotal.
The last tutorial uses the Yara python module.
The YARA modules provide extending features to allow us to define data structures and functions which can be used in your rules to express more complex conditions.
You can also write your own modules.
Some known modules used by YARA are:
- PE
- ELF
- Cuckoo
- Magic
- Hash
- Math
>>> yara.__version__
'3.6.3'
The Cuckoo module enables you to create YARA rules based on behavioral information generated by a Cuckoo sandbox.C:\Python27\Scripts>pip install yara-python
Collecting yara-python
Downloading yara_python-3.6.3-cp27-cp27m-win32.whl (606kB)
100% |################################| 614kB 1.3MB/s
Installing collected packages: yara-python
Successfully installed yara-python-3.6.3
pip install cuckoo
Collecting cuckoo
Downloading Cuckoo-2.0.4.4.tar.gz (3.1MB)
100% |################################| 3.1MB 255kB/s
...
Successfully installed Mako-1.0.7 alembic-0.8.8 androguard-3.0.1 beautifulsoup4-4.5.3
capstone-windows-3.0.4 chardet-2.3.0 click-6.6 colorama-0.3.7 cuckoo-2.0.4.4 django-1.8.4
django-extensions-1.6.7 dpkt-1.8.7 ecdsa-0.13 egghatch-0.2.1 elasticsearch-5.3.0
flask-sqlalchemy-2.1 httpreplay-0.2.1 jsbeautifier-1.6.2 jsonschema-2.6.0 olefile-0.43
oletools-0.42 peepdf-0.3.6 pefile2-1.2.11 pillow-3.2.0 pyelftools-0.24 pymisp-2.4.54
pymongo-3.0.3 python-dateutil-2.4.2 python-editor-1.0.3 python-magic-0.4.12 pythonaes-1.0
requests-2.13.0 sflock-0.2.16 sqlalchemy-1.0.8 tlslite-ng-0.6.0 unicorn-1.0.1 wakeonlan-0.2.2
Let's test this python module:
>>> import cuckoo
>>> from cuckoo import *
>>> dir(cuckoo)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__',
'auxiliary', 'common', 'compat', 'core', 'machinery', 'misc', 'plugins', 'processing',
'reporting', 'signatures', 'web']
Let's test some yara modules:>>> import yara
>>> rule = yara.compile(source='import \"pe\"')
>>> rule = yara.compile(source='import \"elf\"')
>>> rule = yara.compile(source='import \"cuckoo\"')
>>> rule = yara.compile(source='import \"math\"')
I could not use the YARA modules: hash and magic.I will solve this problem in the future.
You can also write your own modules ( see this webpage ).
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
cuckoo,
python,
python modules,
tutorial,
tutorials,
yara
Friday, September 1, 2017
The beauty of Python: subprocess module - part 004 .
This series of python tutorials that we started at the beginning of this blog and called "The beauty of Python" is part of the series of tutorials aimed at the simplicity and beauty of the Python programming language.
The main goal for us is how to use this programming language in everyday life with different tasks.
Today I will come up with examples to cover this goal and show you how to use the subprocess python module.
get and print the hostname :
print the output of ping command :
print the output of dir command :
run the python script like python shell :
The main goal for us is how to use this programming language in everyday life with different tasks.
Today I will come up with examples to cover this goal and show you how to use the subprocess python module.
- using the PowerShell with python :
>>> import subprocess
>>> process=subprocess.Popen(["powershell","Get-Childitem C:\\Windows\\*.log"],stdout=subprocess.PIPE);
>>> result=process.communicate()[0]
>>> print result
>>> print subprocess.check_output("hostname")
>>> print subprocess.check_output("ping localhost", shell=True)
>>> cmd = 'dir *'
>>> supcmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> print supcmd.communicate()[0]
>>> import sys
>>> import subprocess
>>> pid = subprocess.Popen([sys.executable, "calc.py"])
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
python,
python modules,
subprocess,
tutorial,
tutorials
Monday, August 21, 2017
Using pip into shell to install and use pymunk.
The tutorial for today will show how to use pip into the python shell to install a python package.
The first step is shown in the next image:
The first step is shown in the next image:
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
pip,
pip2.7,
pymunk,
python,
python modules,
tutorial,
tutorials
Friday, August 18, 2017
The Google Cloud SDK - part 002 .
The next part of my tutorials about the Google Cloud SDK comes with some info about the project.
As you know I used the default sample app engine hello word standard application.
The goal is to understand how it works by working with Google's documentation and examples.
Into this project folder we have this files:
First is app.yaml and come with:
You can have many application-level configuration files (dispatch.yaml, cron.yaml, index.yaml, and queue.yaml).
This all type of configuration files are included in the top level app directory ( in this case: hello_world).
Let's see some common gcloud commands:
First, change the text from main.py file with something else:
You can read about this files into google documentation page - here.
Also some gcloud commands and reference you can read here.
As you know I used the default sample app engine hello word standard application.
The goal is to understand how it works by working with Google's documentation and examples.
Into this project folder we have this files:
08/17/2017 11:12 PM 98 app.yaml
08/17/2017 11:12 PM 854 main.py
08/17/2017 11:12 PM 817 main_test.py
Let's see what these files contain:First is app.yaml and come with:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
The next is main.py file:# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello, World!')
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
The last from this folder is main_test.py :# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import webtest
import main
def test_get():
app = webtest.TestApp(main.app)
response = app.get('/')
assert response.status_int == 200
assert response.body == 'Hello, World!'
The app.yaml file is used to configure your App Engine application's settings of the project.You can have many application-level configuration files (dispatch.yaml, cron.yaml, index.yaml, and queue.yaml).
This all type of configuration files are included in the top level app directory ( in this case: hello_world).
Let's see some common gcloud commands:
- gcloud app deploy --project XXXXXX - deploy your project;
- gcloud app browse - show your project running into your browser;
- gcloud components list - show all available components;
- gcloud components update - update all gcloud components;
- gcloud projects list --limit=10 - show all projects with a limit number;
First, change the text from main.py file with something else:
self.response.write('Hello, World!')
Now use this commands:C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app deploy
C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app browse
The result is shown in your browser.You can read about this files into google documentation page - here.
Also some gcloud commands and reference you can read here.
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
google,
Google Cloud SDK,
python,
python modules,
SDK,
tutorial,
tutorials
Thursday, August 17, 2017
The Google Cloud SDK - part 001 .
This tutorial will cover this steps into development with Google Cloud SDK and Python version 2.7:
First, you need to download the Google Cloud SDK and run it.
After GUI install a window command will ask you to set the default project for your work.
This will start an online tutorial into the right area of the screen with all commands and steps for your Google Cloud SDK online project.
Follow this steps and in the end will see how the online Google Cloud SDK project will show: Hello, World! into your browser.
The next step is to make a local project and run it.
You can use the python docs sample from GoogleCloudPlatform but is not the same with the online example.
To download the GoogleCloudPlatform sample use git command:
- install the Google Cloud SDK on the computer;
- make settings online for your Google project to use Google Cloud SDK;
- run the online project of Google Cloud SDK;
- make setting into your computer to run the local project ;
First, you need to download the Google Cloud SDK and run it.
After GUI install a window command will ask you to set the default project for your work.
Welcome to the Google Cloud SDK! Run "gcloud -h" to get the list of available commands.
---
Welcome! This command will take you through the configuration of gcloud.
Your current configuration has been set to: [default]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic (1/1 checks) passed.
You must log in to continue. Would you like to log in (Y/n)? Y
...
The next step is to start online to deploying a Hello World app with: Deploy a Hello World app:This will start an online tutorial into the right area of the screen with all commands and steps for your Google Cloud SDK online project.
Follow this steps and in the end will see how the online Google Cloud SDK project will show: Hello, World! into your browser.
The next step is to make a local project and run it.
You can use the python docs sample from GoogleCloudPlatform but is not the same with the online example.
To download the GoogleCloudPlatform sample use git command:
C:\Python27>git clone https://github.com/GoogleCloudPlatform/python-docs-samples
Cloning into 'python-docs-samples'...
remote: Counting objects: 12126, done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 12126 (delta 1), reused 10 (delta 1), pack-reused 12106
Receiving objects: 100% (12126/12126), 3.37 MiB | 359.00 KiB/s, done.
Resolving deltas: 100% (6408/6408), done.
C:\Python27>cd python-docs-samples/appengine/standard/hello_world
To start this sample into your google project you need to use this:C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app deploy app.yaml --project encoded-metrics-147522
Services to deploy:
descriptor: [C:\Python27\python-docs-samples\appengine\standard\hello_world\app.yaml]
source: [C:\Python27\python-docs-samples\appengine\standard\hello_world]
target project: [encoded-metrics-147522]
target service: [default]
target version: [20170817t234925]
target url: [https://encoded-metrics-147522.appspot.com]
Do you want to continue (Y/n)? Y
Beginning deployment of service [default]...
#============================================================#
#= Uploading 5 files to Google Cloud Storage =#
#============================================================#
File upload done.
Updating service [default]...done.
Waiting for operation [apps/encoded-metrics-147522/operations/XXXXXX] to complete...done.
Updating service [default]...done.
Deployed service [default] to [https://XXXXXX.appspot.com]
You can stream logs from the command line by running:
$ gcloud app logs tail -s default
To view your application in the web browser run:
$ gcloud app browse
C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app browse
Opening [https://XXXXXX.appspot.com] in a new tab in your default browser.
C:\Python27\python-docs-samples\appengine\standard\hello_world>
This will start your application with the text - Hello, World! into your browser address bar with this web address: XXXXXX.appspot.com.
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
google,
Google Cloud SDK,
python,
python modules,
SDK,
tutorial,
tutorials
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:
To run it just try the dreampie.exe with your python shell, I used with my python 2.7 version:
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:
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:
There are two ways to install the DreamPie:
- cloning the git repository;
- downloading a release.
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
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
dreampie,
interactive shell,
python,
python 3,
python modules,
shell,
tutorial,
tutorials
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.
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.
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:
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:
you are:
atmospheric model based on data taken in the United States:
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 whereyou 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 anatmospheric 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.
Posted by
Cătălin George Feștilă
Labels:
2.7,
2017,
pysolar,
python,
python 3,
python modules,
tutorial,
tutorials
Subscribe to:
Posts (Atom)