Skip to content

Commit

Permalink
to add outstanding scripts from my machine
Browse files Browse the repository at this point in the history
  • Loading branch information
Violin1208 committed Mar 11, 2017
1 parent 4db4eb9 commit db574ee
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 48 deletions.
88 changes: 44 additions & 44 deletions NLTK_textmine/map2.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,26 @@
'b19879088':('Barnes (London, England). Borough Council.','Richmond upon Thame'),
'b1987909x':('Barnes (London, England). Borough Council.','Richmond upon Thame'),
'b19879106':('Barnes (London, England). Borough Council.','Richmond upon Thame'),
'b19878795':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19878801':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19878813':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19878825':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19968437':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975715':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975727':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975739':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975740':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975752':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975764':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975776':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975788':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b1997579x':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975806':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975818':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b1997582x':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975831':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975843':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19975855':('Barnes (London, England). Urban District Council. n 2008185447','Richmond upon Thame'),
'b19878795':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19878801':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19878813':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19878825':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19968437':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975715':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975727':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975739':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975740':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975752':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975764':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975776':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975788':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b1997579x':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975806':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975818':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b1997582x':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975831':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975843':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19975855':('Barnes (London, England). Urban District Council.','Richmond upon Thame'),
'b19783930':('Barnet (London, England). London Borough.','Barnet'),
'b19783942':('Barnet (London, England). London Borough.','Barnet'),
'b19783954':('Barnet (London, England). London Borough.','Barnet'),
Expand Down Expand Up @@ -317,9 +317,9 @@
'b19785070':('Beckenham (London, England). Borough Council.','Bromley'),
'b19785082':('Beckenham (London, England). Borough Council.','Bromley'),
'b1978479x':('Beckenham (London, England). Urban District Council.','Bromley'),
'b19784788':('Beckenham (London, England). Urban District Council. nb2010007086','Bromley'),
'b19784806':('Beckenham (London, England). Urban District Council. nb2010007086','Bromley'),
'b19784818':('Beckenham (London, England). Urban District Council. nb2010007086','Bromley'),
'b19784788':('Beckenham (London, England). Urban District Council.','Bromley'),
'b19784806':('Beckenham (London, England). Urban District Council.','Bromley'),
'b19784818':('Beckenham (London, England). Urban District Council.','Bromley'),
'b19883730':('Beddington and Wallington (England). Borough Council.','Sutton'),
'b19883742':('Beddington and Wallington (England). Borough Council.','Sutton'),
'b19883754':('Beddington and Wallington (England). Borough Council.','Sutton'),
Expand Down Expand Up @@ -546,14 +546,14 @@
'b19785392':('Bexley (London, England). Borough Council.','Bexley'),
'b19785094':('Bexley (London, England). Urban District Council.','Bexley'),
'b19821839':('Bexley (London, England). Urban District Council.','Bexley'),
'b19880893':('Brent (London, England). Council. n 91051650','Brent'),
'b1988090x':('Brent (London, England). Council. n 91051650','Brent'),
'b19880911':('Brent (London, England). Council. n 91051650','Brent'),
'b19880923':('Brent (London, England). Council. n 91051650','Brent'),
'b19880935':('Brent (London, England). Council. n 91051650','Brent'),
'b19880947':('Brent (London, England). Council. n 91051650','Brent'),
'b19880959':('Brent (London, England). Council. n 91051650','Brent'),
'b19880960':('Brent (London, England). Council. n 91051650','Brent'),
'b19880893':('Brent (London, England). Council.','Brent'),
'b1988090x':('Brent (London, England). Council.','Brent'),
'b19880911':('Brent (London, England). Council.','Brent'),
'b19880923':('Brent (London, England). Council.','Brent'),
'b19880935':('Brent (London, England). Council.','Brent'),
'b19880947':('Brent (London, England). Council.','Brent'),
'b19880959':('Brent (London, England). Council.','Brent'),
'b19880960':('Brent (London, England). Council.','Brent'),
'b19968541':('Brentford (London, England). Local Board.','Hounslow'),
'b19968553':('Brentford (London, England). Urban District Council.','Hounslow'),
'b19968577':('Brentford (London, England). Urban District Council.','Hounslow'),
Expand Down Expand Up @@ -3857,19 +3857,19 @@
'b18246345':('Poplar (London, England). Metropolitan Borough.','Tower Hamlets'),
'b18246357':('Poplar (London, England). Metropolitan Borough.','Tower Hamlets'),
'b18246369':('Poplar (London, England). Metropolitan Borough.','Tower Hamlets'),
'b18111580':('Port of London (London, England). County Council.','Port of London Authority'),
'b18111592':('Port of London (London, England). County Council.','Port of London Authority'),
'b18121317':('Port of London (London, England). County Council.','Port of London Authority'),
'b1988414x':('Port of London (London, England). County Council.','Port of London Authority'),
'b19884266':('Port of London (London, England). County Council.','Port of London Authority'),
'b1988428x':('Port of London (London, England). County Council.','Port of London Authority'),
'b19884291':('Port of London (London, England). County Council.','Port of London Authority'),
'b1988431x':('Port of London (London, England). County Council.','Port of London Authority'),
'b1988445x':('Port of London (London, England). County Council.','Port of London Authority'),
'b1988459x':('Port of London (London, England). County Council.','Port of London Authority'),
'b19884606':('Port of London (London, England). County Council.','Port of London Authority'),
'b1988462x':('Port of London (London, England). County Council.','Port of London Authority'),
'b1988476x':('Port of London (London, England). County Council.','Port of London Authority'),
'b18111580':('Port of London (London, England). County Council.','City of London'),
'b18111592':('Port of London (London, England). County Council.','City of London'),
'b18121317':('Port of London (London, England). County Council.','City of London'),
'b1988414x':('Port of London (London, England). County Council.','City of London'),
'b19884266':('Port of London (London, England). County Council.','City of London'),
'b1988428x':('Port of London (London, England). County Council.','City of London'),
'b19884291':('Port of London (London, England). County Council.','City of London'),
'b1988431x':('Port of London (London, England). County Council.','City of London'),
'b1988445x':('Port of London (London, England). County Council.','City of London'),
'b1988459x':('Port of London (London, England). County Council.','City of London'),
'b19884606':('Port of London (London, England). County Council.','City of London'),
'b1988462x':('Port of London (London, England). County Council.','City of London'),
'b1988476x':('Port of London (London, England). County Council.','City of London'),
'b19883262':('Redbridge (London, England). Borough Council.','Redbridge'),
'b19883274':('Redbridge (London, England). Borough Council.','Redbridge'),
'b19883286':('Redbridge (London, England). Borough Council.','Redbridge'),
Expand Down
8 changes: 4 additions & 4 deletions python_utils/sqlite_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def connect_to_sqlite_db(sqlite_file):
conn = sqlite3.connect(sqlite_file)
cur = conn.cursor()
return conn, cur
except Error as e:
print(e)
except:
print()

