示例#1
0
def convert_currency(amount, from_currency, to_currency):
    try:
        client = osa.Client(URL_CURRENCY)
        response_cur = client.service.ConvertToNum(fromCurrency=from_currency,
                                                   toCurrency=to_currency,
                                                   amount=amount,
                                                   rounding=True)
        return response_cur
    except:
        client = osa.Client(URL_CURRENCY)
        currencies = client.service.Currencies()
        print('ERROR: failed converting currencies. Available currencies are:')
        print(currencies.replace(';', ', '))
示例#2
0
文件: HW_temp.py 项目: Odisssssey/py
def coantCelsius(a):
    URL = 'http://www.webservicex.net/ConvertTemperature.asmx?WSDL'
    client = osa.Client(URL)

    response1 = client.service.ConvertTemp(Temperature=a, FromUnit='degreeFahrenheit' , ToUnit='degreeCelsius')

    return response1
示例#3
0
def convert_temperature_from_fahrenheit_to_celsius(data):
    client = osa.Client('http://www.webservicex.net/ConvertTemperature.asmx?WSDL')
    temperatures_list = data.replace(' F', '').split('\n')
    converted_temperatures_list = list()
    for temperature in temperatures_list:
        converted_temperatures_list.append(client.service.ConvertTemp(temperature, 'degreeFahrenheit', 'degreeCelsius'))
    return converted_temperatures_list
示例#4
0
    def __init__(self, hostname, username, password, port=ISIS_SOAP_PORT):
        """
            :param hostname: hostname or ip of the Avid Isis Storage server
            :param username: a valid username
            :param password: password of the user
            :param port:     the port of the legacy web interface (80 or 3002)
        """
        self.hostname = hostname
        self.username = username
        self.password = password
        self.port = port
        
        # must be present for __del__ to gracefully exit failed session
        self.token = None

        url = ISIS_SOAP_URL.format(hostname=self.hostname,
                                   port=self.port)

        try:
            self._client = osa.Client(url)
        except urllib2.URLError:
            raise HostnameError("Hostname %s not found." % self.hostname)

        try:
            self.token = self._client.service.Login(ISIS_AGENT,
                                                self.username,
                                                self.password)
        except ValueError:
            raise LoginError("Username or password invalid.")

        self.set_byte_count_divisor(1024*1024)
示例#5
0
def convert_currency(currency_dict):
    client = osa.Client('http://fx.currencysystem.com/webservices/CurrencyServer4.asmx?WSDL')
    for key, value in currency_dict.items():
        if value[1] not in 'RUB':
            converted_value = client.service.ConvertToNum('', value[1], 'RUB', value[0], True, '', '')
            currency_dict[key] = [math.ceil(converted_value), 'RUB']
    return currency_dict
示例#6
0
def convert_curr(data):
    client = osa.Client(
        "http://fx.currencysystem.com/webservices/CurrencyServer4.asmx?WSDL")
    return client.service.ConvertToNum(fromCurrency=f"{data[2]}",
                                       toCurrency="rub",
                                       amount=f"{data[1]}",
                                       rounding="1")
