Ejemplo n.º 1
0
def updatePollingPlace(mysql,id_place,request):
    try:
        response = {}
        cur = mysql.connection.cursor()
        sql = """SELECT city
                FROM citys 
                WHERE id_city = %s
                """
        cur.execute(sql, (request["id_city"],))
        data_city = cur.fetchone()
        # data = cur.fetchall()
        array_address = getGeolocation(request["address"],data_city[0])
        if type(id_place) == int and type(request["id_city"]) == int and request["name_place"] != "" and array_address["address_show"] != "" and array_address["latitude"] != "" and array_address["lenght"] != "":
            sql = """UPDATE polling_places 
                    SET name_place = %s, address_show = %s, latitude = %s, lenght = %s, id_city = %s 
                    WHERE id_place = %s
            """
            cur.execute(sql, (request["name_place"],array_address["address_show"],array_address["latitude"],array_address["lenght"],request["id_city"],id_place))
            if cur.rowcount > 0:
                mysql.connection.commit()
                response["code"] = 200
                response["data"] = '1'
            else:
                response["code"] = 202
        else:
            response["code"] = 400                
        cur.close()
        return response
    except:
        return ({"code":409})
Ejemplo n.º 2
0
def insertPollingPlace(mysql,request):
    try:
        response = {}
        cur = mysql.connection.cursor()
        sql = """SELECT city
                FROM citys 
                WHERE id_city = %s
                """
        cur.execute(sql, (request["id_city"],))
        data_city = cur.fetchone()
        # data = cur.fetchall()
        array_address = getGeolocation(request["address"],data_city[0])
        if type(request["id_city"]) == int and request["name_place"] != "" and array_address["address_show"] != "" and array_address["latitude"] != "" and array_address["lenght"] != "": 
            sql = """INSERT INTO polling_places (name_place, address_show, latitude, lenght, id_city)
                    VALUES (%s,%s,%s,%s,%s)
            """
            cur.execute(sql,(request["name_place"],array_address["address_show"],array_address["latitude"],array_address["lenght"],request["id_city"]))
            if cur.rowcount > 0:
                mysql.connection.commit()
                response["code"] = 200
                response["data"] = str(cur.lastrowid)
            else:
                response["code"] = 202
        else:
            response["code"] = 400                
        cur.close()
        return response
    except:
        return ({"code":409})
Ejemplo n.º 3
0
def updateVoter(mysql, id_voter, request):
    try:
        response = {}
        cur = mysql.connection.cursor()
        print("esto", request)
        sql = """SELECT city
                FROM citys 
                WHERE id_city = %s
                """
        cur.execute(sql, (request["id_city"], ))
        data_city = cur.fetchone()
        # data = cur.fetchall()
        print(data_city[0])
        # print(cur.fetchone())
        array_address = getGeolocation(request["address"], data_city[0])
        print(array_address)
        print(type(id_voter))
        print(type(request["id_place"]))
        if type(id_voter) == int and type(request["id_city"]) == int and type(
                request["id_place"]
        ) == int and request["names"] != "" and request[
                "last_names"] != "" and request["document"] != "" and request[
                    "phone"] != "" and array_address[
                        "address_show"] != "" and array_address[
                            "latitude"] != "" and array_address[
                                "lenght"] != "" and request[
                                    "voting_table"] != "":
            print("""UPDATE voters 
                    SET names= %s, last_names= %s, document= %s, phone= %s, address_show= %s, latitude= %s, lenght= %s, id_city= %s, id_place= %s, voting_table= %s
                    WHERE id_voter = %s
            """)
            sql = """UPDATE voters 
                    SET names= %s, last_names= %s, document= %s, phone= %s, address_show= %s, latitude= %s, lenght= %s, id_city= %s, id_place= %s, voting_table= %s
                    WHERE id_voter = %s
            """
            cur.execute(
                sql, (request["names"], request["last_names"],
                      request["document"], request["phone"],
                      array_address["address_show"], array_address["latitude"],
                      array_address["lenght"], request["id_city"],
                      request["id_place"], request["voting_table"], id_voter))
            if cur.rowcount > 0:
                mysql.connection.commit()
                response["code"] = 200
                response["data"] = '1'
            else:
                response["code"] = 202
        else:
            response["code"] = 400
        print(response)
        cur.close()
        return response
    except:
        print("Error updateVoter")
        return ({"code": 409})
