Skip to content

Commit 838c37a

Browse files
author
Anh-Duy Le
committed
DLE-190515-First commit init proj
0 parents  commit 838c37a

File tree

10 files changed

+252
-0
lines changed

10 files changed

+252
-0
lines changed

Test_OnSolve.code-workspace

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {}
8+
}

__main__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sys
2+
import os
3+
4+
5+
ROOT_DIR = os.getcwd() # Get root directory
6+
sys.path.append(os.path.dirname(ROOT_DIR + r'/'))# Add absolute path to current sys.path
7+
# print('Path: ' + str(sys.path))
8+
9+
10+
"""
11+
doc: Main base class
12+
"""
13+
class Main():
14+
15+
def __init__(self):
16+
pass
17+
18+
def mainProcess(self):
19+
20+
try:
21+
pass
22+
23+
except Exception as ex:
24+
print('Error: ', ex)
25+
26+
print('#'*40)
27+
return
28+
29+
"""
30+
doc: Code will begin from here
31+
"""
32+
if __name__ == '__main__':
33+
proc = Main()
34+
proc.mainProcess()
35+
36+
37+
38+
### BUILD APP
39+
# Step 1: Put all images folder to "dist" folder (folder to deploy app)
40+
# Step 2: Open CMD/Terminal and change directory path to main.py
41+
# Step 3: Run command => pyinstaller main.py

config.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"version": "1.0",
3+
"configurations":[
4+
{
5+
"type": "project_info",
6+
"project_name": "Test_OnSolve"
7+
},
8+
{
9+
"type": "api",
10+
"api_type": "banking_exchange_rates",
11+
"site_name": "openexchangerates",
12+
"site_domain": "https://openexchangerates.org",
13+
"is_default": "True",
14+
"api_url": "/api/historical/",
15+
"api_extension": ".json",
16+
"api_params": [
17+
{
18+
"param_name": "app_id",
19+
"default_vaule": "e1e21981345b4bbe959f49186802ce97"
20+
},
21+
{
22+
"param_name": "base",
23+
"default_vaule": "USD"
24+
}
25+
]
26+
},
27+
{
28+
"type": "api",
29+
"api_type": "banking_exchange_rates",
30+
"site_name": "exchangeratesapi",
31+
"site_domain": "https://api.exchangeratesapi.io",
32+
"is_default": "False",
33+
"api_url": "/",
34+
"api_extension": ".json",
35+
"api_params": [
36+
{
37+
"param_name": "base",
38+
"default_vaule": "USD"
39+
}
40+
]
41+
},
42+
]
43+
}

config.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import json
2+
import sys, os
3+
from pathlib import Path, PureWindowsPath
4+
5+
ROOT_DIR = os.getcwd()# Get root directory
6+
sys.path.append(os.path.dirname(ROOT_DIR + r'/'))# Add absolute path to current sys.path
7+
# print('Path: ' + str(sys.path))
8+
9+
class Configuration():
10+
11+
12+
def __init__(self):
13+
Configuration.ConfigFileName = "config.json"
14+
Configuration.Platform = self.getOSplatform()
15+
self.apiType_banking = "banking_exchange_rates"
16+
17+
18+
def getOSplatform(self):
19+
os = ""
20+
21+
if sys.platform == "linux" or sys.platform == "linux2":
22+
os = "Linux"
23+
elif sys.platform == "darwin":
24+
os = "OSX"
25+
elif sys.platform == "win32":
26+
os = "Window"
27+
28+
return os
29+
30+
31+
def getApiConnection(self, apiName, apiType):
32+
33+
try:
34+
filename = Path(ROOT_DIR + r'\\' + Configuration.ConfigFileName)
35+
with open(filename, 'rt') as config_file:
36+
config = json.load(config_file)
37+
# print(config)
38+
for cf in list(config['configurations']):
39+
if(cf['type'] == "api" and cf['api_type'] == self.apiType_banking and cf['is_default'] == "True"):
40+
return cf
41+
42+
return None
43+
44+
except Exception as ex:
45+
print('Error: ', ex)
46+
47+
48+
49+
50+
726 Bytes
Binary file not shown.
966 Bytes
Binary file not shown.

