Skip to content

Instantly share code, notes, and snippets.

@senthilsweb
Created December 15, 2019 01:18
Show Gist options
  • Save senthilsweb/2b860519fe703114322bd86dd02af98a to your computer and use it in GitHub Desktop.
Save senthilsweb/2b860519fe703114322bd86dd02af98a to your computer and use it in GitHub Desktop.
# -----------------------------------------------------
# Query sqlite using sqlalchemy
# dependencies: Pandas & sqlalchemy
#
# -----------------------------------------------------
# {Modification Log}
# -----------------------------------------------------
# Author: Senthilnathan
# Maintainer: {maintainer}
# Created At: 12/14/2019
# Last Modified: 12/14/2019
# Status: production
# -----------------------------------------------------
import pandas as pd
from sqlalchemy import create_engine
import datetime as dt
# variables (Start)
dbname='meetup'
tname='members'
encoding='ISO-8859-1'
start = dt.datetime.now()
# variables (End)
try:
csv_database = create_engine('sqlite:///{}.db'.format(dbname))
df = pd.read_sql_query('select * from {} ORDER BY random() limit 5'.format(tname), csv_database)
print(df)
except Exception as e:
print('Exception while querying {} - [{}]'.format(dbname,str(e)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment