login
   

Networks

Databases

Programming

Consulting

Security

Data Recovery

 

 

Home

Contact us
 
Databases
Networks
Programming
Security
Data Recovery
Consulting
Repair
Websites
Marketing
Training
 
References
About Us
 
Python programming for Long Island New York
 
 
 A rising star of languages, Python is well used now for artificial intelligence programming and machine learning ( which we’ve experimented with ) as well as web page development with Flask and other frameworks (which we’ve also worked with). Our main use for it here has been data processing with MYSQL


 

For example:

 

First a shell script called from a Cron job:
 

#!/bin/bash 

#-e  
#-xv
/usr/bin/uptime >> /usr/idlesave/itsrunning1.txt
python gasfieldupdate.py
python gaspriceupdate.py
python fleetsavingsupdate.py
python setGhostMiles.py
/usr/bin/uptime >> /usr/idlesave/it-ran1.txt

 

And, for a simple example (not cleaned up for the web):
 
import mysql.connector
from mysql.connector import Error
def my_function(id):
    a = 0
    try:
        connection = mysql.connector.connect(host='222.22.22.22',
                                             database='l2222',
                                             user='2222',
                                             password='22', charset='utf8')

 
        # sql = "select sum(time) from idletimehistory AS  vsum  where vehicleid= %s  and idle=0"
        sql = "SELECT SUM(gas*.84*(TIME/3600)) FROM idlexxxx WHERE vehicleid=%s AND idle =0"
        adr = (id,)
        cursor = connection.cursor()
        cursor.execute(sql, adr)
        records = cursor.fetchall()
        # print("Total number of rows in Laptop is: ", cursor.rowcount)
        print("\nPrinting each  record")
        for row in records:
            a = a + 1
            vid = row[0]
        
            print("sum = ", id, row[0], )
 
        sql2 = "update vehicles set savings = %s where id = %s "
        adr2 = (vid, id,)
        cursor.execute(sql2, adr2)
        connection.commit()
 
    except Error as e:
        print("Error reading data from MySQL table", e)
 
a = 0
try:
 
    connection = mysql.connector.connect(host='12222226',
                                         database='2222',
                                         user='2222',
                                         password='22', charset='utf8')
    sql_select_Query = "select id from vehicles"
    cursor = connection.cursor()
    cursor.execute(sql_select_Query)
    records = cursor.fetchall()
    print("Total number of rows in vehicles is: ", cursor.rowcount)

 
    print("\nPrinting each laptop record")
    for row in records:
        a = a + 1
        vid = row[0]
 
        my_function(vid)  # call the function with the id number

 
except Error as e:
    print("Error reading data from MySQL table", e)
finally:
    if (connection.is_connected()):
        connection.close()
        cursor.close()
        print("MySQL connection is closed.", a)
        print(a)
 
 

Home

   

Contact us