return None

Expand Down Expand Up @@ -62,8 +62,8 @@ def execute_sql(conn, cur, sql):

try:
cur.execute(sql)
except Error as e:
print(e)
except:
print()

def main():

Expand Down
60 changes: 60 additions & 0 deletions python_utils/sqlite_utilities_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3

# This script connects to and performs queries on an SQLite database using Python.

import dataset


def connect_to_db():
""" Connect to an SQLite database. Return a connection."""
db = dataset.connect('sqlite:///../database/smells.sqlite')
return db


def sql_get_data_colnames(cur, sql, column_names):
"""Perform an SQL command to get data from an SQL database. Return data in a list of dictionaries with
column headers as keys and their associated values."""
print(sql)
sql = sql.replace('{column_names}', ",".join(column_names))
cur.execute(sql)
all_rows = cur.fetchall()

data = []
for row in all_rows:
d={}
i=0
for column_name in column_names:
d[column_name] = row[i]
i=i+1

data.append(d)

return data

def get_data(db, sql):
'''Get data from a database using the connection and cursor and defined sql.Output the data in a python list.'''
table = db['smells']
return all_rows

def copy_sqlite_file(original_sqlite_file, destination_sqlite_file):
'''Creates a copy of an sqlite file. Outputs an exact copy as an sqlite file.'''
shutil.copy(original_sqlite_file, destination_sqlite_file)


def main():
db = dataset.connect('sqlite:///../database/smells.sqlite')

sqlite_file = '/home/jen/projects/smelly_london/git/smelly_london/database'
column_names = ['category', 'location', 'number_of_smells', 'centroid_lat', 'centroid_lon', 'id', 'year', 'sentence']
sql = 'select {column_names} from (select Category category, Borough location, Id id, Year year, Sentence sentence, count(*) number_of_smells from smells group by Category, Borough having Year = "1904") join locations on location = name;'

conn, cur = connect_to_sqlite_db(sqlite_file)
data = sql_get_data_colnames(cur, sql, column_names)

close_sqlite_connection(conn)

return data

if __name__ == '__main__':

main()

0 comments on commit db574ee

Please sign in to comment.