Example #1
0
def convert_currency():
    error = None
    if request.method == "POST":
        try:
            input_code = request.form.get('in')
            output_code = request.form.get('out')
            amount = request.values.get('amount', type = int)
            converted = converter(input_code,output_code,amount)
            symbol = CC.get_symbol(output_code)
        except:
            error = 'Not valid symbol'
     
            return render_template('amount.html', converted = converted, symbol = symbol, error = error)
    flash('Currency Converted')
    return render_template('amount.html', converted = converted, symbol = symbol)
 def __init__ (self):
     self.adapters = {
         'pantry':lambda t,r: self.rename_rows(t,r,{'itm':'ingkey'}),
         'categories':self.handle_categories,
         'ingredients':self.adapt_ids,
         'recipe':self.handle_recipe,
         'shopcats':lambda t,r: self.rename_rows(t,r,{'shopkey':'ingkey',
                                                      'category':'shopcategory',
                                                      }),
         'shopcatsorder':lambda t,r: self.rename_rows(t,r,{'category':'shopcategory'}),
         
         }
     self.id_converter = {}
     self.top_id = 1
     from importers.importer import RatingConverter
     self.rc = RatingConverter()
     import convert
     self.conv = convert.converter()
Example #3
0
def process(thread_queue):
    from api.mongo_api import MongoExecuter
    from api.mongo_driver import db_handler
    from api.mongo_driver import conn
    c = MongoExecuter(db_handler)
    
    while 1:
        try:
            action_type, data = thread_queue.get()
            item = converter(data)
        except hub.LoopExit:
            print "process exit..."
            return
        
        thread_queue.task_done()
        
        for vm in item:
            data = vm['data']
            uuid = vm['uuid']
            
            cond = {"type": action_type, "uuid": uuid}
            ret = c.query_one("virtual_host", cond)
            
            record = {
                "data": {},
                "uuid": uuid,
                "type": action_type,
                "timestamp": str(int(time.time()))
            }
            
            for data_field, value in data.items():
                temp_lsit = []
                for item_val in value:
                    temp = {}
                    temp['last_update'] = str(item_val['last_update'])
                    temp['data'] = float(item_val['data'])
                    temp['timestamp'] = long(item_val['timestamp'])
                    temp_lsit.append(temp)
                record['data'][data_field] = temp_lsit
            
            if not ret:
                c.insert("virtual_host", record)
            else:
                c.update("virtual_host", cond, record)
Example #4
0
def upload_file2():
    pollf = open(pollfilename, 'r')
    for line in pollf:
        vote = line.rstrip("\n")
        print("vote=", vote)
    if request.method == 'POST':
        if vote == "1. OpenTable Reservation Report":
            print("OpenTable Reservation Report type file")
            if 'reservation_file' not in request.files:
                flash('No file part')
                return redirect(request.url)
            f = request.files['reservation_file']
            nameOfFile = os.path.join(app.instance_path, 'htmlfi',
                                      secure_filename(f.filename))
            print("file name: ", nameOfFile, f)
            f.save(nameOfFile)
            dfr = converter(nameOfFile)
            print(dfr.shape)
            print('RESERVATION_FILE')
            # give unique filenames
            csv = dfr.to_csv('OpenTable_Reservation_Report.csv')
            # try:
            #       return send_file('OpenTable_Reservation_Report.csv', attachment_filename='OpenTable_Reservation_Report.csv')
            # except Exception as ex:
            #       return str(ex)
        else:
            return "File type mismatch"
        # print('file converted successfully')

        try:
            # return send_file('OpenTable_Reservation_Report.csv', attachment_filename='reformatted_reservation_report.csv')
            CORS(app, expose_headers=["x-suggested-filename"])

            # In file with the download endpoint
            result = send_file("Reformatted_Reservation_Report.csv",
                               mimetype="text/csv",
                               as_attachment=True,
                               conditional=False)
            result.headers[
                "x-suggested-filename"] = "use_this_filename.csv"  # not showing this name
            return result
        except Exception as e:
            return str(e)
    return render_template('thankyou.html')
