def login(): data = request.json if data: dataDict = json.loads(json.dumps(data)) if 'user' in dataDict and 'pass' in dataDict: cnx, cur = helper.start() query = 'SELECT `id` FROM Client WHERE `username`=%s AND `password`=%s' cur.execute(query, (dataDict['user'], dataDict['pass'])) theid = cur.fetchone() helper.stop(cnx, cur) if theid[0] > 0: if dataDict['booking']: # deal with booking cnx, cur = helper.start() query = 'SELECT MAX(id) FROM Booking WHERE `client` = %s AND `start_time` >= %s' cur.execute(query, (theid[0], datetime.datetime.now())) ids = cur.fetchone() helper.stop(cnx, cur) return Response(json.dumps({'bookings': ids}), status=200, mimetype='application/json') else: return Response(status=200) else: return helper.error() else: return helper.error() else: return helper.error()
def addCharge(booking, prices, quantities): con, cur = helper.start() #find the owner of the booking query = 'SELECT `Client`.`id` FROM `Client` INNER JOIN `Booking` ON `Client`.`id` = `Booking`.`client` WHERE `Booking`.`id` = %s' cur.execute(query, (booking, )) owner = cur.fetchone()[0] helper.stop(con, cur) #add the total of price[i] * quantities[i] to the owner's account total_charge = 0 for i in range(0, len(prices)): total_charge = total_charge + (prices[i] * quantities[i]) con, cur = helper.start() query = 'SELECT `spend` FROM `Client` WHERE id = %s' cur.execute(query, (owner, )) current_spend = cur.fetchone()[0] helper.stop(con, cur) total_charge = total_charge + current_spend con, cur = helper.start() query = 'UPDATE `Client` SET spend = %s WHERE `Client`.`id` = %s' cur.execute(query, (total_charge, owner)) con.commit() helper.stop(con, cur)
def main(): helper.parser.description( "The NewRelic Plugin Agent polls various " "services and sends the data to the NewRelic " "Platform" ) helper.parser.name("newrelic_plugin_agent") argparse = helper.parser.get() argparse.add_argument("-C", action="store_true", dest="configure", help="Run interactive configuration") args = helper.parser.parse() if args.configure: print("Configuration") sys.exit(0) helper.start(NewRelicPluginAgent)
def main(): """Invoked by the script installed by setuptools.""" parser.name('tinman') parser.description(__desc__) p = parser.get() p.add_argument('-p', '--path', action='store_true', dest='path', help='Path to prepend to the Python system path') helper.start(Controller)
def main(): """Invoked by the script installed by setuptools.""" parser.name('tinman') parser.description(__desc__) p = parser.get() p.add_argument('-p', '--path', action='store', dest='path', help='Path to prepend to the Python system path') helper.start(Controller)
def main(): helper.parser.description('The Statsd Plugin Agent polls various services and sends the data to a statsd agent') helper.parser.name('statsd_plugin_agent') argparse = helper.parser.get() argparse.add_argument('-C', action='store_true', dest='configure', help='Run interactive configuration') args = helper.parser.parse() if args.configure: print('Configuration') sys.exit(0) helper.start(StatsDPluginAgent)
def main(): start() try: charge_no = sys.argv[1] log_date = sys.argv[2] log_date = datetime.datetime.strptime(log_date, '%Y-%m-%d').date() lines = read_log_lines(LogFile.IData, log_date) if not lines: raise Exception('Read nothing from log') sync_info = sync_info_extract(lines, charge_no) info(sync_info.__repr__()) except Exception, e: err('%s\n%s' % (str(e), traceback()))
def main(): helper.parser.description('The NewRelic Plugin Agent polls various ' 'services and sends the data to the NewRelic ' 'Platform') helper.parser.name('newrelic_plugin_agent') argparse = helper.parser.get() argparse.add_argument('-C', action='store_true', dest='configure', help='Run interactive configuration') args = helper.parser.parse() if args.configure: print('Configuration') sys.exit(0) helper.start(NewRelicPluginAgent)
def groupCoors(matrix): actual_coors = [] current_coor = h.start(matrix) #[0, 0] - x y position from top left actual_coors.append(current_coor) # passed takes two args: matrix and coordinate # 8 value matrix: passed([[1, 1] # [0, 1]], [0, 0]) --> [[8, 1] # [0, 1]] matrix = h.passed(matrix, current_coor) print(matrix) possible_coors = h.cardinalOnes(matrix, current_coor) # possible_coors will be [[1, 0], [0, 1]], assuming both are one valued while possible_coors != []: current_coor = possible_coors[0] actual_coors.append(current_coor) matrix = h.passed(matrix, current_coor) print(matrix) possible_coors.remove(current_coor) possible_coors += h.cardinalOnes(matrix, current_coor) return actual_coors
def getNumLounger(): con, cur = helper.start() cur.execute('SELECT COUNT(Lounger.id) ' 'FROM Lounger;') numOfLounger = cur.fetchall() helper.stop(cur, con) numOfLounger = list(numOfLounger[0]) return numOfLounger[0]
def main(): start() try: vpr = sys.argv[1] log_datetime = sys.argv[2] log_datetime = datetime.datetime.strptime(log_datetime, '%Y-%m-%d %H:%M:%S') lines = read_log_lines(LogFile.ParkOut, log_datetime.date()) if not lines: raise Exception('Read nothing from log') park_info = extract_park_info(lines, vpr, log_datetime) if u'出场方式' not in park_info: if u'出口报费' in park_info and park_info[u'出口报费'] == 0: park_info[u'出场方式'] = u'自动抬杆出场' else: park_info[u'出场方式'] = u'未知' info(park_info.__repr__()) except Exception, e: err('%s\n%s' % (str(e), traceback()))
def getLoungerInfo(id): con, cur = helper.start() chair_id = id cur.execute( 'SELECT Lounger.name, Lounger.desc' ' FROM Lounger' ' WHERE Lounger.id = %s' ' LIMIT 1;', (chair_id, )) lounger_info = cur.fetchall() helper.stop(cur, con) return lounger_info[0]
def makeOrder(ids, quantities, booking): # Make the connection and cursor con, cur = helper.start() # Get the size of order table before the new order is added cur.execute('SELECT COUNT(Order.id) FROM password.Order;') number_before = cur.fetchone() number_before = number_before[0] helper.stop(con, cur) con, cur = helper.start() for i in range(0, len(ids)): query = 'INSERT INTO `Order` (booking, item, quantity) VALUES (%s, %s, %s)' cur.execute(query, (booking, ids[i], quantities[i])) con.commit() helper.stop(con, cur) con, cur = helper.start() # Get the size of order table after the new order is added cur.execute('SELECT COUNT(Order.id) FROM password.Order;') number_after = cur.fetchone() number_after = number_after[0] # Check th right number of orders have been added did_work = False if ((number_after - number_before) == len(ids)): did_work = True print(did_work) helper.stop(con, cur) return did_work
def getBooked(): con, cur = helper.start() current_dt = datetime.datetime.now() # Get Data cur.execute( 'SELECT Lounger.id' ' FROM Booking' ' INNER JOIN Lounger ON Booking.lounger = Lounger.id' ' WHERE Booking.start_time < %s AND Booking.finish_time > %s;', (current_dt, current_dt)) booking_result = cur.fetchall() # Close Down helper.stop(con, cur) # Turn tuple into array useful_results = [x for xs in booking_result for x in xs] print(useful_results) # Return array of integers return useful_results
def main(): parser.description('A python statsd clone') helper.start(Cardiff)
def main(): parser.name('jnpr_nr_plugin') parser.description('jnpr_nr_plugin') helper.start(Controller)
def main(): """Called when invoking the command line script.""" add_parser_arguments() parser.description('Rejected AMQP consumer supervisor') helper.start(Controller)
def main(): """Called when invoking the command line script.""" add_parser_arguments() parser.description('RabbitMQ consumer framework') helper.start(Controller)
def main(): parser.description(DESCRIPTION) helper.start(Controller)
def book(): data = request.json if data: dataDict = json.loads(json.dumps(data)) if 'lounger' in dataDict and 'start_time' in dataDict and 'finish_time' in dataDict and 'client' in dataDict: now = datetime.datetime.now() if datetime.datetime.strptime( dataDict['start_time'], "%Y-%m-%d %H:%M:%S") >= now and datetime.datetime.strptime( dataDict['finish_time'], "%Y-%m-%d %H:%M:%S") > datetime.datetime.strptime( dataDict['start_time'], "%Y-%m-%d %H:%M:%S"): # Check client cnx, cur = helper.start() query = 'SELECT `id` FROM Client WHERE `id` = %s' cur.execute(query, (dataDict['client'], )) num = cur.rowcount cur.close() if num > 0: # Times & Client are okay # Check if the thing is free cur = cnx.cursor() query = 'SELECT `id` FROM Booking WHERE `start_time` <= %s AND `finish_time` >= %s' cur.execute( query, (dataDict['start_time'], dataDict['finish_time'])) num = cur.rowcount cur.close() if num == 0 and dataDict['lounger'] > 0: #Everything is good! cur = cnx.cursor() query = 'INSERT INTO Booking (`lounger`, `start_time`, `finish_time`, `client`) VALUES (%s, %s, %s, %s)' cur.execute( query, (dataDict['lounger'], dataDict['start_time'], dataDict['finish_time'], dataDict['client'])) cnx.commit() cur.close() # Now get the deails! cur = cnx.cursor() query = 'SELECT `id` FROM Booking WHERE `lounger` = %s AND `start_time` = %s AND `finish_time` = %s AND `client` = %s' cur.execute( query, (dataDict['lounger'], dataDict['start_time'], dataDict['finish_time'], dataDict['client'])) theid = cur.fetchone() helper.stop(cnx, cur) return Response(json.dumps({'booking': theid}), status=200, mimetype='application/json') else: print("1") return helper.error() else: print("2") return helper.error() else: print("3") return helper.error() else: return helper.error() else: return helper.error()
def order(): data = request.json if data: dataDict = json.loads(json.dumps(data)) if 'order' in dataDict and 'booking' in dataDict: cnx, cur = helper.start() #query = 'SELECT `id` FROM Client WHERE `username`=%s AND `password`=%s' #cur.execute(query, (dataDict['user'], dataDict['pass'])) #theid = cur.fetchone() #helper.stop(cnx, cur) ordered_items = [] prices = [] quantities = [] for i in range(0, len(dataDict['order'])): query = 'SELECT `id` FROM Item WHERE `name`=%s;' cur.execute(query, (dataDict['order'][i]['name'], )) ordered_items.append(cur.fetchone()[0]) print(ordered_items) helper.stop(cnx, cur) cnx, cur = helper.start() for i in range(0, len(dataDict['order'])): query = 'SELECT `price` FROM Item WHERE `id`=%s;' cur.execute(query, (ordered_items[i], )) prices.append(cur.fetchone()[0]) print(prices) for i in range(0, len(dataDict['order'])): quantities.append(dataDict['order'][i]['quantity']) print(quantities) print(dataDict['booking']) did_work = makeOrder(ordered_items, quantities, dataDict['booking']) if (did_work == True): addCharge(dataDict['booking'], prices, quantities) return Response(status=200) else: return helper.error() # if theid[0] > 0: # if dataDict['booking']: # # deal with booking # cnx, cur = helper.start() # query = 'SELECT MAX(id) FROM Booking WHERE `client` = %s AND `start_time` >= %s' # cur.execute(query, (theid[0], datetime.datetime.now())) # ids = cur.fetchone() # helper.stop(cnx, cur) # return Response(json.dumps({'bookings' : ids}), status=200, mimetype='application/json') # else: # return Response(status=200) #else: # return helper.error() else: return helper.error() else: return helper.error()
from helper import get_mysql_addr, start, end, info if __name__ == '__main__': start() addr = get_mysql_addr() info('%s %d' % (addr[0], addr[1])) end()