Almost 8 years ago I am learning about wonderful programming language, and in this last year I have been watching your Fruits.
As a programmer you earn very well and I simply do what I like, from learning to create games to extract data with a script from one app to another.
When I talk about Python I want to tell you how good it is with me, it's like talking about how good God is with my friends, although python does not compare.
I write here to encourage others to write in Steemit, either by Joby or to earn some money, although I think the best way to earn money is to share the conviction of your passions and ideas.
It does not matter if you are learning a new passion, sit down write and tell us what you like.
Python is very powerful and anyone with the right motivation can learn, for example every day there are problems that seem unique because of the complicated and repetitive or routine tasks, with python are solved only thinking about Python, that's what I want to talk about today .
Look at the dimensions of the Problem:
Currently I am programming on an ERP called ODOO with Python as Backend, that is to say as the main programming language, do not be scared we will focus on the simplicity of Python not on ODOO.
I have requested that you send me some files that contain ticket information of the airline that I am integrating to ODOO with a function that I will call every so often, and good for more than I have asked them to different folders they have sent them to the same folder .
In the end I have many different files in a folder and I have to classify them, and I do not have a graphical interface, what has happened to me is to use Linux Cron since the VPS is in Ubuntu Server, but Cron sometimes gets involved and has left me a bit wrong with the tests, so right now I thought about creating a function that runs from ODOO and is Bash in Python embedded using the system library os.
import os, subprocess
With this library we are going to embed the Bash code or what we use in the terminal with Python, for the purposes that I need, it would look something like this:
import os, subprocess
os.system("ls /home/odoo/archivos_kiu/ | grep 'CMAS.zip'| grep 'CRS' > /home/odoo/archivos_kiu/CMAS_a_Extraer.txt")
archivo='/home/odoo/archivos_kiu/CMAS_a_Extraer.txt'
archi=open(archivo,'r')
lineas=archi.read().splitlines()
if len(lineas)> 0:
iteracion = 0
for archivo_cmas_a_extraer in lineas:
arch_a_extraer = '/home/odoo/archivos_kiu/'+archivo_cmas_a_extraer
cmas_a_extraer_descomprimido = archivo_cmas_a_extraer[0:-4]
subprocess.call(['unzip', arch_a_extraer])
subprocess.call(['mv', arch_a_extraer, '/home/odoo/archivos_kiu/CRS_comprimidos'])
subprocess.call(['mv', cmas_a_extraer_descomprimido, '/home/odoo/archivos_kiu/CRS_descomprimidos'])
print "MOVIENDO ARCHIVO A /home/odoo/archivos_kiu/CRS_descomprimidos", cmas_a_extraer_descomprimido
print "MOVIENDO ARCHIVO A /home/odoo/archivos_kiu/CRS_comprimidos", arch_a_extraer
And what the program does is list the files in /home/odoo /archivos_kiu/ that contain 'CMAS.zip' and with the piper we look again for those that are CRS and with the symbol > we send the output to the file /home/odoo/archivos_kiu / CMAS_a_Extraer.txt that will be read later and file to file unzip it with python and bash and then move one to the compressed and the other to the unzipped folder, then the system does other things but that is another thing :D .
Greetings here we could see the power of Python for what we need
God bless you
Fuente de la imagen: https://www.function1.com/2015/09/splunk-sdk-for-python-getting-data-in