Ejemplo n.º 4
0
def insertVoter(mysql, request):
    try:
        response = {}
        cur = mysql.connection.cursor()
        print("esto", request)
        sql = """SELECT city
                FROM citys 
                WHERE id_city = %s
                """
        cur.execute(sql, (request["id_city"], ))
        data_city = cur.fetchone()
        # data = cur.fetchall()
        print(data_city[0])
        # print(cur.fetchone())
        array_address = getGeolocation(request["address"], data_city[0])
        print(array_address)
        if type(request["id_city"]) == int and type(
                request["id_place"]
        ) == int and type(
                request["id_leader"]
        ) == int and request["names"] != "" and request[
                "last_names"] != "" and request["document"] != "" and request[
                    "phone"] != "" and array_address[
                        "address_show"] != "" and array_address[
                            "latitude"] != "" and array_address[
                                "lenght"] != "" and request[
                                    "voting_table"] != "":
            sql = """INSERT INTO voters (names, last_names, document, phone, address_show, latitude, lenght, id_city, id_place, id_leader, voting_table)
                    VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
            """
            print(sql)
            cur.execute(
                sql,
                (request["names"], request["last_names"], request["document"],
                 request["phone"], array_address["address_show"],
                 array_address["latitude"], array_address["lenght"],
                 request["id_city"], request["id_place"], request["id_leader"],
                 request["voting_table"]))
            if cur.rowcount > 0:
                mysql.connection.commit()
                response["code"] = 200
                response["data"] = str(cur.lastrowid)
            else:
                response["code"] = 202
        else:
            response["code"] = 400
        print(response)
        cur.close()
        return response
    except:
        print("Error insertVoter")
        return ({"code": 409})
Ejemplo n.º 5
0
def __main__():
    global config
    if not readConfigFile():
        sys.exit()

    while True:
        # scan the wifi networks, and get geolocation data from API
        data = geolocation.getGeolocation(config['apiKey'])
        # display the data
        geolocation.displayGeolocation(data)

        # sleep
        sleep(config['scanInterval'])
Ejemplo n.º 6
0
def updateLeader(mysql, id_leader, request):
    try:
        response = {}
        cur = mysql.connection.cursor()
        sql = """SELECT city
                FROM citys 
                WHERE id_city = %s
                """
        cur.execute(sql, (request["id_city"], ))
        data_city = cur.fetchone()
        array_address = getGeolocation(request["address"], data_city[0])
        if type(id_leader) == int and type(
                request["id_city"]
        ) == int and request["names"] != "" and request[
                "last_names"] != "" and request["document"] != "" and request[
                    "phone"] != "" and array_address[
                        "address_show"] != "" and array_address[
                            "latitude"] != "" and array_address["lenght"] != "":
            sql = """UPDATE users 
                    SET names= %s, last_names= %s, document= %s, phone= %s, address_show= %s, latitude= %s, lenght= %s, id_city= %s
                    WHERE id_user = %s
            """
            cur.execute(
                sql, (request["names"], request["last_names"],
                      request["document"], request["phone"],
                      array_address["address_show"], array_address["latitude"],
                      array_address["lenght"], request["id_city"], id_leader))
            if cur.rowcount > 0:
                mysql.connection.commit()
                response["code"] = 200
                response["data"] = '1'
            else:
                response["code"] = 202
        else:
            response["code"] = 400
        cur.close()
        return response
    except:
        return ({"code": 409})
Ejemplo n.º 7
0
def insertLeader(mysql, request):
    try:
        response = {}
        cur = mysql.connection.cursor()
        sql = """SELECT city
                FROM citys 
                WHERE id_city = %s
                """
        cur.execute(sql, (request["id_city"], ))
        data_city = cur.fetchone()
        array_address = getGeolocation(request["address"], data_city[0])
        if type(
                request["id_city"]
        ) == int and request["names"] != "" and request[
                "last_names"] != "" and request["document"] != "" and request[
                    "phone"] != "" and array_address[
                        "address_show"] != "" and array_address[
                            "latitude"] != "" and array_address["lenght"] != "":
            sql = """INSERT INTO users (names, last_names, document, phone, address_show, latitude, lenght, id_city, id_profile, status_user)
                    VALUES (%s,%s,%s,%s,%s,%s,%s,%s,2,1)
            """
            cur.execute(
                sql, (request["names"], request["last_names"],
                      request["document"], request["phone"],
                      array_address["address_show"], array_address["latitude"],
                      array_address["lenght"], request["id_city"]))
            if cur.rowcount > 0:
                mysql.connection.commit()
                response["code"] = 200
                response["data"] = str(cur.lastrowid)
            else:
                response["code"] = 202
        else:
            response["code"] = 400
        cur.close()
        return response
    except:
        return ({"code": 409})
Ejemplo n.º 8
0
if __name__ == "__main__":
    fileDir = os.path.abspath(os.path.join(
        os.path.realpath(sys.argv[0]), os.pardir))
    fileName = os.path.join(fileDir, "demo.json")
    with open(fileName, 'r') as fhandler:
        data = json.load(fhandler)

    # update index, prev+1
    index = max([int(x) for x in data['problems'].keys()]) + 1
    newProblem = copy.deepcopy(data['problems']['1'])

    newProblem['date'] = getDate.get_date()
    # newProblem['Address'] = ''
    newProblem['Address'] = data['problems'][str(index - 1)]['Address']
    newProblem['Geolocation'] = geolocation.getGeolocation()
    newProblem['problem'] = ''
    newProblem['description'] = ''
    newProblem['notes'] = ''
    newProblem['link']['lintcode'] = ''
    newProblem['link']['jiuzhangsuanfa'] = ''

    data['problems'][str(index)] = newProblem

    newData = dict()
    newData['problems'] = dict()
    for key, val in data['problems'].items():
        newData['problems'][MyStr(key)] = val

    with open(fileName, 'w') as fhandler:
        json.dump(newData, fhandler, indent=4, sort_keys=True)