From 01bb17e0c217b94829fdd0a47654d6328fcd74e2 Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Sun, 15 Sep 2019 12:02:49 +0200 Subject: [PATCH 1/9] added bank card payment app --- bank_card_payment | 1 + 1 file changed, 1 insertion(+) create mode 120000 bank_card_payment diff --git a/bank_card_payment b/bank_card_payment new file mode 120000 index 00000000..7304f32d --- /dev/null +++ b/bank_card_payment @@ -0,0 +1 @@ +../bank_card_payment/app/ \ No newline at end of file From ef8c1f0dd7f39c60ab2dff6c81f716efe70ee53f Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Wed, 30 Oct 2019 19:55:55 +0100 Subject: [PATCH 2/9] added directory as oppposed to a symlink --- bank_card_payment | 1 - 1 file changed, 1 deletion(-) delete mode 120000 bank_card_payment diff --git a/bank_card_payment b/bank_card_payment deleted file mode 120000 index 7304f32d..00000000 --- a/bank_card_payment +++ /dev/null @@ -1 +0,0 @@ -../bank_card_payment/app/ \ No newline at end of file From d76fda72b9851d985375c0c5799b51c9cec78f23 Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Wed, 30 Oct 2019 19:58:06 +0100 Subject: [PATCH 3/9] added bank_card_payment dir --- bank_card_payment/Dockerfile | 6 ++++++ bank_card_payment/requirements.txt | 1 + bank_card_payment/test_dwolla.py | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 bank_card_payment/Dockerfile create mode 100644 bank_card_payment/requirements.txt create mode 100644 bank_card_payment/test_dwolla.py diff --git a/bank_card_payment/Dockerfile b/bank_card_payment/Dockerfile new file mode 100644 index 00000000..46d8493d --- /dev/null +++ b/bank_card_payment/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7-alpine +COPY test_dwolla.py /test_dwolla.py +COPY requirements.txt /requirements.txt +RUN pip install -r /requirements.txt +RUN chmod +x /test_dwolla.py +CMD python test_dwolla.py \ No newline at end of file diff --git a/bank_card_payment/requirements.txt b/bank_card_payment/requirements.txt new file mode 100644 index 00000000..1781170a --- /dev/null +++ b/bank_card_payment/requirements.txt @@ -0,0 +1 @@ +dwollav2>=1.3.0 \ No newline at end of file diff --git a/bank_card_payment/test_dwolla.py b/bank_card_payment/test_dwolla.py new file mode 100644 index 00000000..fd990403 --- /dev/null +++ b/bank_card_payment/test_dwolla.py @@ -0,0 +1,19 @@ +import dwollav2 +import sys +payment_id = sys.argv[1] + + +client = dwollav2.Client( + key = 'XfEX77omgP2XNRjI04wQOA3nusm6xrJy7xRoiulVLdh4hxhwDS', + secret = 'HhpRzVXYX3t4NMpcwS7pC4XgJsqXi5E2DQIBNWevGGwvQOxpda', + environment = 'sandbox' +) + +app_token = client.Auth.client() + +payment_info = app_token.get('https://api-sandbox.dwolla.com/transfers/%s' % payment_id) +amount = '%(value)s %(currency)s' % (payment_info.body['amount']) +payer_ID = payment_info.body['id'] +print(amount,payer_ID) + + From 26f90a0cbe3f1ae69045d26a11c96b629ccb90ea Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Wed, 30 Oct 2019 20:10:36 +0100 Subject: [PATCH 4/9] modified Dockerfile to have ENTRYPOINT --- bank_card_payment/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bank_card_payment/Dockerfile b/bank_card_payment/Dockerfile index 46d8493d..4238ceb2 100644 --- a/bank_card_payment/Dockerfile +++ b/bank_card_payment/Dockerfile @@ -3,4 +3,4 @@ COPY test_dwolla.py /test_dwolla.py COPY requirements.txt /requirements.txt RUN pip install -r /requirements.txt RUN chmod +x /test_dwolla.py -CMD python test_dwolla.py \ No newline at end of file +ENTRYPOINT ["/test_dwolla.py"] \ No newline at end of file From e3556806ab5e1bac9ec7b9fc84610d217d1c7c53 Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Wed, 30 Oct 2019 20:38:44 +0100 Subject: [PATCH 5/9] added shebang to python file --- bank_card_payment/app/test_dwolla.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 bank_card_payment/app/test_dwolla.py diff --git a/bank_card_payment/app/test_dwolla.py b/bank_card_payment/app/test_dwolla.py new file mode 100644 index 00000000..ed2aea0f --- /dev/null +++ b/bank_card_payment/app/test_dwolla.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +import dwollav2 +import sys +payment_id = sys.argv[1] + + +client = dwollav2.Client( + key = 'XfEX77omgP2XNRjI04wQOA3nusm6xrJy7xRoiulVLdh4hxhwDS', + secret = 'HhpRzVXYX3t4NMpcwS7pC4XgJsqXi5E2DQIBNWevGGwvQOxpda', + environment = 'sandbox' +) + +app_token = client.Auth.client() + +payment_info = app_token.get('https://api-sandbox.dwolla.com/transfers/%s' % payment_id) +amount = '%(value)s %(currency)s' % (payment_info.body['amount']) +payer_ID = payment_info.body['id'] +print(amount,payer_ID) + + From ae163f2618d1a6a044237a8ab5b3384439228394 Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Wed, 30 Oct 2019 20:39:31 +0100 Subject: [PATCH 6/9] added some files --- bank_card_payment/app/Dockerfile | 6 ++++++ bank_card_payment/app/requirements.txt | 1 + bank_card_payment/chain.json | 29 ++++++++++++++++++++++++++ bank_card_payment/iexec.json | 10 +++++++++ 4 files changed, 46 insertions(+) create mode 100644 bank_card_payment/app/Dockerfile create mode 100644 bank_card_payment/app/requirements.txt create mode 100644 bank_card_payment/chain.json create mode 100644 bank_card_payment/iexec.json diff --git a/bank_card_payment/app/Dockerfile b/bank_card_payment/app/Dockerfile new file mode 100644 index 00000000..973f1ed9 --- /dev/null +++ b/bank_card_payment/app/Dockerfile @@ -0,0 +1,6 @@ +FROM jfloff/alpine-python +COPY test_dwolla.py /test_dwolla.py +COPY requirements.txt /requirements.txt +RUN pip install -r /requirements.txt +RUN chmod +x /test_dwolla.py +ENTRYPOINT ["/test_dwolla.py"] \ No newline at end of file diff --git a/bank_card_payment/app/requirements.txt b/bank_card_payment/app/requirements.txt new file mode 100644 index 00000000..1781170a --- /dev/null +++ b/bank_card_payment/app/requirements.txt @@ -0,0 +1 @@ +dwollav2>=1.3.0 \ No newline at end of file diff --git a/bank_card_payment/chain.json b/bank_card_payment/chain.json new file mode 100644 index 00000000..700ab0e4 --- /dev/null +++ b/bank_card_payment/chain.json @@ -0,0 +1,29 @@ +{ + "default": "kovan", + "chains": { + "dev": { + "host": "http://localhost:8545", + "sms": "http://localhost:5000", + "id": "17", + "hub": "0x60E25C038D70A15364DAc11A042DB1dD7A2cccBC" + }, + "ropsten": { + "host": "https://ropsten.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", + "id": "3" + }, + "rinkeby": { + "host": "https://rinkeby.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", + "id": "4" + }, + "kovan": { + "host": "https://kovan.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", + "id": "42", + "sms": "https://sms-kovan.iex.ec" + }, + "mainnet": { + "host": "https://mainnet.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", + "id": "1", + "sms": "https://sms-mainnet.iex.ec" + } + } +} \ No newline at end of file diff --git a/bank_card_payment/iexec.json b/bank_card_payment/iexec.json new file mode 100644 index 00000000..dcbdd2a3 --- /dev/null +++ b/bank_card_payment/iexec.json @@ -0,0 +1,10 @@ +{ + "description": "My iExec ressource description, must be at least 150 chars long in order to pass the validation checks. Describe your application, dataset or workerpool to your users", + "license": "MIT", + "author": "?", + "social": { + "website": "?", + "github": "?" + }, + "logo": "logo.png" +} \ No newline at end of file From 36406797c740d32e34d44beb40ac13d0f7244cc9 Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Wed, 30 Oct 2019 21:20:46 +0100 Subject: [PATCH 7/9] several pending changes --- bank_card_payment/Dockerfile | 6 ------ bank_card_payment/deployed.json | 5 +++++ bank_card_payment/iexec.json | 27 ++++++++++++++++++++++++++- bank_card_payment/orders.json | 15 +++++++++++++++ bank_card_payment/requirements.txt | 1 - bank_card_payment/smart-contract | 1 + bank_card_payment/test_dwolla.py | 19 ------------------- 7 files changed, 47 insertions(+), 27 deletions(-) delete mode 100644 bank_card_payment/Dockerfile create mode 100644 bank_card_payment/deployed.json create mode 100644 bank_card_payment/orders.json delete mode 100644 bank_card_payment/requirements.txt create mode 160000 bank_card_payment/smart-contract delete mode 100644 bank_card_payment/test_dwolla.py diff --git a/bank_card_payment/Dockerfile b/bank_card_payment/Dockerfile deleted file mode 100644 index 4238ceb2..00000000 --- a/bank_card_payment/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM python:3.7-alpine -COPY test_dwolla.py /test_dwolla.py -COPY requirements.txt /requirements.txt -RUN pip install -r /requirements.txt -RUN chmod +x /test_dwolla.py -ENTRYPOINT ["/test_dwolla.py"] \ No newline at end of file diff --git a/bank_card_payment/deployed.json b/bank_card_payment/deployed.json new file mode 100644 index 00000000..77a0897b --- /dev/null +++ b/bank_card_payment/deployed.json @@ -0,0 +1,5 @@ +{ + "app": { + "42": "0x4f29393e0e9842DdEaf49a0AC2e7fc66CFA00a33" + } +} \ No newline at end of file diff --git a/bank_card_payment/iexec.json b/bank_card_payment/iexec.json index dcbdd2a3..a5ca7555 100644 --- a/bank_card_payment/iexec.json +++ b/bank_card_payment/iexec.json @@ -6,5 +6,30 @@ "website": "?", "github": "?" }, - "logo": "logo.png" + "logo": "logo.png", + "buyConf": { + "params": "", + "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", + "trust": "0", + "callback": "0x0000000000000000000000000000000000000000" + }, + "app": { + "owner": "0xe597d6fD63A56e645DbD680C56599038e5E02Be3", + "name": "BankCardPayment", + "type": "DOCKER", + "multiaddr": "registry.hub.docker.com/thomasvangurp/price-feed:1.0.0", + "checksum": "0x78495ddcb012dd32091cfa80a757c240d3dcc0366db64869c902e6802b043daa", + "mrenclave": "" + }, + "order": { + "apporder": { + "app": "0x4f29393e0e9842DdEaf49a0AC2e7fc66CFA00a33", + "appprice": "0", + "volume": "1000000", + "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", + "datasetrestrict": "0x0000000000000000000000000000000000000000", + "workerpoolrestrict": "0x0000000000000000000000000000000000000000", + "requesterrestrict": "0x0000000000000000000000000000000000000000" + } + } } \ No newline at end of file diff --git a/bank_card_payment/orders.json b/bank_card_payment/orders.json new file mode 100644 index 00000000..eee96b4c --- /dev/null +++ b/bank_card_payment/orders.json @@ -0,0 +1,15 @@ +{ + "42": { + "apporder": { + "app": "0x4f29393e0e9842DdEaf49a0AC2e7fc66CFA00a33", + "appprice": "0", + "volume": "1000000", + "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", + "datasetrestrict": "0x0000000000000000000000000000000000000000", + "workerpoolrestrict": "0x0000000000000000000000000000000000000000", + "requesterrestrict": "0x0000000000000000000000000000000000000000", + "salt": "0x911dc3bcbd5991abd8e56cfb0d51889b51045425b8e7771e78d179cdb5de7fa4", + "sign": "0xf26c19dfc30a01701d95be4acf87198222d9081f33ce99589a445358c325ad814a0467f3ae0702f101418ac05208e33139a6f2243ea2e77951fc60512978342f1c" + } + } +} \ No newline at end of file diff --git a/bank_card_payment/requirements.txt b/bank_card_payment/requirements.txt deleted file mode 100644 index 1781170a..00000000 --- a/bank_card_payment/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -dwollav2>=1.3.0 \ No newline at end of file diff --git a/bank_card_payment/smart-contract b/bank_card_payment/smart-contract new file mode 160000 index 00000000..b7cd4ef5 --- /dev/null +++ b/bank_card_payment/smart-contract @@ -0,0 +1 @@ +Subproject commit b7cd4ef5e286189f47a6959eceef17ecd0928934 diff --git a/bank_card_payment/test_dwolla.py b/bank_card_payment/test_dwolla.py deleted file mode 100644 index fd990403..00000000 --- a/bank_card_payment/test_dwolla.py +++ /dev/null @@ -1,19 +0,0 @@ -import dwollav2 -import sys -payment_id = sys.argv[1] - - -client = dwollav2.Client( - key = 'XfEX77omgP2XNRjI04wQOA3nusm6xrJy7xRoiulVLdh4hxhwDS', - secret = 'HhpRzVXYX3t4NMpcwS7pC4XgJsqXi5E2DQIBNWevGGwvQOxpda', - environment = 'sandbox' -) - -app_token = client.Auth.client() - -payment_info = app_token.get('https://api-sandbox.dwolla.com/transfers/%s' % payment_id) -amount = '%(value)s %(currency)s' % (payment_info.body['amount']) -payer_ID = payment_info.body['id'] -print(amount,payer_ID) - - From 53e7fb12c5922874c145732e599d69925528d0aa Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Sun, 3 Nov 2019 12:28:54 +0100 Subject: [PATCH 8/9] added weather oracle --- weather_api/app/Dockerfile | 5 ++++ weather_api/app/config.ini | 2 ++ weather_api/app/openweathermap_api_call.py | 32 ++++++++++++++++++++ weather_api/chain.json | 29 ++++++++++++++++++ weather_api/deployed.json | 5 ++++ weather_api/iexec.json | 35 ++++++++++++++++++++++ weather_api/orders.json | 15 ++++++++++ weather_api/smart-contract | 1 + 8 files changed, 124 insertions(+) create mode 100644 weather_api/app/Dockerfile create mode 100644 weather_api/app/config.ini create mode 100644 weather_api/app/openweathermap_api_call.py create mode 100644 weather_api/chain.json create mode 100644 weather_api/deployed.json create mode 100644 weather_api/iexec.json create mode 100644 weather_api/orders.json create mode 160000 weather_api/smart-contract diff --git a/weather_api/app/Dockerfile b/weather_api/app/Dockerfile new file mode 100644 index 00000000..be1d5d13 --- /dev/null +++ b/weather_api/app/Dockerfile @@ -0,0 +1,5 @@ +FROM jfloff/alpine-python +COPY config.ini /config.ini +COPY openweathermap_api_call.py /openweathermap_api_call.py +RUN chmod +x /openweathermap_api_call.py +ENTRYPOINT ["/openweathermap_api_call.py"] \ No newline at end of file diff --git a/weather_api/app/config.ini b/weather_api/app/config.ini new file mode 100644 index 00000000..bf1df8de --- /dev/null +++ b/weather_api/app/config.ini @@ -0,0 +1,2 @@ +[openweathermap] +api=c1b5213b85fc28611f3a462ac85000f4 \ No newline at end of file diff --git a/weather_api/app/openweathermap_api_call.py b/weather_api/app/openweathermap_api_call.py new file mode 100644 index 00000000..7462e016 --- /dev/null +++ b/weather_api/app/openweathermap_api_call.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +import configparser +import requests +import sys + + +def get_api_key(): + config = configparser.ConfigParser() + config.read('config.ini') + return config['openweathermap']['api'] + + +def get_weather(api_key, location): + url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key) + r = requests.get(url) + return r.json() + + +def main(): + if len(sys.argv) != 2: + exit("Usage: {} LOCATION".format(sys.argv[0])) + location = sys.argv[1] + + api_key = get_api_key() + weather = get_weather(api_key, location) + + print(weather['weather']['description']) + print(weather) + + +if __name__ == '__main__': + main() diff --git a/weather_api/chain.json b/weather_api/chain.json new file mode 100644 index 00000000..700ab0e4 --- /dev/null +++ b/weather_api/chain.json @@ -0,0 +1,29 @@ +{ + "default": "kovan", + "chains": { + "dev": { + "host": "http://localhost:8545", + "sms": "http://localhost:5000", + "id": "17", + "hub": "0x60E25C038D70A15364DAc11A042DB1dD7A2cccBC" + }, + "ropsten": { + "host": "https://ropsten.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", + "id": "3" + }, + "rinkeby": { + "host": "https://rinkeby.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", + "id": "4" + }, + "kovan": { + "host": "https://kovan.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", + "id": "42", + "sms": "https://sms-kovan.iex.ec" + }, + "mainnet": { + "host": "https://mainnet.infura.io/v3/f3e0664e01504f5ab2b4360853ce0dc7", + "id": "1", + "sms": "https://sms-mainnet.iex.ec" + } + } +} \ No newline at end of file diff --git a/weather_api/deployed.json b/weather_api/deployed.json new file mode 100644 index 00000000..c5eedea7 --- /dev/null +++ b/weather_api/deployed.json @@ -0,0 +1,5 @@ +{ + "app": { + "42": "0xF0392D1500275D7e68aE25E95Ab0a134F635713b" + } +} \ No newline at end of file diff --git a/weather_api/iexec.json b/weather_api/iexec.json new file mode 100644 index 00000000..bb675075 --- /dev/null +++ b/weather_api/iexec.json @@ -0,0 +1,35 @@ +{ + "description": "My iExec ressource description, must be at least 150 chars long in order to pass the validation checks. Describe your application, dataset or workerpool to your users", + "license": "MIT", + "author": "?", + "social": { + "website": "?", + "github": "?" + }, + "logo": "logo.png", + "buyConf": { + "params": "", + "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", + "trust": "0", + "callback": "0x0000000000000000000000000000000000000000" + }, + "app": { + "owner": "0xe597d6fD63A56e645DbD680C56599038e5E02Be3", + "name": "WeatherOracle", + "type": "DOCKER", + "multiaddr": "registry.hub.docker.com/thomasvangurp/weather_oracle:1.0.0", + "checksum": "0x00f51494d7a42a3c1c43464d9f09e06b2a99968e3b978f6cd11ab3410b7bcd14", + "mrenclave": "" + }, + "order": { + "apporder": { + "app": "0xF0392D1500275D7e68aE25E95Ab0a134F635713b", + "appprice": "0", + "volume": "1000000", + "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", + "datasetrestrict": "0x0000000000000000000000000000000000000000", + "workerpoolrestrict": "0x0000000000000000000000000000000000000000", + "requesterrestrict": "0x0000000000000000000000000000000000000000" + } + } +} \ No newline at end of file diff --git a/weather_api/orders.json b/weather_api/orders.json new file mode 100644 index 00000000..2563a43f --- /dev/null +++ b/weather_api/orders.json @@ -0,0 +1,15 @@ +{ + "42": { + "apporder": { + "app": "0xF0392D1500275D7e68aE25E95Ab0a134F635713b", + "appprice": "0", + "volume": "1000000", + "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", + "datasetrestrict": "0x0000000000000000000000000000000000000000", + "workerpoolrestrict": "0x0000000000000000000000000000000000000000", + "requesterrestrict": "0x0000000000000000000000000000000000000000", + "salt": "0x43cda66395d901181d2fd74f9c1a4a74e30e6779ae9b983fdb9cf02fd3a2b341", + "sign": "0x8928c6d3ff6dc022a5018a62bfab07cd575d90f7fd2399986a4d18440d7c86b1002eede7a39d88e53876a94796f456c6050322da77dab8ef069a4832d792022d1b" + } + } +} \ No newline at end of file diff --git a/weather_api/smart-contract b/weather_api/smart-contract new file mode 160000 index 00000000..b7cd4ef5 --- /dev/null +++ b/weather_api/smart-contract @@ -0,0 +1 @@ +Subproject commit b7cd4ef5e286189f47a6959eceef17ecd0928934 From 1021cc02ba2d890f36b5e2c0e189b19150daaffb Mon Sep 17 00:00:00 2001 From: Thomas van Gurp Date: Mon, 4 Nov 2019 19:53:35 +0100 Subject: [PATCH 9/9] using darksky for weather and opencagedata for coordinates --- weather_api/app/Dockerfile | 8 ++-- weather_api/app/config.ini | 6 ++- weather_api/app/darkskyp_api_call.py | 54 ++++++++++++++++++++++ weather_api/app/openweathermap_api_call.py | 25 ++++++---- weather_api/app/requirements.txt | 3 ++ weather_api/deployed.json | 2 +- weather_api/iexec.json | 4 +- weather_api/orders.json | 6 +-- 8 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 weather_api/app/darkskyp_api_call.py create mode 100644 weather_api/app/requirements.txt diff --git a/weather_api/app/Dockerfile b/weather_api/app/Dockerfile index be1d5d13..304e2db4 100644 --- a/weather_api/app/Dockerfile +++ b/weather_api/app/Dockerfile @@ -1,5 +1,7 @@ FROM jfloff/alpine-python COPY config.ini /config.ini -COPY openweathermap_api_call.py /openweathermap_api_call.py -RUN chmod +x /openweathermap_api_call.py -ENTRYPOINT ["/openweathermap_api_call.py"] \ No newline at end of file +COPY darkskyp_api_call.py /darkskyp_api_call.py +COPY requirements.txt /requirements.txt +RUN pip install -r /requirements.txt +RUN chmod +x /darkskyp_api_call.py +ENTRYPOINT ["/darkskyp_api_call.py"] \ No newline at end of file diff --git a/weather_api/app/config.ini b/weather_api/app/config.ini index bf1df8de..598693db 100644 --- a/weather_api/app/config.ini +++ b/weather_api/app/config.ini @@ -1,2 +1,6 @@ [openweathermap] -api=c1b5213b85fc28611f3a462ac85000f4 \ No newline at end of file +api=c1b5213b85fc28611f3a462ac85000f4 +[darksky] +api=28ea66e419c8820705d5496cce3ac0ae +[opencagedata] +api=812c8fc8222b49a0b650fea303db6f5c \ No newline at end of file diff --git a/weather_api/app/darkskyp_api_call.py b/weather_api/app/darkskyp_api_call.py new file mode 100644 index 00000000..814120b9 --- /dev/null +++ b/weather_api/app/darkskyp_api_call.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +import configparser +import requests +import sys +import ciso8601 +import time +from opencage.geocoder import OpenCageGeocode + +def get_api_key(api_name): + config = configparser.ConfigParser() + config.read('config.ini') + return config[api_name]['api'] + +def get_unixtime(date): + """return unixtime for date""" + ts = ciso8601.parse_datetime(date) + # to get time in seconds: + return int(time.mktime(ts.timetuple())) + + +def get_coordinates(api_key, location): + geocoder = OpenCageGeocode(api_key) + result = geocoder.geocode(location, no_annotations='1') + if result and len(result): + longitude = result[0]['geometry']['lng'] + latitude = result[0]['geometry']['lat'] + else: + sys.stderr.write("not found: %s\n" % location) + return latitude,longitude + +def get_weather(api_key, lat, long, date): + weatherdict = {'api_key':api_key,'start':date,'lat':lat,'long':long} + url = "https://api.darksky.net/forecast/{api_key}/{lat},{long},{start}?exclude=currently,flags,hourly".format(**weatherdict) + r = requests.get(url) + return r.json() + + +def main(): + if len(sys.argv) != 3: + exit("Usage: {} DATE LOCATION".format(sys.argv[0])) + date = sys.argv[1] + epoch_time = str(get_unixtime(date)) + location = sys.argv[2] + + api_key_ds = get_api_key('darksky') + api_key_oc = get_api_key('opencagedata') + lat,long = get_coordinates(api_key_oc, location) + weather = get_weather(api_key_ds, lat,long, epoch_time) + + print(weather['daily']['data'][0]['summary']) + + +if __name__ == '__main__': + main() diff --git a/weather_api/app/openweathermap_api_call.py b/weather_api/app/openweathermap_api_call.py index 7462e016..dffda3cb 100644 --- a/weather_api/app/openweathermap_api_call.py +++ b/weather_api/app/openweathermap_api_call.py @@ -2,30 +2,39 @@ import configparser import requests import sys - +import ciso8601 +import time def get_api_key(): config = configparser.ConfigParser() config.read('config.ini') return config['openweathermap']['api'] +def get_unixtime(date): + """return unixtime for date""" + ts = ciso8601.parse_datetime(date) + # to get time in seconds: + return int(time.mktime(ts.timetuple())) -def get_weather(api_key, location): - url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key) +def get_weather(api_key, location, date): + weatherdict = {'api_key':api_key,'start':date,'city ID':location} + url = "http://history.openweathermap.org/data/2.5/history/city?q={city ID}&type=hour&start={start}&cnt=1".format(**weatherdict) + # url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, api_key) r = requests.get(url) return r.json() def main(): - if len(sys.argv) != 2: + if len(sys.argv) != 3: exit("Usage: {} LOCATION".format(sys.argv[0])) - location = sys.argv[1] + date = sys.argv[1] + epoch_time = str(get_unixtime(date)) + location = sys.argv[2] api_key = get_api_key() - weather = get_weather(api_key, location) + weather = get_weather(api_key, location, epoch_time) - print(weather['weather']['description']) - print(weather) + print(weather['weather'][0]['description']) if __name__ == '__main__': diff --git a/weather_api/app/requirements.txt b/weather_api/app/requirements.txt new file mode 100644 index 00000000..b528b260 --- /dev/null +++ b/weather_api/app/requirements.txt @@ -0,0 +1,3 @@ +requests +ciso8601==1.0.1 +opencage \ No newline at end of file diff --git a/weather_api/deployed.json b/weather_api/deployed.json index c5eedea7..35025abd 100644 --- a/weather_api/deployed.json +++ b/weather_api/deployed.json @@ -1,5 +1,5 @@ { "app": { - "42": "0xF0392D1500275D7e68aE25E95Ab0a134F635713b" + "42": "0x5f9049B4461Be705eCf75688042e3593f3E2eD42" } } \ No newline at end of file diff --git a/weather_api/iexec.json b/weather_api/iexec.json index bb675075..f853c007 100644 --- a/weather_api/iexec.json +++ b/weather_api/iexec.json @@ -18,12 +18,12 @@ "name": "WeatherOracle", "type": "DOCKER", "multiaddr": "registry.hub.docker.com/thomasvangurp/weather_oracle:1.0.0", - "checksum": "0x00f51494d7a42a3c1c43464d9f09e06b2a99968e3b978f6cd11ab3410b7bcd14", + "checksum": "0xcbeeaa8491196182d0160b8b60e96175ba50c19476201074dc93bd0b980d4ad0", "mrenclave": "" }, "order": { "apporder": { - "app": "0xF0392D1500275D7e68aE25E95Ab0a134F635713b", + "app": "0x5f9049B4461Be705eCf75688042e3593f3E2eD42", "appprice": "0", "volume": "1000000", "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", diff --git a/weather_api/orders.json b/weather_api/orders.json index 2563a43f..a0fad15f 100644 --- a/weather_api/orders.json +++ b/weather_api/orders.json @@ -1,15 +1,15 @@ { "42": { "apporder": { - "app": "0xF0392D1500275D7e68aE25E95Ab0a134F635713b", + "app": "0x5f9049B4461Be705eCf75688042e3593f3E2eD42", "appprice": "0", "volume": "1000000", "tag": "0x0000000000000000000000000000000000000000000000000000000000000000", "datasetrestrict": "0x0000000000000000000000000000000000000000", "workerpoolrestrict": "0x0000000000000000000000000000000000000000", "requesterrestrict": "0x0000000000000000000000000000000000000000", - "salt": "0x43cda66395d901181d2fd74f9c1a4a74e30e6779ae9b983fdb9cf02fd3a2b341", - "sign": "0x8928c6d3ff6dc022a5018a62bfab07cd575d90f7fd2399986a4d18440d7c86b1002eede7a39d88e53876a94796f456c6050322da77dab8ef069a4832d792022d1b" + "salt": "0xd8f63c3065e0fcca5374c2e85ec222cfa3ad92dcb465b3b8b19dd2f0982e7bdb", + "sign": "0xeb86d1560702069a210c1caf682f1a336096b5b3c316da2eecff42107a622cad2bf72fbf6e54f28dff42f07e3d56083d5d7e183aed26464c00e8ede95f1546291b" } } } \ No newline at end of file