def does_ticket_exist(username): # Sets the path path = '/tmp' a = False try: # Get list of items in the path for i in os.listdir(path): if a == True: break # Change the working directory to the path os.chdir(path) # File and directory check if os.path.isdir(i): continue if os.path.isfile(i): # Open the file hand = open(i) # Search for username for line in hand: if re.search(username, line): break a = True else: continue except IOError, e: error_logging("Kerb_Auth_Check", e)
def does_ticket_exist(username): # Sets the path path = '/tmp' a = False try: # Get list of items in the path for i in os.listdir(path): if a == True: break # Change the working directory to the path os.chdir(path) # File and directory check if os.path.isdir(i): continue if os.path.isfile(i): # Open the file hand = open(i) # Search for username for line in hand: if re.search(username,line): break a = True else: continue except IOError, e: error_logging("Kerb_Auth_Check", e)
def get_user(connection, user_name): try: cur = create_connection() cur.execute("SELECT user_service FROM user WHERE username = %s", user_name) user_service = cur.fetchall() return user_service except: wsLogging.error_logging("Get User", "Couldn't send user token")
def create_connection(): try: cnx = MySQLdb.connect(host = "localhost", user = "******", passwd = "Team5", db = "testDB") cur = cnx.cursor() wsLogging.audit_logging("CRUD", "String created") return cur except: wsLogging.error_logging("CRUD","Error during Connection")
def compute_error_for_line_give_points(b,m,points): try: totalError = 0 for i in range(0,len(points)): y,x = points[i] totalError += (y - (m * x + b)) ** 2 return totalError/float(len(points)) except: error_logging("ConEngine", "Error in computer error")
def itemFinder(search_item,inten): items = [] intens = int(inten) try: api = Finding(appid="ScottRus-bf7d-437a-a830-3735324dd553",config_file=None,debug=True) for page_num in range(intens): # TODO: Change back to range later response = api.execute('findCompletedItems', {'keywords': search_item,'paginationInput': {'entriesPerPage': 100, 'pageNumber':page_num}}) response_dict = response.dict() if response_dict['ack'] == 'Failure': continue else: items.append(response.dict()) except: error_logging("ConEng", "Failed") for s_item in items: # Assign searchResult value to variable search_result = s_item['searchResult'] # Assign item value to item_array item_array = search_result['item'] count = 0 try: for item in item_array: count += 1 # Get selling status selling_status_price = item['sellingStatus'] selling_status_price = item['sellingStatus'] #Get current price current_price = selling_status_price['currentPrice'] value = float(current_price['value']) # Store price in price_array price_array.append(value) # Get the listingInfo listing_info = item['listingInfo'] # Get endTime end_time = listing_info['endTime'] sliced_date = end_time[:10] a = dt.strptime(sliced_date, '%Y-%m-%d').date() # Start date star_date = datetime.date(2015,1,1) delta = a - star_date # Get date number relative to the year int_delta = int(delta.days) # Store Date in date array date_array.append(int_delta) # Y X pair point_tuple = (value,int_delta) point_array.append(point_tuple) except: error_logging("ConEng", "Failed")
def send_to(Message): try: channel.basic_publish(exchange='', routing_key="FirstQ", body=str(Message)) #Logs process audit_logging("RabbitSend","Sent to queue") connection.close() except: # Logs Process error_logging("RabbitSend","Couldn't Send")
def return_jwt(username): try: # Create connection to DB con = create_connection() #Get user and their services and parse out the dict taht is sent back user_service_array = get_user(con, username) user_service_tuple = user_service_array[0] service_unpacked = user_service_tuple[0] encoded = jwt.encode({'user_service': service_unpacked},'secret', algorithm='HS256') wsLogging.audit_logging("Create_Token", "Toek was created") return encoded except: wsLogging.error_logging("Create_Token","Error when creating token")
def step_gradient(b_current, m_current, points, learningRate): try: b_gradient = 0 m_gradient = 0 N = float(len(points)) for i in range(0, len(points)): y,x = points[i] b_gradient += -(2/N) * (y - ((m_current * x) + b_current)) m_gradient += -(2/N) * x * (y - ((m_current * x) + b_current)) new_b = b_current - (learningRate * b_gradient) new_m = m_current - (learningRate * m_gradient) return [new_b, new_m] except: error_logging("webService", "Error in computer error")
def runtest (search_item,search_intensity,what_day): try: #std_div_price = numpy.std(price_array) #std_div_date = stats.stats.tstd(date_array) try: day = int(what_day) error = None new_b, new_m = None, None itemFinder(search_item,search_intensity) (m,b) = pylab.polyfit(date_array,price_array,1) # Iterations for Step Gradient for i in range(100): new_b, new_m = step_gradient(b,m,point_array,1) error = compute_error_for_line_give_points(new_b,new_m,point_array) mean_of_item = numpy.mean(price_array) std_div_price = numpy.std(price_array) predict_value = ((new_m*(day)) + new_b) print predict_value client_message = ("The new b {0}, the new m {1}, the error {2} this is for {3}\n" "The mean of the {3} is {5}\n" "Standard Deviations for {3} is {4} for the price\n" "The price of your value on {6} day is estimated to be ".format(new_b, new_m,error, search_item, std_div_price, mean_of_item, what_day, predict_value)+ str(predict_value)) except: error("ConEng", "RunTest Method parsing, and calculation won't work") try: #Sends to RabitMQ, incase client loses connection or long process rabbit_send.send_to(client_message) except: error("ConEngine", "Error with rabbitsening") return client_message except: error_logging("ConEngine", "Error in runtest") # print len(price_array) # print len(date_array)
class SoapService(SimpleWSGISoapApp): """Class for webservice """ ##Login method try: @soapmethod(soap_types.String, soap_types.String, _returns=soap_types.Boolean) def service_login(self, username, password): if auth_kinit(username, password) == True: audit_logging("webService", "Login successful") #Send Json token with permissions else: audit_logging("webService", "Login Failed") #Send message with failure return False except TypeError, e: error_logging("webService", e)
def does_ticket_exist(username): # Sets the path path = '/tmp' a = False try: # Get list of items in the path for i in os.listdir(path): if a == True: break # Change the working directory to the path os.chdir(path) # File and directory check if os.path.isdir(i): continue if os.path.isfile(i): # Open the file hand = open(i) # Search for username for line in hand: if re.search(username, line): break a = True else: continue except IOError, e: error_logging("Kerb_Auth_Check", e) except Exception, e: error_logging("Kerb_Auth_Check", e) return a
path = '/tmp' a = False try: # Get list of items in the path for i in os.listdir(path): if a == True: break # Change the working directory to the path os.chdir(path) # File and directory check if os.path.isdir(i): continue if os.path.isfile(i): # Open the file hand = open(i) # Search for username for line in hand: if re.search(username,line): break a = True else: continue except IOError, e: error_logging("Kerb_Auth_Check", e) except Exception, e: error_logging("Kerb_Auth_Check", e) return a
def service_login(self, username, password): if auth_kinit(username, password) == True: audit_logging("webService", "Login successful") #Send Json token with permissions else: audit_logging("webService", "Login Failed") #Send message with failure return False except TypeError, e: error_logging("webService", e) except: error_logging("webService", "Failed") #if does_ticket_exist() == True: # @soapmethod(soap_types.String, _returns=soap_types.String) # def ebay_service(self,keyword): # return ebayFinder.itemFinder(keyword) #Methods here are for how web service communicates class EbayServ(SoapService): """Class for web.py """ def start_response(self, status, headers): web.ctx.status = status for header, value in headers: web.header(header, value)
def test_error_logging_create(self): log = wsLogging.error_logging("UnitTest","Something") self.assertFalse(log)
def start_consume(): try: audit_logging("Rabbit Recieve", "started consume") channel.start_consuming() except: error_logging("Rabbit Receive", "Error running CallBack")
import pika from wsLogging import error_logging, audit_logging connection = pika.BlockingConnection(pika.ConnectionParameters( host='localhost')) channel = connection.channel() channel.queue_declare(queue='FirstQ') def callback(ch, method, properties, body): print " [x] Received %r" % (body,) try: channel.basic_consume(callback, queue='FirstQ', no_ack=True) audit_logging("Rabbit Receive", "Basic consume") except: error_logging("Rabbit Receive", "Error running CallBack") def start_consume(): try: audit_logging("Rabbit Recieve", "started consume") channel.start_consuming() except: error_logging("Rabbit Receive", "Error running CallBack")
import pika from wsLogging import error_logging, audit_logging try: # Creates connection we can specify an ipAddress later connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) # Sets up connection channel = connection.channel() channel.queue_declare(queue='FirstQ') # Logs audit_logging("Rabbit Send", "Connected to Queue") except: error_logging("RabbitSend","Couldn't Create connection") def send_to(Message): try: channel.basic_publish(exchange='', routing_key="FirstQ", body=str(Message)) #Logs process audit_logging("RabbitSend","Sent to queue") connection.close() except: # Logs Process error_logging("RabbitSend","Couldn't Send")
# TODO: Currenly making one call should be multiple calls, meaning that username,passwrod, and search is sent here @soapmethod(soap_types.String, soap_types.String, soap_types.String, _returns=soap_types.String) def service_login(self,username, password,search): if auth_kinit(username, password) == True: audit_logging("webService", "Login successful") #Send Json token with permissions return return_jwt(username) else: audit_logging("webService", "Login Failed") #Send message with failure return "Failed to connect to service" except TypeError, e: error_logging("webService", e) except: error_logging("webService", "Failed") # Prediction Method try: @soapmethod(soap_types.String,soap_types.Integer,soap_types.String,_returns=soap_types.String) def prediction(self,search_request,search_intensity,predictor_day): return ConEng.runtest(search_request,search_intensity,predictor_day) except TypeError, e: error_logging("webService", e) except: error_logging("webService", "Failed") #if does_ticket_exist() == True: # @soapmethod(soap_types.String, _returns=soap_types.String) # def ebay_service(self,keyword): # return ebayFinder.itemFinder(keyword)