У меня есть функция python, которая получает курсы обмена с веб-сайта: -
import requests
import time
def myFunction(myCCY,myDate):
url=f'https://www1.oanda.com/currency/converter/updatebase_currency_0=GBP"e_currency={myCCY}&end_date={myDate}&view=details&id=5&action=C&'
headers={
'accept':'text/javascript, text/html, application/xml, text/xml,*/*',
'referer':'https://www1.oanda.com/currency/converter/',
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36',
'x-prototype-version':'1.7',
'x-requested-with':'XMLHttpRequest'
}
resp=requests.get(url=url,headers=headers)
time.sleep(2.73)
if resp.status_code==200:
jsonReturn=resp.json()
myRate=jsonReturn['data']['bid_ask_data']['bid']
return myRate
else:
return 0
Я пытаюсь вызвать ее из Excel, где у меня есть список валют: -
Sub getRates()
Dim i As Integer
Dim shell As Object
Dim exePath As String
Dim scriptPath As String
Dim command As String
Dim myDate As String
Set shell = VBA.CreateObject("Wscript.Shell")
exePath = """C:/Program Files (x86)/Microsoft Visual Studio/Shared/Python37_64/python.exe"""
scriptPath = "C:/Users/Philip/Documents/python2.myFunction"
myDate = "2020-05-25"
Stop
For i = 1 To Worksheets("Sheet1").Range("rates").Rows.Count
command = exePath & " " & scriptPath & " " & Worksheets("Sheet1").Range("rates").Range("A1").Offset(i - 1, 0).Value & " " & myDate
Debug.Print shell.Run(command, vbHide)
Next i
End Sub
, но похоже, что это не работает.
Очевидно, что я делаю не так ???
Спасибо, Фил