示例#7
0
def getProtokol(addr, string):
    """
    Возвращает протокол за дату. Если не указана, то за вчерашний день.
    :param addr адрес сервиса
    :param date: дата, за которую получать протокол
    :return: список файлов из архива и кол-во ошибок
    """
    err = 0
    fileList = list()
    resp = None
    print('Строка даты=', string)
    # пробуем получить протокол
    try:
        cl = osa.Client(addr + '?wsdl')
        request = cl.types.GetProtocol()
        request.date = string
        resp = cl.service.GetProtocol(request)
    except:
        print('При обращении к методу GetProtocol, адрес %s возникли ошибки' %
              addr)
        err += 1
    # может прийти и пустой
    if resp is None:
        print('Протокол за %s не получен' % string)
        err += 1
    else:
        # проверяем были ли ошибки
        print(resp.HasError)
        if resp.HasError is False:
            # проверка результата
            if resp.Result is not None:
                # преобразуем протокол из base64 в zip и сохраняем
                open('arh.zip',
                     'wb').write(base64.standard_b64decode(resp.Result))
                # проверка zip файла
                with zipfile.ZipFile('arh.zip') as zipFile:
                    # проверка файла
                    error = zipFile.testzip()
                    if error is None:
                        print('Полученный zip файл прошел проверку')
                        # разархивирую файлы
                        fileList = zipFile.namelist()
                        print('Внутри архива файлы: %s' % fileList)
                        zipFile.extractall(path='csv/')
                    else:
                        print(
                            'Полученный zip файл поврежден. Результат проверки: '
                            % error)
                        err += 1
                # удалить временный zip файл
                os.remove('arh.zip')
            else:
                print('Вернулься пустой результат')
                err += 1
        else:
            # вернулись ошибки при получении протокола
            err += 1
            print('Вернулась ошибка при получении протокола: %s' %
                  resp.Message)
    return fileList, err
def convert_temperature(value, from_unit, to_unit):
    client = osa.Client(
        'http://www.webservicex.net/ConvertTemperature.asmx?WSDL')
    result = client.service.ConvertTemp(Temperature=value,
                                        FromUnit=from_unit,
                                        ToUnit=to_unit)
    return result
def temp_converter_from_fahr_to_cels(temp):
    FromUnit = 'degreeFahrenheit'
    ToUnit = 'degreeCelsius'

    client = osa.Client(
        'http://www.webservicex.net/ConvertTemperature.asmx?WSDL')
    result = client.service.ConvertTemp(temp, FromUnit, ToUnit)
    return round(result, 2)
示例#10
0
def get_average_temp(filename):
    client = osa.Client(
        'http://www.webservicex.net/ConvertTemperature.asmx?WSDL')
    temps = read_temps_from_file(filename)
    average_temps = sum(temps) / len(temps)
    response = client.service.ConvertTemp(average_temps, 'degreeFahrenheit',
                                          'degreeCelsius')
    return round(response, 2)
示例#11
0
def temp_converter(file):
    client = osa.Client('https://www.w3schools.com/xml/tempconvert.asmx')
    with open(file, 'r') as f:
        temp = [f for f in f.read().split() if f != 'F']
        for t in temp:
            t = client.service.ConvertTemp(t, 'degreeFahrenheit',
                                           'degreeCelsius')
            print(round(t, 1), 'градусов Цельсия')
示例#12
0
def convert_length(value, from_unit, to_unit):
    client = osa.Client('http://www.webservicex.net/length.asmx?WSDL')
    result = client.service.ChangeLengthUnit(
        LengthValue=value,
        fromLengthUnit=from_unit,
        toLengthUnit=to_unit,
    )
    return float(result)
示例#13
0
def convert_currency(fromCurrency, amount):
    client = osa.Client(
        'http://fx.currencysystem.com/webservices/CurrencyServer4.asmx?WSDL')
    response = client.service.ConvertToNum(fromCurrency=fromCurrency,
                                           toCurrency='RUB',
                                           amount=amount,
                                           rounding=True)
    return response
示例#14
0
def Convert_temperature(Temperature_value,
                        FromUnit="degreeFahrenheit",
                        ToUnit="degreeCelsius"):
    client = osa.Client(
        "http://www.webservicex.net/ConvertTemperature.asmx?WSDL")
    print(
        round(client.service.ConvertTemp(Temperature_value, FromUnit, ToUnit),
              2))
def convert_weight(value, from_unit, to_unit):
    client = osa.Client(
        'http://www.webservicex.net/convertMetricWeight.asmx?WSDL')
    result = client.service.ChangeMetricWeightUnit(
        MetricWeightValue=value,
        fromMetricWeightUnit=from_unit,
        toMetricWeightUnit=to_unit)
    return result
示例#16
0
def convert_temp(temperature):
    URL_temps = 'http://www.webservicex.net/ConvertTemperature.asmx?WSDL'
    client =osa.Client(wsdl_url=URL_temps)
    temp_params = dict(
        Temperature = temperature,
        FromUnit = 'degreeFahrenheit',
        ToUnit = 'degreeCelsius')
    response = client.service.ConvertTemp(**temp_params)
    return round(response, 2)