Example #5
0
 def __init__(self):
     self.adapters = {
         'pantry':
         lambda t, r: self.rename_rows(t, r, {'itm': 'ingkey'}),
         'categories':
         self.handle_categories,
         'ingredients':
         self.adapt_ids,
         'recipe':
         self.handle_recipe,
         'shopcats':
         lambda t, r: self.rename_rows(t, r, {
             'shopkey': 'ingkey',
             'category': 'shopcategory',
         }),
         'shopcatsorder':
         lambda t, r: self.rename_rows(t, r, {'category': 'shopcategory'}),
     }
     self.id_converter = {}
     self.top_id = 1
     from importers.importer import RatingConverter
     self.rc = RatingConverter()
     import convert
     self.conv = convert.converter()
Example #6
0
 def test_converter(self):
     self.assertEqual(converter('USD', 'USD', 1), 1)
Example #7
0
def calendar(message):
    today = str(dt.date.today())
    target_date = convert.converter(today)
    date_to_convert = cal.Calendar().to_french_revolutionary(target_date)
    return date_to_convert
Example #8
0
def process(thread_queue):
    from api.mongo_api import MongoExecuter
    from api.mongo_driver import db_handler
    from api.mongo_driver import conn
    c = MongoExecuter(db_handler)
    
    while 1:
        try:
            action_type, data = thread_queue.get()
            item = converter(data)
        except hub.LoopExit:
            print "process exit..."
            return
        
        thread_queue.task_done()
        
        for vm in item:
            data = vm['data']
            uuid = vm['uuid']
            
            cond = {"type": action_type, "uuid": uuid}
            ret = c.query_one("virtual_host", cond)
            
            record = {
                "data": {},
                "uuid": uuid,
                "type": action_type,
                "timestamp": str(int(time.time()))
            }
            
            cpu_usage = []
            network_io = []
            disk_io = []
            
            for data_field, value in data.items():
                temp_lsit = []
                for item_val in value:
                    temp = {}
                    temp['last_update'] = str(item_val['last_update'])
                    temp['data'] = float(item_val['data'])
                    temp['timestamp'] = long(item_val['timestamp'])
                    temp_lsit.append(temp)
                record['data'][data_field] = temp_lsit
                
                
                if re.match(cpu_usage_re, data_field):
                    if not math.isnan(temp['data']):
                        cpu_usage.append(temp['data'])
                    
                if re.match(network_rx_re, data_field) or re.match(network_tx_re, data_field):
                    if not math.isnan(temp['data']):
                        network_io.append(temp['data'])
                    
                if re.match(disk_read_re, data_field) or re.match(disk_write_re, data_field):
                    if not math.isnan(temp['data']):
                        disk_io.append(temp['data'])
            
            
            # 保存每台虚拟机的CPU负载/网卡IO/磁盘IO性能参数
            cpu_usage_data = 0
            if len(cpu_usage) > 0:
                for i in cpu_usage:
                    cpu_usage_data += i
                try:
                    cpu_usage_data = cpu_usage_data / len(cpu_usage)
                except:
                    pass
            
            network_io_data = 0
            if len(network_io) > 0:
                for i in network_io:
                    network_io_data += i
                try:
                    network_io_data = network_io_data / len(network_io)
                except:
                    pass
            
            disk_io_data = 0
            if len(disk_io) > 0:
                for i in disk_io:
                    disk_io_data += i
                try:
                    disk_io_data = int(disk_io_data / len(disk_io))
                except:
                    pass
            
            save_cpu_usage(uuid, cpu_usage_data)
            save_network_io(uuid, network_io_data)
            save_disk_io(uuid, disk_io_data)
            
            if not ret:
                c.insert("virtual_host", record)
            else:
                c.update("virtual_host", cond, record)