def queryExperiment(request): if request.method == 'POST': with connection.cursor() as cursor: expConditions = '' seqName = request.POST.get('seqName') if request.POST.get('expConditions') != '': expConditions = request.POST.get('expConditions') # Check all of the specific conditions and find the ids for them expConditions = ''.join(expConditions.split()) listSpecCond = expConditions.split(',') dataList = [] for specCondition in listSpecCond: item = specCondition.split(':') if len(item) < 2: return render(request, 'GUI/error.html') query = 'SELECT * FROM GUI_SpecificCondition WHERE name = "{}" AND value = "{}"'.format( sqlescape(item[0]), sqlescape(item[1])) cursor.execute(query) condFound = cursor.fetchall() for a in condFound: dataList.append(a[0]) dataList.sort() newList = str(dataList).strip('[]') query = 'SELECT * FROM GUI_Experiment WHERE sequence = "{}" AND Conditions = "{}"'.format( sqlescape(seqName), sqlescape(newList)) cursor.execute(query) expFound = cursor.fetchall() context = {'found': False} if len(expFound) > 0: se = request.POST.get('seqName') es = request.POST.get('expConditions') measurementList = {} myList = expFound[0][3].split(',') for a in myList: a = a.strip() query = 'SELECT * FROM GUI_SpecificMeasurement WHERE id = "{}"'.format( sqlescape(a)) cursor.execute(query) measurementFound = cursor.fetchall() if len(measurementFound) > 0: mesua = measurementFound[0] measurementList[mesua[1]] = mesua[2] context = { "data": ({ "ExperimentFound": expFound, "es": es, "se": se, "measurements": measurementList }), "found": True, "compare": False } return render(request, 'GUI/results.html', context) return render(request, 'GUI/results.html', context)
def login(): data = request.json if not have(data, ['user', 'pass']): return make_response({"error": 'User name or password wasn\'t provided'}, 400) user, password = sqlescape(data['user']), data['pass'].encode() user: User = User.query.filter_by(name=user).first() if user is None: return make_response({"error": "User doesn't exists"}, 401) if not checkpw(password, user.passwd.encode('utf-8')): return make_response({"error": "Password is incorrect"}, 401) secret = os.getenv('PRIVATE_KEY') if secret is None: print('Private key is not set!!!') return make_response({"error": "Private key is not set"}, 500) encoded_jwt = jwt.encode({'user': user.name}, secret, algorithm='HS256') return {"token": encoded_jwt.decode()}
def build_search_products_query(lang, input, filter, project_page_path): search_phrase = re.sub('([^\w\s]|((?<=[\s])\d+))', '', sqlescape(input)) words = [ word.strip() for word in search_phrase.split(' ') if not word == "" ] ts_query_phrase = ' <-> '.join(words) ts_query_words = ' | '.join(words) return f"""
def dataInputSequence(request): if request.method == 'POST': with connection.cursor() as cursor: seqName = request.POST.get('name') seqInfo = request.POST.get('info') seqFile = request.POST.get('fileName') if len(seqInfo) == 0: seqInfo = "None" if len(seqFile) == 0: seqFile == "None" # Check if that sequence already exists sql_search_query = "SELECT * FROM GUI_Sequence WHERE name=%s" seqQuery = (sqlescape(seqName), ) cursor.execute(sql_search_query, seqQuery) seqFound = cursor.fetchall() if len(seqFound) == 0: newSeq = Sequence(name=sqlescape(seqName), info=sqlescape(seqInfo), file=sqlescape(seqFile)) newSeq.save() print("Sequence inserted successfully") else: print("Sequence was already found. Try another Sequence") query = 'UPDATE GUI_Sequence SET info ="{}", file ="{}" WHERE name="{}"'.format( sqlescape(seqInfo), sqlescape(seqFile), sqlescape(seqName)) cursor.execute(query) return render(request, 'GUI/updated.html') return render(request, 'GUI/insertedComplete.html')
def save_user(name: str, passwd: str): new_user = User(name=sqlescape(name), passwd=passwd) user = User.query.filter(User.name == new_user.name).first() if user is None: db.session.add(new_user) db.session.commit() else: raise RegisterException('User already exists')
def find_entity_by_id(entity_id: str = "0", table: str = "users") -> dict: try: query = "SELECT * FROM {table} WHERE id = {id}".format( table=sqlescape(str(table)), id=sqlescape(str(int(entity_id)))) result = conn.execute(query) column_names = result.keys() values = result.fetchone() row = dict(zip(column_names, values)) logger.debug(f"Result from query: '{row}'") return row except Exception as e: logger.warning( f"Query with entity_id = {entity_id} and table = {table} failed!") return {}
def build_query(input): input = sqlescape(input) print('input', input) word_list = [word.strip() for word in input.split(' ') if not word == ''] last_word = word_list[-1] if len(word_list) else input phrase = " <-> ".join(word_list[:-1] if len(word_list) else []) if phrase: phrase += " <-> " ts_query = phrase + last_word + ':*' + ' | ' + last_word + ':*' print(ts_query) lang = get_language() return f"""
def filter(): if not type_param and not on_index_param: return '' where = '' if type_param: type_values = sqlescape(type_param).split(',') where += ' AND (' + ' OR '.join([ f"app_projects_project_type.value='{value}'" for value in type_values ]) + ')' if on_index_param: where += ' AND (app_projects_project.show_on_index = TRUE) ' return where
def get_template_and_context(self, request, path): try: context = {} if re.match('.*\.\w{,5}$', path): #file raise ObjectDoesNotExist('path') route = self.process_path(sqlescape(path), request) if route.get('redirect'): return [None, {'redirect': route.get('redirect')}] if route.get('not_found'): raise LookupError('not found') page_id = route.get('page_id') pattern = route.get('pattern') page_name, page_template = self.get_page_raw(page_id) params = self.get_groups(pattern, path) sections = self.get_page_sections_raw(page_id) views = self.import_views(sections) views_context = {'page_id': page_id} views_data = self.process_views(request, views, views_context, params) context = { **context, **views_data, 'meta': self.get_page_meta(page_id, request), 'menus': self.get_menus_raw(page_id), 'sections': sections['view_data'], 'no_index': not request.get_host() in settings.INDEXED_DOMAINS } if context.get('page_meta'): context['meta'] = context['page_meta'] return [page_template, context] except (Page.DoesNotExist, IndexError, LookupError, ObjectDoesNotExist): context = { 'meta': { 'title': 'Page not found', 'meta_title': 'Page not found', 'meta_description': 'Page not found' } } return ['404.html', context]
def hashfiles(source, buff): i = 1 # a lista kiírásához a kezdőérték megadása for r, d, f in os.walk( source ): # az r a kezdőkönyvtár a d a könyvtár a f pedig az aktuális file for file in f: if file.lower().endswith(extensions): filename = os.path.join("/", r, file) with open(filename, 'rb') as afile: # read file as byte (rb) hasher = hashlib.blake2b( ) # blake2b hash megadása a fájlokhoz. Jobb mint az md5 állítólag. for chunk in iter(lambda: afile.read(buff), b""): hasher.update(chunk) sql = (sqlescape(filename), hasher.hexdigest()) SqlInsert.append(sql) # print('{}; - filenév: {}.'.format(i, filename)) i += 1
def dataInputCondition(request): if request.method == 'POST': with connection.cursor() as cursor: condName = request.POST.get('name') condDomain = request.POST.get('domain') possibleValues = request.POST.get('possValues') if condDomain is None or condDomain == '' or condDomain.lower( ) == 'domain': return render(request, 'GUI/error.html') if condDomain.lower() == 'boolean' and possibleValues.lower( ) != 'true' and possibleValues.lower( ) != 'false' and possibleValues != '1' and possibleValues != '0': return render(request, 'GUI/error.html') try: if condDomain.lower() == 'int' and int(possibleValues): return render(request, 'GUI/error.html') except Exception: return render(request, 'GUI/error.html') try: if condDomain.lower() == 'float' and float(possibleValues): return render(request, 'GUI/error.html') except Exception: return render(request, 'GUI/error.html') # Check if that condition already exists sql_search_query = "SELECT * FROM GUI_Condition WHERE name=%s" condQuery = (sqlescape(condName), ) cursor.execute(sql_search_query, condQuery) condFound = cursor.fetchall() if len(condFound) == 0: newCon = Condition(name=sqlescape(condName), domain=sqlescape(condDomain), possValues=sqlescape(possibleValues)) newCon.save() print("Condition inserted successfully") else: print( "Condition was already found. Will update this condition") query = 'UPDATE GUI_Condition SET domain ="{}", possValues ="{}" WHERE name="{}"'.format( sqlescape(condDomain), sqlescape(possibleValues), sqlescape(condName)) cursor.execute(query) return render(request, 'GUI/updated.html') return render(request, 'GUI/insertedComplete.html')
def dataInputMeasurement(request): if request.method == 'POST': with connection.cursor() as cursor: measName = request.POST.get('name') measDomain = request.POST.get('domain') possibleValues = request.POST.get('possValues') if measDomain is None or measDomain == '' or measDomain.lower( ) == 'domain': return render(request, 'GUI/error.html') if measDomain.lower() == 'boolean' and possibleValues.lower( ) != 't' and possibleValues.lower( ) != 'f' and possibleValues != '1' and possibleValues != '0': return render(request, 'GUI/error.html') try: if measDomain.lower() == 'int' and int(possibleValues): return render(request, 'GUI/error.html') except Exception: return render(request, 'GUI/error.html') try: if measDomain.lower() == 'float' and float(possibleValues): return render(request, 'GUI/error.html') except Exception: return render(request, 'GUI/error.html') # Check if that measurement already exists sql_search_query = "SELECT * FROM GUI_Measurement WHERE name=%s" measQuery = (sqlescape(measName), ) cursor.execute(sql_search_query, measQuery) measFound = cursor.fetchall() if len(measFound) == 0: newMeas = Measurement(name=sqlescape(measName), domain=sqlescape(measDomain), possValues=sqlescape(possibleValues)) newMeas.save() print("Measurement inserted successfully") else: print("Measurement was already found. Try another Measurement") query = 'UPDATE GUI_Measurement SET domain ="{}", possValues ="{}" WHERE name="{}"'.format( sqlescape(measDomain), sqlescape(possibleValues), sqlescape(measName)) cursor.execute(query) return render(request, 'GUI/updated.html') return render(request, 'GUI/insertedComplete.html')
def type_condition(): if not params.get("type"): return "" value = sqlescape(params.get("type"), '') return 'contact.type = ' + value
def comparisonResults(request): # The user should enter a list of sequences and conditions. # # Then the system should retrieve all experiments that has the sequence and # (at least) one of the conditions and list them. # # The user can also enter a list of measurements and the system will return the value # of the measurements for all the experiments above as a table. if request.method == 'POST': with connection.cursor() as cursor: seqName = request.POST.getlist('seqName') expConditions = request.POST.getlist('expConditions') expMeasures = request.POST.getlist('expMeasure') totalExperiments = [] expFound = [] if len(seqName) == 0: return render(request, 'GUI/error.html') # Get the certain experiment where the sequence matches for something in seqName: query = 'SELECT * FROM GUI_Experiment WHERE Sequence = "{}"'.format( sqlescape(something)) cursor.execute(query) expASA = cursor.fetchall() if len(expASA) > 0: for a in expASA: totalExperiments.append(a) # For each experiment that matches, check if one of the conndition matches the conditions requested # If so then insert that experiment for experiment in totalExperiments: expss = experiment[2].replace(',', '') experiments = list(expss.replace(' ', '')) for condition_id in experiments: query = 'SELECT * FROM GUI_SpecificCondition sc WHERE sc.id = "{}"'.format( sqlescape(condition_id)) cursor.execute(query) condsFound = cursor.fetchall() # For loop to check if the condition was one of the ones inserted for cond in expConditions: if cond == condsFound[0][1]: expFound.append(experiment) # For each experiment in the list, if there are measurements then query to see if that experiment has # those measurements expFound = list(dict.fromkeys(expFound)) measListIFound = {} for exp in expFound: measListIFound[exp[0]] = "Experiment :" + str( exp[0]) + " with Measurements : " # For each of those experiments, get the value of the measurements requested flagLol = 0 if len(expMeasures) > 0: flagLol = 1 for expMea in expMeasures: for expWhole in expFound: mana = expWhole[3].split(', ') expFoundC = [int(i) for i in mana] for measInExp in expFoundC: query = 'SELECT * FROM GUI_SpecificMeasurement sc WHERE sc.id = "{}"'.format( sqlescape(str(measInExp))) cursor.execute(query) condsFounda = cursor.fetchall() if condsFounda[0][1] == expMea: measListIFound[expWhole[0]] += str( condsFounda[0][1]) + ":" + str( condsFounda[0][2]) + ", " context = { "data": ({ "measurements": measListIFound, "se": seqName, "es": expConditions, 'meas': flagLol }), 'found': len(expFound) > 0 } return render(request, 'GUI/resultsExtra.html', context)
def querySideBySide(request): if request.method == 'POST': with connection.cursor() as cursor: one = request.POST.get('itemOneChoice') two = request.POST.get('itemTwoChoice') se1 = '' se2 = '' condListOne = [] condListTwo = [] measurementList = {} measurementList2 = {} # Get both experiments and convert their measurementlists into list of ints # Get first experiment conditions and then measurements query = 'SELECT * FROM GUI_Experiment WHERE id = "{}" '.format( sqlescape(one)) cursor.execute(query) expOneFound = cursor.fetchall() for a in expOneFound[0][3]: query = 'SELECT * FROM GUI_SpecificMeasurement WHERE id = "{}" '.format( sqlescape(a)) cursor.execute(query) s = cursor.fetchall() if len(s) > 0: condListOne.append(s[0][1]) for a in expOneFound[0][2]: query = 'SELECT * FROM GUI_SpecificCondition WHERE id = "{}" '.format( sqlescape(a)) cursor.execute(query) s = cursor.fetchall() if len(s) > 0: se1 += str(s[0][1]) + ':' + str(s[0][2]) + ' ' # Get second experiment conditions and then measurements query = 'SELECT * FROM GUI_Experiment WHERE id = "{}" '.format( sqlescape(two)) cursor.execute(query) expTwoFound = cursor.fetchall() for a in expTwoFound[0][3]: query = 'SELECT * FROM GUI_SpecificMeasurement WHERE id = "{}" '.format( sqlescape(a)) cursor.execute(query) s = cursor.fetchall() if len(s) > 0: condListTwo.append(s[0][1]) for a in expTwoFound[0][2]: query = 'SELECT * FROM GUI_SpecificCondition WHERE id = "{}" '.format( sqlescape(a)) cursor.execute(query) s = cursor.fetchall() if len(s) > 0: se2 += str(s[0][1]) + ':' + str(s[0][2]) + ' ' es1 = expOneFound[0][1] es2 = expTwoFound[0][1] condListOneA = set(condListOne) condListTwoA = set(condListTwo) similarSet = condListOneA & condListTwoA for a in similarSet: for b in expOneFound[0][3]: query = 'SELECT * FROM GUI_SpecificMeasurement WHERE id = "{}"'.format( sqlescape(str(b))) cursor.execute(query) measurementFound = cursor.fetchall() if len(measurementFound) > 0: if a == measurementFound[0][1]: mesua = measurementFound[0] measurementList[mesua[1]] = mesua[2] for a in similarSet: for b in expTwoFound[0][3]: query = 'SELECT * FROM GUI_SpecificMeasurement WHERE id = "{}"'.format( sqlescape(str(b))) cursor.execute(query) measurementFound = cursor.fetchall() if len(measurementFound) > 0: if a == measurementFound[0][1]: mesua = measurementFound[0] measurementList2[mesua[1]] = mesua[2] context = { "data": ({ "es1": es1, "es2": es2, "se1": se1, "se2": se2, "measurements": measurementList, "measurements2": measurementList2 }), "found": True, "compare": True } return render(request, 'GUI/results.html', context)
from sqlescapy import sqlescape # assuming this 2 variables are coming from a user input clean_input = "JhonWick" dangerous_input = "JhonWick'" clean_raw_statement = "\"foo_table\".username='******'" % clean_input dangerous_raw_statement = "\"foo_table\".username='******'" % dangerous_input protected_raw_statement = "\"foo_table\".username='******'" % sqlescape( dangerous_input) clean_query = """ SELECT "foo_table".*, "bar_table".* FROM "foo_table", "bar_table" WHERE "foo_table".id = "bar_table".id AND %s """ % clean_raw_statement dangerous_query = """ SELECT "foo_table".*, "bar_table".* FROM "foo_table", "bar_table" WHERE "foo_table".id = "bar_table".id AND %s """ % dangerous_raw_statement protected_query = """ SELECT "foo_table".*, "bar_table".* FROM "foo_table", "bar_table"
def insertCSV(request): if request.method == 'POST': csv_file = request.FILES['csv_file'] if csv_file.multiple_chunks(): print("File is too big") return render(request, 'GUI/invalidInsert.html') # Read in each line of the csv file try: file_data = csv_file.read().decode("utf-8") except Exception: return render(request, 'GUI/invalidInsert.html') lines = file_data.split("\r\n") # Loop over the lines and save them in db. If error , store as string and then display # First line contains the experiments so read those in first as experiments lineOne = lines[0] if len(lineOne) < 1: return render(request, 'GUI/invalidInsert.html') if lineOne[0] == ',': lineOne = lineOne[1:] fields = lineOne.split(",") if len(fields) == 0: return render(request, 'GUI/invalidInsert.html') seqCond = {} conds = [] measurements = [] count = 0 with connection.cursor() as cursor: # Each is a particular seq with its conditions for exp in fields: # insert into db the sequence if it doesnt exist(line[0]) line = exp.split("_") if len(line) < 2: return render(request, 'GUI/invalidInsert.html') seqCond[count] = line[0] conds.append([]) measurements.append([]) sql_search_query = "SELECT * FROM GUI_Sequence WHERE name=%s" seqQuery = (sqlescape(line[0]), ) cursor.execute(sql_search_query, seqQuery) sequenceFound = cursor.fetchall() if len(sequenceFound) == 0: newSeq = Sequence(name=sqlescape(line[0]), info="Nothing") newSeq.save() print("Inserting ", line[0], " into the database as a sequence") else: print(line[0], " is already inserted into the database") # Insert into db the specific condition and if it doesnt exist store the id for i in range(1, len(line), 2): # Check if a condition exists with that name else insert it sql_search_query = "SELECT * FROM GUI_Condition WHERE name=%s" ConQuery = (sqlescape(line[i]), ) cursor.execute(sql_search_query, ConQuery) conFound = cursor.fetchall() if len(conFound) == 0: newCon = Condition(name=sqlescape(line[i]), domain="String", possValues="any") newCon.save() # Check if the specific condition exists else insert it sql_search_query = "SELECT * FROM GUI_SpecificCondition WHERE name=%s AND value=%s" SpecConQuery = ( sqlescape(line[i]), sqlescape(line[i + 1]), ) cursor.execute(sql_search_query, SpecConQuery) SpecConFound = cursor.fetchall() if len(SpecConFound) == 0: newSpecCon = SpecificCondition(name=sqlescape(line[i]), value=sqlescape( line[i + 1])) newSpecCon.save() print("Added new specific condition : ", newSpecCon.id) conds[count].append(newSpecCon.id) else: print("Found previous specific condition: ", SpecConFound[0][0]) conds[count].append(SpecConFound[0][0]) count += 1 # Each is a specific measurement for line in lines[1:-1]: fields = line.split(",") if len(line) == 0: return render(request, 'GUI/invalidInsert.html') data_dict = {'measurement': fields[0]} print(data_dict['measurement']) curr = 0 # Check if a measurement exists with that name else insert it sql_search_query = "SELECT * FROM GUI_Measurement WHERE name=%s" measurementQuery = (sqlescape(fields[0]), ) cursor.execute(sql_search_query, measurementQuery) measurementFound = cursor.fetchall() if len(measurementFound) == 0: newMeasurement = Measurement(name=sqlescape(fields[0]), domain="String", possValues="any") newMeasurement.save() # Insert into db the specific measurement and if it doesnt exist store the id for exp in fields[1:]: sql_search_query = "SELECT * FROM GUI_SpecificMeasurement WHERE name=%s AND value=%s" SpecMeaQuery = ( sqlescape(fields[0]), sqlescape(exp), ) cursor.execute(sql_search_query, SpecMeaQuery) SpecMeaFound = cursor.fetchall() if len(SpecMeaFound) == 0: newSpecMea = SpecificMeasurement(name=sqlescape( fields[0]), value=sqlescape(exp)) newSpecMea.save() print("\tAdded new specific measurement : ", newSpecMea.id) measurements[curr].append(newSpecMea.id) else: print("\tFound previous specific measurement: ", SpecMeaFound[0][0]) measurements[curr].append(SpecMeaFound[0][0]) curr += 1 while curr < count: print("\tSequence ", curr, " has var " + fields[0] + " of null") curr += 1 # For each combo of sequences and conditions insert all of the measurements for that seqCond # to make an experiment if it doesnt exist it = 0 while it < count: conds[it].sort() print(seqCond[it], " has conditions:", str(conds[it]).strip('[]'), " and measurements:", str(measurements[it]).strip('[]')) sql_search_query = "SELECT * FROM GUI_Experiment WHERE sequence=%s AND conditions=%s" SpecCond = str(conds[it]).strip('[]') SpecMeasure = str(measurements[it]).strip('[]') expQuery = ( sqlescape(seqCond[it]), sqlescape(SpecCond), ) cursor.execute(sql_search_query, expQuery) expFound = cursor.fetchall() if len(expFound) == 0: newExp = Experiment(sequence=sqlescape(seqCond[it]), conditions=sqlescape(SpecCond), measurements=sqlescape(SpecMeasure)) newExp.save() print("Experiment was inserted.") else: print( "Experiment has already been recorded. Try another experiment" ) it += 1 return render(request, 'GUI/insertedComplete.html')
def dataInputExperiment(request): if request.method == 'POST': with connection.cursor() as cursor: seqName = request.POST.get('name') condList = request.POST.get('conditions') measList = request.POST.get('measurements') conditionsList = [] measurementsList = [] # Check if that sequence already exists sql_search_query = "SELECT * FROM GUI_Sequence WHERE name=%s" seqQuery = (sqlescape(seqName), ) cursor.execute(sql_search_query, seqQuery) seqFound = cursor.fetchall() if len(seqFound) > 0: # For each condition check if it exists conList = condList.split(',') flag = 1 for a in conList: a = a.strip() aa = a.split(':') if len(aa) < 2: return render(request, 'GUI/error.html') sql_search_query = "SELECT * FROM GUI_Condition WHERE name=%s" seqQuery = (sqlescape(aa[0]), ) cursor.execute(sql_search_query, seqQuery) seqFound = cursor.fetchall() if len(seqFound) == 0: flag = 0 flag2 = 1 if flag: meaList = measList.split(',') print(measList) for b in meaList: b = b.strip() bb = b.split(':') print(bb) if len(bb) < 2: return render(request, 'GUI/error.html') sql_search_query = "SELECT * FROM GUI_Measurement WHERE name=%s" seqQuery = (sqlescape(bb[0]), ) cursor.execute(sql_search_query, seqQuery) meaFound = cursor.fetchall() if len(meaFound) == 0: flag2 = 0 if flag2: # insert all specific conditions and specific measurements then insert the experiment # only if they dont exist, else just add the ids of those found # TODO: !!!!!!!! print("Condition : ", conList) for a in conList: aa = a.split(':') if len(aa) < 2: return render(request, 'GUI/error.html') print(aa) query = 'SELECT * FROM GUI_SpecificCondition WHERE name="{}" AND value="{}"'.format( sqlescape(aa[0]), sqlescape(aa[1])) cursor.execute(query) specCondFounda = cursor.fetchall() if len(specCondFounda) == 0: newSpecCon = SpecificCondition( name=sqlescape(aa[0]), value=sqlescape(aa[1])) newSpecCon.save() conditionsList.append(newSpecCon.id) else: conditionsList.append(specCondFounda[0][0]) print("Measurement : ", meaList) for b in meaList: bb = b.split(':') if len(bb) < 2: return render(request, 'GUI/error.html') print(bb) query = 'SELECT * FROM GUI_SpecificMeasurement WHERE name="{}" AND value="{}"'.format( sqlescape(bb[0]), sqlescape(bb[1])) cursor.execute(query) specMeasuFound = cursor.fetchall() if len(specMeasuFound) == 0: newSpecMea = SpecificMeasurement( name=sqlescape(bb[0]), value=sqlescape(bb[1])) newSpecMea.save() measurementsList.append(newSpecMea.id) else: measurementsList.append(specMeasuFound[0][0]) SpecCond = str(conditionsList).strip('[]') SpecMeau = str(measurementsList).strip('[]') query = 'SELECT * FROM GUI_Experiment WHERE sequence="{}" AND conditions="{}"'.format( sqlescape(seqName), sqlescape(SpecCond)) cursor.execute(query) exMeasuFound = cursor.fetchall() if len(exMeasuFound) == 0: newExp = Experiment(sequence=sqlescape(seqName), conditions=sqlescape(SpecCond), measurements=sqlescape(SpecMeau)) newExp.save() else: print("Experiment has already been recorded") query = 'UPDATE GUI_Experiment SET measurements ="{}" WHERE sequence="{}" AND conditions="{}"'.format( sqlescape(SpecMeau), sqlescape(seqName), sqlescape(SpecCond)) cursor.execute(query) return render(request, 'GUI/updated.html') else: print("No sequence found") return error(request) return render(request, 'GUI/insertedComplete.html')
if last_sold_exist==2: last_sold =browser.find_element_by_class_name('dp-price-history-block').find_elements_by_tag_name('div')[1].find_elements_by_tag_name('span')[1].get_attribute('innerHTML').replace('\xA3','').replace(',','') Price_Changes = int(property_price) - int(last_sold) else: Price_Changes = '0' date1 = datetime.datetime.strptime('{}'.format(first_listed_date_new), '%d %b %Y').strftime('%d,%m,%Y') today = date.today() today_new = datetime.datetime.strptime('{}'.format(today),'%Y-%m-%d').strftime('%d,%m,%Y') def days_between(d1, d2): d1 = datetime.datetime.strptime(d1,'%d,%m,%Y') d2 = datetime.datetime.strptime(d2,'%d,%m,%Y') return abs((d2 - d1).days) Changes_date = days_between('{}'.format(today_new),'{}'.format(date1)) sql = """INSERT INTO zoopla_wales (Area,Keyword,Postal_code,Address,Bedrooms,Bathrooms,Receptions,Proerty_type,Property_price,Price_changes,Detail_urls,First_listed_date,Last_listed,Time_since_first_listed,Agent_name) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s',%s,'%s','%s','%s',%s,'%s')""" % (sqlescape(area),sqlescape(keyword),postal_code_new,sqlescape(address),sqlescape(bedroom),sqlescape(bathroom),sqlescape(reception),sqlescape(property_type),sqlescape(property_price),Price_Changes,sqlescape(detail_urls),sqlescape(first_listed_date),sqlescape(last_sold),Changes_date,sqlescape(agent_name)) mycursor.execute(sql) mydb.commit() except NoSuchElementException: address = 'N/A' bedroom = 'N/A' bathroom = 'N/A' reception = 'N/A' last_sold = 'N/A' Price_Changes = 'N/A' property_type = 'N/A' property_price = 'N/A' agent_name = 'N/A' first_listed_date = 'N/A' Changes_date = 'N/A'
comma = '' for fieldname in netblocksFullFieldnames: if fieldname in set(netblocksSchema.keys()): if str(row[fieldname]).strip() == '': insertstring += comma + 'Null' else: if netblocksSchema[fieldname][0] == 'varchar': insertstring += comma + "'%s'" % row[ fieldname].replace("'", "\\'") elif netblocksSchema[fieldname][0] == 'date': insertstring += comma + datetime.datetime.strptime( row[fieldname], "%Y-%m-%dT%H:%M:%SZ" ).strftime('\'%Y-%m-%d %H:%M:%S\'') elif fieldname == 'remarks': if REMARKS_FIELD: insertstring += comma + "'%s'" % sqlescapy.sqlescape( row['remarks']) else: insertstring += comma + 'Null' else: insertstring += comma + "'%s'" % row[fieldname] comma = ',' if args.r_tree_index: insertstring += ", ST_GEOMFROMWKB(ST_AsWKB(Polygon(LineString(Point(%f,-1),Point(%f,-1),Point(%f,1),Point(%f,1), Point(%f, -1)))),0)" % ( row['inetnumFirst'] - 0.5, row['inetnumLast'] + 0.5, row['inetnumLast'] + 0.5, row['inetnumFirst'] - 0.5, row['inetnumFirst'] - 0.5) insertstring += ')' try: cursor.execute(insertstring) except Exception as e: if not args.no_mysql_error_reports:
Zkr: {} FFikar: {} Egyeztet: {} Kontakt: {} Státusz: {} Külszáll: {} Megjegy: {}'''.format( c1.value, c2.value, c3.value, c4.value, c5.value, c6.value, c7.value, c8.value, c9.value)) sql = "INSERT INTO aut (sorsz,datum,ceg,kezd,hely,musor,kontakt,megjegyzes,helykod) VALUES ( NULL," c2db = c2.value.split( '/') # A 0 az időpont/helyszín, az 1 pedig a műsor. idopont = re.match('[0-9][0-9].?[0-9][0-9]', c2db[0]) try: c2db[1] = c2db[1].strip() musor = sqlescapy.sqlescape(c2db[1]) # musor = re.escape(c2db[1]) except IndexError: musor = 'Nincs megadva műsor.' logging.debug('IndexError - Nincs megadva műsor.') if idopont: logging.debug('Van időpont!') # kezdes = c1.value.replace(hour=int(idopont.group()[:2]), minute=00) kezdes = idopont.group() hely = c2db[0].replace(kezdes, '', 1) hely = hely.strip() # ely elejéről levesszük a spacet logging.debug('Helyszín eredménye: ' + hely) else: kezdes = 'Nincs megadva kezdés.' hely = c2db[0]