def convert_dist(value, from_unit):
    URL_dist = 'http://www.webservicex.net/length.asmx?WSDL'
    client =osa.Client(wsdl_url=URL_dist)
    dist_params = dict(
        LengthValue = value,
        fromLengthUnit = convert(from_unit),
        toLengthUnit = 'Kilometers')
    response = client.service.ChangeLengthUnit(**dist_params)
    return round(response, 2)
示例#18
0
def travel_length(file_path):
    client = osa.Client('http://www.webservicex.net/length.asmx?WSDL')
    with open(file_path) as f:
        amount = 0
        for way in f:
            trip = way.strip().split(' ')
            amount += float(trip[1].replace(',', ''))
    return round(client.service.ChangeLengthUnit(amount, 'Miles',
                                                 'Kilometers'))
示例#19
0
def convert_miles_to_km(filename):
    client = osa.Client('http://www.webservicex.net/length.asmx?WSDL')
    miles = read_miles_from_file(filename)
    kilometers = []
    for mile in miles:
        kilometer = client.service.ChangeLengthUnit(mile, 'Miles',
                                                    'Kilometers')
        kilometers.append(round(kilometer, 2))
    return sum(kilometers)
def length_converter_from_miles_to_km(length):
    LengthValue = length,
    fromLengthUnit = 'Miles',
    toLengthUnit = 'Kilometers'

    client = osa.Client('http://www.webservicex.net/length.asmx?WSDL')
    result = client.service.ChangeLengthUnit(LengthValue, fromLengthUnit,
                                             toLengthUnit)
    return round(result, 2)
示例#21
0
def convert_currencies(value, from_unit, to_unit, round_bool):
    client = osa.Client('http://fx.currencysystem.com/webservices/CurrencyServer4.asmx?WSDL')
    result = client.service.ConvertToNum(
        amount=value,
        fromCurrency=from_unit,
        toCurrency=to_unit,
        rounding=round_bool
    )
    return float(result)
示例#22
0
def printPrice(currency, price, sum_currencies):
    url = 'http://fx.currencysystem.com/webservices/CurrencyServer4.asmx?WSDL'
    client1 = osa.Client(url)

    response = client1.service.ConvertToNum(fromCurrency=currency,
                                            toCurrency='RUB',
                                            amount=price,
                                            rounding=True)
    sum_currencies += (int(round(response, 0)))
    return sum_currencies
示例#23
0
def currency_convert(source_path):
    client = osa.Client(
        'http://fx.currencysystem.com/webservices/CurrencyServer4.asmx?WSDL')
    sum = 0
    with open(source_path, 'r') as f:
        for line in f.readlines():
            text = line.replace('\n', '').split(' ')
            sum += client.service.ConvertToNum('', text[2], 'rub', text[1],
                                               'false')
    return round(sum)
示例#24
0
def currencies(curr_file_path):
    client = osa.Client('http://fx.currencysystem.com/webservices/CurrencyServer4.asmx?WSDL')
    with open(curr_file_path) as f:
        costs_list = []
        for line in f:
            costs_list.append(line.strip().split())
    costs_rub = 0
    for costs in costs_list:
        response = client.service.ConvertToNum(toCurrency='RUB', fromCurrency=costs[2], amount=costs[1], rounding=True)
        costs_rub += response
    return costs_rub
示例#25
0
def travel_unit(travel_file_path):
    client = osa.Client('http://www.webservicex.net/length.asmx?WSDL')
    with open(travel_file_path) as f:
        travel_list = []
        for line in f:
            travel_list.append(line.strip().split())
    travel_km = 0
    for travel in travel_list:
        response = client.service.ChangeLengthUnit(travel[1].replace(',', ''), fromLengthUnit='Miles', toLengthUnit='Kilometers')
        travel_km += round(response, 2)
    return travel_km