YanyangChen / stock_analysis

0 stars 0 forks source link

Use python to get and update data #2

Open YanyangChen opened 6 years ago

YanyangChen commented 6 years ago

reason: 1.python can be triggered by java 2.python is more intuitive to shell 3.Easier to be aqcuired by different platforms 4.Easier to implement machine learning and analytical modules 5.Open source community is more available 6.Python is easier to get system variables and plot charts 7.https://realpython.com/python3-object-oriented-programming/#what-is-object-oriented-programming-oop

YanyangChen commented 6 years ago

import sqlite3 from sqlite3 import Error

def create_connection(db_file): """ create a database connection to the SQLite database specified by the db_file :param db_file: database file :return: Connection object or None """ try: conn = sqlite3.connect(db_file) return conn except Error as e: print(e)

return None

def select_all_tasks(conn): """ Query all rows in the tasks table :param conn: the Connection object :return: """ cur = conn.cursor() cur.execute("SELECT * FROM STOCKS")

rows = cur.fetchall()

for row in rows:
    print(row)

def select_task_by_priority(conn, priority): """ Query tasks by priority :param conn: the Connection object :param priority: :return: """ cur = conn.cursor() cur.execute("SELECT * FROM STOCKS")

rows = cur.fetchall()

for row in rows:
    print(row)

def main(): database = "/Users/chenyanyang/tst.db"

# create a database connection
conn = create_connection(database)
with conn:
    # print("1. Query task by priority:")
    # select_task_by_priority(conn, 1)

    print("2. Query all tasks")
    select_all_tasks(conn)

if name == 'main': main()

YanyangChen commented 6 years ago

import sqlite3 from sqlite3 import Error

http://www.sqlitetutorial.net/sqlite-python/sqlite-python-select/

def create_connection(db_file): """ create a database connection to the SQLite database specified by the db_file :param db_file: database file :return: Connection object or None """ try: conn = sqlite3.connect(db_file) return conn except Error as e: print(e)

return None

def select_all_tasks(conn): """ Query all rows in the tasks table :param conn: the Connection object :return: """ cur = conn.cursor() cur.execute("SELECT * FROM STOCKS")

rows = cur.fetchall()

for row in rows:
    print(row)

def select_task_by_priority(conn, priority): """ Query tasks by priority :param conn: the Connection object :param priority: :return: """ cur = conn.cursor() cur.execute("SELECT * FROM STOCKS")

rows = cur.fetchall()

for row in rows:
    print(row)

def main(): database = "/Users/chenyanyang/tst.db"

# create a database connection
conn = create_connection(database)
with conn:
    # print("1. Query task by priority:")
    # select_task_by_priority(conn, 1)

    print("2. Query all tasks")
    select_all_tasks(conn)

if name == 'main': main()