core_utils/util_common.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from datetime import datetime
2+
3+
4+
class Core_UtilityCommon():
5+
6+
7+
def __init__(self):
8+
pass
9+
10+
def validateDateFormat(self, date_text):
11+
try:
12+
if date_text != datetime.strptime(date_text, "%Y-%m-%d").strftime('%Y-%m-%d'):
13+
raise ValueError
14+
return True
15+
except ValueError:
16+
return False
17+
18+

core_utils/util_data.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import urllib
2+
import json
3+
import urllib.request
4+
5+
class Core_UtilityData():
6+
7+
def __init__(self):
8+
pass
9+
10+
def readJsonFromFile(self, path):
11+
file = open(path, encoding='utf-8')
12+
content = json.load(file)
13+
file.close()
14+
return content
15+
16+
def readJsonFromUrl(self, url):
17+
with urllib.request.urlopen(url) as data:
18+
content = json.loads(data.read().decode())
19+
return content
20+
21+

domains/ApiOpenExcRateModel.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
"""
3+
doc: Model class with the decorator
4+
"""
5+
class ApiOpenExcRateModel(object):
6+
"""
7+
A data descriptor that sets and returns values normally and optional prints a message logging their access.
8+
"""
9+
def __init__(self):
10+
pass
11+
12+
@property
13+
def Currency(self):
14+
return self.__Currency
15+
@Currency.setter
16+
def Currency(self, val):
17+
self.__Currency = val
18+
19+
20+
@property
21+
def RateValue(self):
22+
return self.__RateValue
23+
@RateValue.setter
24+
def RateValue(self, val):
25+
self.__RateValue = val
26+

unit_tests/test_utility.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import unittest
2+
import sys, os
3+
import urllib
4+
import urllib.parse
5+
6+
7+
ROOT_DIR = os.getcwd() # Get root directory
8+
sys.path.append(os.path.dirname(ROOT_DIR + r'/'))# Add absolute path to current sys.path
9+
# print('Path: ' + str(sys.path))
10+
11+
from core_utils.util_common import Core_UtilityCommon
12+
from core_utils.util_data import Core_UtilityData
13+
14+
class UtilityTestCase(unittest.TestCase):
15+
16+
UtilCommon = Core_UtilityCommon()
17+
UtilData = Core_UtilityData()
18+
19+
def test_common__validateDateFormat(self):
20+
21+
self.assertTrue(UtilityTestCase.UtilCommon.validateDateFormat('2016-01-15'), '###Error Message: Not valid')
22+
23+
self.assertFalse(UtilityTestCase.UtilCommon.validateDateFormat('2016-01-32'), '###Error Message: Not valid')
24+
25+
self.assertFalse(UtilityTestCase.UtilCommon.validateDateFormat('2016-13-01'), '###Error Message: Not valid')
26+
27+
self.assertFalse(UtilityTestCase.UtilCommon.validateDateFormat('2019-2-30'), '###Error Message: Not valid')
28+
29+
def test_data_readJsonFromUrl(self):
30+
args = '2016-01-15'
31+
baseCurrency = 'USD'
32+
url = "https://openexchangerates.org/api/historical/{0}.json?app_id=e1e21981345b4bbe959f49186802ce97&base={1}".format(args, baseCurrency)# urllib.parse.urlencode()
33+
34+
content = UtilityTestCase.UtilData.readJsonFromUrl(url)
35+
print(content)
36+
# for item in content:
37+
# print(item['title'] + ' - ' + item['woeid'])
38+
39+
###########################################################################################################
40+
"""
41+
doc: Code will begin from here
42+
"""
43+
if __name__ == '__main__':
44+
45+
unittest.main()

0 commit comments

Comments
 (0)