def login(): response = {"result": 0, "error": "", "data": ""} requ = { "user": request.args.get("user"), "password": request.args.get("password") } if requ["user"] != None and requ["password"] != None: userInfo = Main.getSingleFromTable( "user", "idUser AS ID,username,password", " AND username = '******' AND active = 1", 1) if userInfo != None: userLog = Main.getMultipleFromTable( "user_session", "*", " AND idUser= "******"ID"]) + " AND active = 1 ORDER BY insertDate ASC", 1) if len(userLog) >= 3: updateData = { "active": "0", "logoutDate": str(datetime.datetime.now()) } updateWhere = { "id_user_session": userLog[0]["id_user_session"] } update = Main.updateTable("user_session", updateData, updateWhere, 1) if requ["password"] == userInfo["password"]: token = ''.join( choice(string.ascii_letters + string.digits) for i in range(64)) userInsert = { "idUser": str(userInfo["ID"]), "bearerToken": token } login = Main.insertTable("user_session", userInsert, 1) if login != None: response["result"] = 1 response["data"] = {"username": userInfo["username"]} else: response["error"] = "User Not Login" else: response["error"] = "Incorrect Password" else: response["error"] = "User Not Found" else: response["error"] = "Parameter" return response
def uploadMunicpio(): response = {"result": 0, "error": "", "data": ""} if request.method == "POST": PATH_FILE = 'csvs/' if 'file' in request.files: file = request.files['file'] if file.filename != '': if file and allowed_file(file.filename): if not os.path.exists(PATH_FILE): os.makedirs(PATH_FILE) extension = "." + file.filename.rsplit('.', 1)[1].lower() filename = extension r_save = file.save(os.path.join(PATH_FILE, filename)) with open(PATH_FILE + filename) as csvfile: reader = csv.DictReader(csvfile) lista = [] aux1 = [] cont = 0 for row in reader: lista.append(row) for row in lista: if row.keys() >= { "c_estado", "d_municipio", "c_mnpio" }: insertData = { "c_estado": row["c_estado"], "d_municipio": row["d_municipio"], "c_mnpio": row["c_mnpio"] } insert = Main.insertTable( "municipio", insertData, 1) if insert != None: response["data"] = insert else: response["error"] = "Hay campos vacios" else: response[ "error"] = "Error Not Parameters Found" else: response["error"] = "Error filename" else: response["error"] = "Error filename vacio" else: response["error"] = "Error file" else: reponse["error"] = "Es un POST" return response
def colonia(): response = {"result": 0, "error": "", "data": ""} requ = request.get_json() if request.headers.get('Authorization'): if request.method == "GET": if request.args.get("cp"): colonia = Main.getSingleFromTable( "colonia", "d_asenta AS colonia", " AND d_codigo= '" + str(request.args.get("cp")) + "'", 1) if colonia != []: response["data"] = colonia response["result"] = 1 else: response["error"] = "No existe esta colonia" else: response["error"] = "Se busca por Codigo Postal" else: response["error"] = "Tiene que ser un GET" else: response["error"] = "No tienes Authorization" return response
def getEstado(): response = {"result": 0, "error": "", "data": ""} requ = request.get_json() if request.headers.get('Authorization'): if request.method == "GET": if request.args.get("nombre"): estado = Main.getSingleFromTable( "estado", "d_estado AS estado", " AND d_estado= '" + str(request.args.get("nombre")) + "'", 1) if estado != []: response["data"] = estado response["result"] = 1 else: response["error"] = "No existe este estado" else: response["error"] = "Se busca por nombre completo" else: response["error"] = "Tiene que ser un GET" else: response["error"] = "No tienes Authorization" return response
from classes.Main import Main from flask import request from werkzeug.utils import secure_filename import datetime Main = Main() def getEstado(): response = {"result": 0, "error": "", "data": ""} requ = request.get_json() if request.headers.get('Authorization'): if request.method == "GET": if request.args.get("nombre"): estado = Main.getSingleFromTable( "estado", "d_estado AS estado", " AND d_estado= '" + str(request.args.get("nombre")) + "'", 1) if estado != []: response["data"] = estado response["result"] = 1 else: response["error"] = "No existe este estado" else: response["error"] = "Se busca por nombre completo" else: response["error"] = "Tiene que ser un GET" else: response["error"] = "No tienes Authorization" return response
import operator from classes.PorterStemmer import PorterStemmer from classes.StopWordEliminater import StopWordEliminater from classes.Main import Main main = Main() p = PorterStemmer() e = StopWordEliminater() freq = {} size_of_corpus = 0 for count in range(1, 1400): f = open('cranfieldDocs/cranfield' + main.get_number(count), 'r') message = f.read() f.close() text = main.tag_remove(message) items = main.tokenize(text) items = e.eliminate(items) for item in items: word = p.stem(item, 0, len(item) - 1) size_of_corpus += 1 if word in freq: freq[word] = freq[word] + 1 else: freq[word] = 1 vocab_size = len(freq) print("size of vocab : ", vocab_size) sorted_freq = sorted(freq.items(), key=operator.itemgetter(1), reverse=True)
import operator from classes.Main import Main from classes.PorterStemmer import PorterStemmer main = Main() p = PorterStemmer(); freq = {}; size_of_corpus = 0; for count in range(1, 1400) : f = open('cranfieldDocs/cranfield' + get_number(count), 'r'); message = f.read(); f.close(); text = main.tag_remove(message); itmes = main.tokenize(text); for item in items : word = p.stem(item, 0,len(item)-1) size_of_corpus += 1; if word in freq : freq[word] = freq[word] + 1; else : freq[word] = 1; vocab_size = len(freq); print("size of vocab : ", vocab_size); sorted_freq = sorted(freq.items(), key = operator.itemgetter(1), reverse = True ) # print(sorted_freq)
# -*- coding: utf-8 -*- from config import * import collections from classes.Main import Main if __name__ == "__main__": main = Main() """ Example code to import tweets """ # file_path = os.path.realpath(PROJECT_ROOT_DIRECTORY+DATASET_TXT_DIR_NAME+"TTNetTweets2012.txt") # main.retrieve_tweets(file_path) """ Example code to generate arff file with given feature parameters """ # main.extract_features_and_generate_arff(n=3, analyzer='char', year='2012') """ Example code to plot __years' scores """ # root path, ../DataSet-Logs/Word/YearsOnly/TTNet/ # root_path_for_years_itself = PROJECT_ROOT_DIRECTORY + DATASET_LOGS_DIR_NAME + FEATURE_TYPE+\ # LOGS_YEARS_ITSELF_DIR_NAME+MODEL_NAME+'/' # main.plot_years_scores(root_path_for_years_itself) """ Example code to plot 2012 vs rest """
#!/usr/bin/env python # -*- coding: utf-8 -*- from classes.Main import Main if __name__ == '__main__': Main()