def worker(): while not q.empty() : try: line = q.get() payload = line[4:].split(' ')[0] output = subprocess.check_output(["sudo", "msfvenom", "-p", payload, "-f", "python"]).split('\n')[1:-1] code = "" for outline in output: code +=outline.split(" ")[2] code = code.encode("hex") db_connector.insert(code) q.task_done() except Exception as e: pass
def users(user_id): if request.method == 'POST': request_data = request.json user_name = request_data.get('user_name') result = insert(user_id, user_name) if result==1: return {'status': 'ok', 'user_added': user_name}, 200 # status code elif result==2: return {'status': 'error', 'reason': 'id already exists'}, 500 elif result==3: return {'status': 'error', 'reason': "Can't connect to MySQL server"}, 500 else: return {'status': 'error', 'reason': 'unknown'}, 500 elif request.method == 'GET': result = select(user_id) if result not in {2, 3, 4}: return {'status': 'ok', 'user_name': result}, 200 # status code elif result == 2: return {'status': 'error', 'reason': 'no such id'}, 500 elif result == 3: return {'status': 'error', 'reason': "Can't connect to MySQL server"}, 500 else: return {'status': 'error', 'reason': 'unknown'}, 500 elif request.method == 'PUT': request_data = request.json user_name = request_data.get('user_name') result = update(user_id, user_name) if result == 1: return {'status': 'ok', 'user_updated': user_name}, 200 # status code elif result == 2: return {'status': 'error', 'reason': 'no such id'}, 500 elif result == 3: return {'status': 'error', 'reason': "Can't connect to MySQL server"}, 500 else: return {'status': 'error', 'reason': 'unknown'}, 500 elif request.method == 'DELETE': result = delete(user_id) print("delete user",user_id) if result == 1: return {'status': 'ok', 'user_deleted': user_id}, 200 # status code elif result == 2: return {'status': 'error', 'reason': 'no such id'}, 500 elif result == 3: return {'status': 'error', 'reason': "Can't connect to MySQL server"}, 500 else: return {'status': 'error', 'reason': 'unknown'}, 500
def user(user_id): if request.method == 'POST': try: # getting the json data payload from request request_data = request.json # treating request_data as a dictionary to get a specific value from key user_name = request_data.get('user_name') if insert(user_id, user_name): return { 'status': 'ok', 'user_added': user_name }, 200 # status code else: return {'status': 'error', 'reason': 'id already exists'}, 500 except Exception as e: print(e) return {'status': 'error', 'reason': 'id already exists'}, 500 elif request.method == 'GET': try: user_name = select(user_id) return {'status': 'ok', 'user_name': user_name}, 200 # status code except Exception as e: print(e) return {'status': 'error', 'reason': 'no such id'}, 500 elif request.method == 'PUT': try: # getting the json data payload from request request_data = request.json # treating request_data as a dictionary to get a specific value from key user_name = request_data.get('user_name') update(user_id, user_name) return { 'status': 'ok', 'user_updated': user_name }, 200 # status code except Exception as e: print(e) return {'status': 'error', 'reason': 'no such id'}, 500 elif request.method == 'DELETE': try: delete(user_id) return { 'status': 'ok', 'user_deleted': user_id }, 200 # status code except Exception as e: print(e) return {'status': 'error', 'reason': 'no such id'}, 500
def save_to_db(): db_connector.connect() for lang, rss_records in RSS_STACK.items(): for rss_record in rss_records: db_connector.insert(rss_record, "prod" if WRITE_TO_PROD_TABLE else "test")
def save_to_db(stack): db_connector.connect() for rss_record in stack: db_connector.insert(rss_record)
#extract phone number print '\nPHONE' print '-------------------------' match = re.search(r'(?:<a href=\"tel:([0-9]+))', driver.page_source.replace('\n', '')) if match: phone = match.group(1) info.append(str(phone)) print phone else: info.append('') #no phone number found # At this point, we insert this info into the database. if exists: db.replace(c, 'therapists', info, ['therapist_id', 'pt_id', 'name', 'summary', 'phone']) else: db.insert(c, 'therapists', info, ['pt_id', 'name', 'summary', 'phone']) connection.commit() # Get the therapist id (for use in later insertions) NEED TO KEEP TRACK OF THIS IN THE FUTURE FOR UPDATES db.select(c, ['therapist_id'], 'therapists', where='pt_id=' + prof_id) therapist_id = c.fetchone() if therapist_id is None: c.execute('SELECT last_insert_rowid()') therapist_id = c.fetchone()[0] else: therapist_id = therapist_id[0] #extract the profile linked to by the "next" button (for use the next time through the loop) prof_id = re.search(r'ProfileNav_prevProfLink.*?profid=([0-9]+)', driver.page_source.replace('\n', '')).group(1) #extract location
def users(user_id): """ 1. POST – will accept user_name parameter inside the JSON payload. A new user will be created in the database (Please refer to Database section) with the id passed in the URL and with user_name passed in the request payload. ID has to be unique! On success: return JSON : {“status”: “ok”, “user_added”: <USER_NAME>} + code: 200 On error: return JSON : {“status”: “error”, “reason”: ”id already exists”} + code: 500 2. GET – returns the user name stored in the database for a given user id. Following the example: 127.0.0.1:5000/users/1 will return john. On success: return JSON : {“status”: “ok”, “user_name”: <USER_NAME>} + code: 200 On error: return JSON : {“status”: “error”, “reason”: ”no such id”} + code: 500 3. PUT – will modify existing user name (in the database). Following the above example, when posting the below JSON payload to 127.0.0.1:5000/users/1 george will replace john under the id 1 {“user_name”: “george”} On success: return JSON : {“status”: “ok”, “user_updated”: <USER_NAME>} + code: 200 On error: return JSON : {“status”: “error”, “reason”: ”no such id”} + code: 500 4. DELETE – will delete existing user (from database). Following the above (marked) example, when using delete on 127.0.0.1:5000/users/1 The user under the id 1 will be deleted. On success: return JSON : {“status”: “ok”, “user_deleted”: <USER_ID>} + code: 200 On error: return JSON : {“status”: “error”, “reason”: ”no such id”} + code: 500 """ if request.method == 'POST': my_data = request.json user_name = my_data.get("user_name") mycon = select("'Y'", "users", f"user_id = {user_id}") if mycon.rowcount > 0: return json.dumps({ 'status': 'error', 'reason': "ID already exists" }), 500 else: insert("users", "user_id,user_name,creation_date", f"{user_id}, '{user_name}', '{datetime.datetime.now()}'") return json.dumps({'status': 'ok', 'user_added': user_name}), 200 elif request.method == 'GET': mycon = select("user_name", "users", f"user_id = {user_id}") if mycon.rowcount > 0: for row in mycon: return json.dumps({'status': 'ok', 'user_name': row[0]}), 200 else: return json.dumps({'status': 'error', 'reason': "No such ID"}), 500 elif request.method == 'PUT': my_data = request.json user_name = my_data.get("user_name") mycon = select("'Y'", "users", f"user_id = {user_id}") if mycon.rowcount > 0: update("users", f"user_name = '{user_name}'", f"user_id = {user_id}") return json.dumps({'status': 'ok', 'user updated': user_name}), 200 else: return json.dumps({'status': 'error', 'reason': "No such ID"}), 500 elif request.method == 'DELETE': mycon = select("'Y'", "users", f"user_id = {user_id}") if mycon.rowcount > 0: delete("users", f"user_id = {user_id}") return json.dumps({'status': 'ok', 'user deleted': user_id}), 200 else: return json.dumps({'status': 'error', 'reason': "No such ID"}), 500