def index(): if request.method == 'POST': sql = request.form['sql'] try: conn.isRuning(RPC_Server) conn_1 = conn.create_conn(b_1) except NameError as e: conn.sendText(RPC_Server, e) return render_template( 'index.html', error='No se puede conectar a las bases de datos') except (TimeoutError, ConnectionRefusedError): return render_template( 'index.html', error='No se puede conectar al servidor RPC') else: try: conn.execute(conn_1, sql) except NameError as e: conn.sendText(RPC_Server, e) return render_template('index.html', error='Sql invalido') else: conn.commit(conn_1) conn.sendText(RPC_Server, 'Consultas ejecutadas con exito') return render_template( 'index.html', message='Consultas ejecutadas con exito') else: return render_template('index.html')
def execute(self, render=True): rendered = RenderManagers().render(self) if render: return rendered else: connection.setup(['localhost:9160:demodb']) connection.execute(rendered) print ("Hello")
def delete_token(userid): """ delete token with provided userid """ res = connection.execute( """ DELETE FROM tokens WHERE userid=? """, (userid, )) return res == []
def get_request_pair(userid): """ return ( userid, req_secret ) pair for provided userid or None """ res = connection.execute( """ SELECT userid, reqsec from temp_request WHERE userid=? """, (userid, )) return res[0] if res else None
def save_unverified_request(userid, req_secret): """ save unverified request keys """ res = connection.execute( """ INSERT OR IGNORE INTO temp_request(userid,reqsec) VALUES (?,?) """, (userid, req_secret)) return res == []
def get_access_pair(userid): """ return ( acc_key, acc_secret ) for provided userid or None """ res = connection.execute( """ SELECT accsec, acckey from tokens WHERE userid=? """, (userid, )) return res[0] if res else None
def execute(self, render=True): rendered = RenderQuery().render(self) if render: return rendered else: connection.setup(["localhost:9160:demodb"]) query = connection.execute(rendered) print ("Executed Successfully") return query
def get_table_names(self, connection, schema): string = 'SHOW TABLES FROM %s;' % schema rv = None try: rv = connection.execute(string) except Exception as e: print(e) if rv is not None: return [row[0] for row in rv.fetchall()]
def _get_show_create_table(self, connection, table_name): string = 'SHOW CREATE TABLE %s;' % table_name rv = None try: rv = connection.execute(string) except Exception as e: print(e) row = rv.fetchone() return row[1].strip()
#app.config["SQLALCHEMY_DATABASE_URI"] = (connection.db_connect) #app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.secret_key = "development-key" # Create an engine that stores data in the local db file # engine = create_engine('postgresql://*****:*****@localhost:5432/fitness_log') try: engine = create_engine(connection.db_connect) print("*** Fitness Journal: Inside routes.py ***") print(connection.db_connect) # <<<<< TEST >>>>> connection = engine.connect() result = connection.execute("SELECT * FROM fitness_log.customers;") for row in result: print("row:", row['first_name'], row['last_name'], row['birthdate']) # <<<<< TEST >>>>> except exc.SQLAlchemyError: print("\n *** Oh crap. Something went wrong! *** \n") # Bind the engine to the metadata of the Base class so that the # declaratives can be accessed through a DBSession instance Base.metadata.bind = engine DBSession = sessionmaker(bind = engine) session = DBSession() @app.route("/") def index():
import os import re from connection import execute os.system("bash scanip.sh") fichier = open("ip.txt","r") lignes = fichier.readlines() for ligne in lignes: execute("INSERT INTO confip (ip) VALUES ('"+ligne+"');")
def prune_temp_request(): """ delete temporary requests tables. Should be called at app startup """ res = connection.execute(""" DELETE FROM temp_request(userid,reqsec) VALUES """) return res==[]
def save_unverified_request( userid, req_secret ): """ save unverified request keys """ res = connection.execute(""" INSERT OR IGNORE INTO temp_request(userid,reqsec) VALUES (?,?) """, (userid,req_secret)) return res==[]
def dump_tokens(): res = connection.execute(""" SELECT * FROM tokens; """) # 2D list of lists return res
def delete_token(userid): """ delete token with provided userid """ res = connection.execute(""" DELETE FROM tokens WHERE userid=? """, (userid,) ) return res==[]
from utils import create_log, show_404 config = configparser.ConfigParser() config.read('constants.cnf') cgitb.enable() form = cgi.FieldStorage() session = Session() employee_id = session.current_user() header = dict() header["title"] = "User Settings" header["css_version"] = config.get("version", "css") footer = {"js_version": config.get("version", "css")} if employee_id: if os.environ['REQUEST_METHOD'] == 'GET': header["homeUrl"] = "http://localhost/profiles.py" user = execute(BaseClass.user_name(employee_id))["fetchall"][0] user_name = user["firstName"] + ' ' + user["lastName"] top_right_link = '<a href="http://localhost/logout.py">Logout</a>' header[ "navTopRight"] = '<li class="active"><a>%s</a></li><li class="active">%s</li>' % ( user_name, top_right_link) print("Content-type: text/html") print('') f = open('./template/header.html') print(f.read() % header) f.close() f = open('./template/user_settings.html') print(f.read()) f.close() f = open('./template/footer.html') print(f.read() % footer)
def func(url, payload): j = s.post(url, data=payload) print(j) page = BeautifulSoup(j.text, 'html.parser') # print(page) rows = page.findAll('div', {'class': 'row', 'type': 'tuple'}) count = 0 for i in rows: title, company, experience, location, job_desc, compensation, job_type = 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', \ 'NULL', 'NULL' a_tag = i.find('a', {'class': 'content'}) link = a_tag['href'] jd = s.get(link) job_details = BeautifulSoup(jd.text, 'html.parser') job_title = job_details.find('h1', {'itemprop': 'title'}) pattern = r'[0-9]{12}' job_id = int(re.findall(pattern, link)[0]) query = 'select job_id from naukri_banglore where job_id={}'.format( job_id) data = [int(t[0]) for t in execute(query)] if job_id not in data: if job_title: title = job_title.text cmpny = job_details.find('a', {'itemprop': 'hiringOrganization'}) if cmpny: company = cmpny.text # print(company) count = count + 1 else: print(link) exp = job_details.find('span', {'itemprop': 'experienceRequirements'}) if exp: experience = exp.text loc = job_details.find('div', {'itemprop': 'name'}) if loc: location = loc.text desc = job_details.find('ul', {'itemprop': 'description'}) if desc: job_desc = desc.text salary = job_details.find('span', {'itemprop': 'baseSalary'}) if salary: compensation = salary.text emp_type = job_details.findAll( 'span', {'itemprop': 'occupationalCategory'}) if emp_type: job_type = (emp_type)[-1].text.strip() query = 'insert into naukri_banglore(job_id, job_title, job_description, compensation, ' \ 'job_type,company,experience,job_link) values (%s, %s, %s, %s, %s, %s, %s, %s)' values = (job_id, title, job_desc, compensation, job_type, company, experience, link) execute(query, values) print(count)
def func(url): s = requests.Session() r = s.get( url, headers={ "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" }) page = BeautifulSoup(r.text, 'html.parser') link = page.findAll('a', {'class': 'jobLink'}) count = 0 for i in link: if i.text: job_link = "https://www.glassdoor.co.in" + i['href'] job_id = int(re.findall(r'[0-9]{10}$', job_link)[0]) query = 'select job_id from naukri_banglore where job_id={} and platform="Glassdoor"'.format( job_id) data = [int(t[0]) for t in execute(query)] if job_id not in data: count = count + 1 job = s.get( job_link, headers={ "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" }) job_details = BeautifulSoup(job.text, 'html.parser') title = job_details.find( 'h2', {'class': 'noMargTop margBotXs strong'}) if title: title = title.text.encode('utf8') else: print(job_link) continue cmpny_name = job_details.find('span', {'class': 'strong ib'}) if cmpny_name: cmpny_name = cmpny_name.text.strip().encode('utf8') else: print(job_link) continue try: job_desc1 = job_details.find('div', {'class': 'jobDesc '}) if job_desc1: job_desc1 = job_desc1.text.encode("utf-8") except: job_desc1 = job_details.find('div', { 'class': 'jobDescriptionContent desc module pad noMargBot' }) if job_desc1: job_desc1 = job_desc1.text.encode("utf-8") if job_desc1: query = 'insert into naukri_banglore(job_id, job_title, job_description,' \ 'company,job_link,platform) values (%s, %s, %s, %s, %s, %s)' values = (job_id, title, job_desc1, cmpny_name, job_link, 'Glassdoor') execute(query, values) else: print(job_link) continue print(count)
def prune_temp_request(): """ delete temporary requests tables. Should be called at app startup """ res = connection.execute(""" DELETE FROM temp_request(userid,reqsec) VALUES """) return res == []
from connection import execute from model import BaseClass from session import Session from utils import create_log, show_404 config = configparser.ConfigParser() config.read('constants.cnf') session = Session() employee_id = session.current_user() header = dict() header["title"] = "Edit Profile" if employee_id: header["homeUrl"] = "http://localhost/profiles.py" user = execute(BaseClass.user_name(employee_id))["fetchall"][0] user_name = user["firstName"] + ' ' + user["lastName"] top_right_link = '<a href="http://localhost/logout.py">Logout</a>' header[ "navTopRight"] = '<li class="active"><a>%s</a></li><li class="active">%s</li>' % ( user_name, top_right_link) header["css_version"] = config.get("version", "css") footer = {"js_version": config.get("version", "css")} if os.environ['REQUEST_METHOD'] == 'GET': print("Content-type: text/html\n") f = open('./template/header.html', encoding='utf-8') print(f.read() % header) f.close() f = open('./template/profiles.html') print(f.read()) f.close()
es = Elasticsearch() db = connect_sql() cursor = db.cursor() query = "select * from naukri_banglore where elasticsearch=0" cursor.execute(query) jd = cursor.fetchall() columns = [col[0] for col in cursor.description] for i in jd: job = dict(zip(columns, i)) # print(job) data = {} for j in job: if job[j] != 'NULL': if isinstance(job[j], str): data[j] = job[j].decode("latin1") else: data[j] = job[j] try: doc = es.index(index='jobs', doc_type='job_description', id=data['id'], body=data) query1 = 'update naukri_banglore set elasticsearch=1 where job_id={}'.format( data['job_id']) execute(query1) except Exception as e: print(e) break
def get_request_pair(userid): """ return ( userid, req_secret ) pair for provided userid or None """ res = connection.execute(""" SELECT userid, reqsec from temp_request WHERE userid=? """, (userid,)) return res[0] if res else None
def save_access_tokens(userid, req_secret, acc_key, acc_secret): res = connection.execute( """ INSERT OR IGNORE INTO tokens(userid,reqsec,accsec,acckey) VALUES (?,?,?,?) """, (userid, req_secret, acc_key, acc_secret)) return res == []
def save_access_tokens(userid, req_secret, acc_key, acc_secret): res = connection.execute(""" INSERT OR IGNORE INTO tokens(userid,reqsec,accsec,acckey) VALUES (?,?,?,?) """, (userid,req_secret, acc_key, acc_secret)) return res==[]
def get_access_pair(userid): """ return ( acc_key, acc_secret ) for provided userid or None """ res = connection.execute(""" SELECT accsec, acckey from tokens WHERE userid=? """, (userid,)) return res[0] if res else None
from utils import create_log, get_formvalues, save_uploaded_file, show_404 cgitb.enable() config = configparser.ConfigParser() config.read('constants.cnf') session = Session() employee_id = session.current_user() header = dict() header["title"] = "Edit Profile" header["css_version"] = config.get("version", "css") footer = { "js_version": config.get("version", "css") } if employee_id: header["homeUrl"] = "http://localhost/profiles.py" user = execute(BaseClass.user_name(employee_id))["fetchall"][0] user_name = user["firstName"] + ' ' + user["lastName"] top_right_link = '<a href="http://localhost/logout.py">Logout</a>' header["navTopRight"] = '<li class="active"><a>%s</a></li><li class="active">%s</li>' % ( user_name, top_right_link) if os.environ['REQUEST_METHOD'] == 'GET': form = cgi.FieldStorage() employee_query = execute(["SELECT firstName, lastName, email, dob, image_extension, preferCommun, prefix," " maritalStatus, employer,employment FROM employee WHERE id=%s", (str(employee_id),)])["fetchall"][0] employee_columns = { "firstName": employee_query["firstName"], "lastName": employee_query["lastName"], "email": employee_query["email"], "dob": employee_query["dob"], "image": './static/profile_images/' + str(employee_id) + '.' + employee_query["image_extension"],
} if os.environ['REQUEST_METHOD'] == 'GET': print("Content-type: text/html\n") f = open('./template/header.html') print(f.read() % header) f.close() f = open('./template/register.html') print(f.read()) f.close() f = open('./template/footer.html') print(f.read() % footer) f.close() elif os.environ['REQUEST_METHOD'] == 'POST': print("Content-type:text/html\r\n\r\n") dict_fields = get_formvalues() e = Employee(dict_fields) insert_query = e.insert_employee() activation = e.activation() last_id = execute(insert_query)["lastrowid"] if dict_fields['photo'].filename: image_ext = dict_fields['photo'].filename.split('.')[-1] image_name = str(last_id) + '.' + image_ext image_query = e.set_image(image_ext, str(last_id)) execute(image_query) save_uploaded_file(dict_fields['photo'], config.get('profile', 'path'), image_name) print("Please click on activation link sent in email in order to complete registration process.") send_email(dict_fields["email"], activation) except Exception as e: create_log("Register.py : "+str(e)) show_404()