Last active
December 30, 2016 17:24
-
-
Save javi830810/380b9dfe4d15c85167bd to your computer and use it in GitHub Desktop.
Etecsa Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
connection = sqlite3.connect('/Users/javi830810/Documents/etecsa.db') | |
def find_by_name(query): | |
where_clause = [ | |
('name', 'like', "'" + query + "%'") | |
] | |
return run_query(where_clause) | |
def find_by_year(query): | |
where_clause = [ | |
('identification', 'like', "'" + query + "%'") | |
] | |
return run_query(where_clause) | |
def find_by_province(province): | |
where_clause = [ | |
('province', 'like', "'" + str(_get_province_code(province)) + "%'") | |
] | |
return run_query(where_clause) | |
def run_query(where_clause, include_fix=False, fix_where_clause=None): | |
where_query = _get_where_clause(where_clause) | |
result_set = connection.execute('SELECT * FROM movil WHERE ' + where_query) | |
fix_result_set = [] | |
if include_fix: | |
fix_result_set = connection.execute('SELECT * FROM fix WHERE ' + _get_where_clause(fix_where_clause)) | |
return list(result_set) + list(fix_result_set) | |
def _get_where_clause(where): | |
q = '1=1 ' | |
for where_clause in where: | |
q += 'AND %s %s %s ' %(where_clause[0] , where_clause[1], where_clause[2]) | |
return q | |
def _get_province_code(province): | |
province = province.lower() | |
if province == 'habana': | |
return 7 | |
elif province == 'santiago' or province == 'santiago de cuba': | |
return 22 | |
elif province == 'matanzas': | |
return 45 | |
elif province == 'ciego de avila': | |
return 33 | |
elif province == 'sancti spiritus': | |
return 41 | |
elif province == 'santa clara': | |
return 42 | |
elif province == 'cienfuegos': | |
return 43 | |
elif province == 'holguin': | |
return 7 | |
elif province == 'granma': | |
return 23 | |
elif province == 'guantanamo': | |
return 24 | |
elif province == 'pinar del rio': | |
return 48 | |
elif province == 'las tunas': | |
return 31 | |
elif province == 'isla de la juventud': | |
return 7 | |
elif province == 'artemisa': | |
return 47 | |
elif province == 'mayabeque': | |
return 47 | |
elif province == 'camaguey': | |
return 32 | |
"""-------------------------------------------------------------- | |
| Etecsa Program | | |
| | | |
| | | |
-----------------------------------------------------------------""" | |
print find_by_name('Rita Elena Lopez') | |
print find_by_province('Guantanamo') | |
print find_by_year('1983') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment