| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/gavin/workspace/comecondo/python/home_school_find/ |
Upload File : |
import os
import sys
import mysql.connector
import time
config = {
'user': 'root',
'password': 'Ilovekitty1',
'host': '127.0.0.1',
'database': 'comecondo',
'raise_on_warnings': True
}
if len(sys.argv)<4:
print('Incorrect parameters')
else:
latitude = sys.argv[1]
longitude = sys.argv[2]
postalcode = sys.argv[3]
# print('Youn input: '+latitude+', '+longitude+', '+postalcode)
cnx = mysql.connector.connect(host="localhost", user="root", password="Ilovekitty1", database="comecondo")
dbcur = cnx.cursor()
public_elementary_query = "select school_name, school_type, school_level, school_special_condition, (school_latitude-"+latitude+")*(school_latitude-"+latitude+")+(school_longitude-"+longitude+")*(school_longitude-"+longitude+") as distance, school_website, grade_range,school_language, concat(school_address,', ', school_city) as school_address, school_latitude as lat, school_longitude as lng from cc_ontario_schools where school_name like '%School%' and left(postal_code,3)=left('"+postalcode+"',3) and school_type='Public' and school_level='Elementary' and school_special_condition='Not applicable' order by 5 limit 3;"
public_secondary_query = "select school_name, school_type, school_level, school_special_condition, (school_latitude-"+latitude+")*(school_latitude-"+latitude+")+(school_longitude-"+longitude+")*(school_longitude-"+longitude+") as distancee, school_website, grade_range,school_language, concat(school_address,', ', school_city) as school_addres, school_latitude as lat, school_longitude as lng from cc_ontario_schools where school_name like '%School%' and left(postal_code,3)=left('"+postalcode+"',3) and school_type='Public' and school_level='Secondary' and school_special_condition='Not applicable' order by 5 limit 3;"
public_secondary_query_1 = "select school_name, school_type, school_level, school_special_condition, (school_latitude-"+latitude+")*(school_latitude-"+latitude+")+(school_longitude-"+longitude+")*(school_longitude-"+longitude+") as distancee, school_website, grade_range,school_language, concat(school_address,', ', school_city) as school_addres, school_latitude as lat, school_longitude as lng from cc_ontario_schools where school_name like '%School%' and left(postal_code,2)=left('"+postalcode+"',2) and school_type='Public' and school_level='Secondary' and school_special_condition='Not applicable' order by 5 limit 3;"
catholic_elementary_query = "select school_name, school_type, school_level, school_special_condition, (school_latitude-"+latitude+")*(school_latitude-"+latitude+")+(school_longitude-"+longitude+")*(school_longitude-"+longitude+") as distance, school_website, grade_range,school_language, concat(school_address,', ', school_city) as school_addres, school_latitude as lat, school_longitude as lng from cc_ontario_schools where left(postal_code,3)=left('"+postalcode+"',3) and school_type='Catholic' and school_level='Elementary' and school_special_condition='Not applicable' order by 5 limit 1;"
catholic_secondary_query = "select school_name, school_type, school_level, school_special_condition, (school_latitude-"+latitude+")*(school_latitude-"+latitude+")+(school_longitude-"+longitude+")*(school_longitude-"+longitude+") as distance, school_website, grade_range,school_language, concat(school_address,', ', school_city) as school_addres, school_latitude as lat, school_longitude as lng from cc_ontario_schools where left(postal_code,3)=left('"+postalcode+"',3) and school_type='Catholic' and school_level='Secondary' and school_special_condition='Not applicable' order by 5 limit 1;"
# print(public_elementary_query)
# print('')
# print(public_secondary_query)
# print('')
# print(catholic_elementary_query)
# print('')
# print(catholic_secondary_query)
# Look for best schools
# Public Elementary Schools
final_result = ''
dbcur.execute(public_elementary_query)
result = dbcur.fetchall()
final_result = '"Elementary Public":['
for row in result:
final_result = final_result+'{"school_name":"'+row[0].replace("'","\'")+'","school_web":"'+row[5]+'","grade_range":"'+row[6]+'","school_address":"'+row[8]+'","lat":"'+row[9]+'","lng":"'+row[10]+'"},'
final_result = final_result[:-1]
final_result = final_result+'],'
dbcur.execute(public_secondary_query)
result = dbcur.fetchall()
final_result = final_result + '"Secondary Public":['
for row in result:
final_result = final_result+'{"school_name":"'+row[0].replace("'","\'")+'","school_web":"'+row[5]+'","grade_range":"'+row[6]+'","school_address":"'+row[8]+'","lat":"'+row[9]+'","lng":"'+row[10]+'"},'
if len(result) == 0:
dbcur.execute(public_secondary_query_1)
result = dbcur.fetchall()
for row in result:
final_result = final_result+'{"school_name":"'+row[0].replace("'","\'")+'","school_web":"'+row[5]+'","grade_range":"'+row[6]+'","school_address":"'+row[8]+'","lat":"'+row[9]+'","lng":"'+row[10]+'"},'
final_result = final_result[:-1]
final_result = final_result+']'
final_result = '{'+final_result+'}'
print (final_result)