atk-common 1.20.0__py3-none-any.whl → 1.22.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
atk_common/__init__.py CHANGED
@@ -1,5 +1,6 @@
1
1
  # __init__.py
2
- from atk_common.datetime_utils import date_time_utc, get_utc_date_time
2
+ from atk_common.datetime_utils import date_time_utc_column, get_utc_date_time, seconds_to_utc_timestamp, get_utc_date_from_iso
3
+ from atk_common.db_utils import sql, sql_with_record, convert_none_to_null
3
4
  from atk_common.env_utils import get_env_value
4
5
  from atk_common.error_utils import get_message, create_error_log, get_error_entity, handle_error, get_response_error, get_error_type
5
6
  from atk_common.http_utils import is_http_status_ok, is_http_status_internal, get_test_response
@@ -9,8 +10,13 @@ from atk_common.response_utils import create_response, is_response_ok
9
10
  from atk_common.docker_utils import get_current_container_info
10
11
 
11
12
  __all__ = [
12
- 'date_time_utc',
13
+ 'date_time_utc_column',
13
14
  'get_utc_date_time',
15
+ 'seconds_to_utc_timestamp',
16
+ 'get_utc_date_from_iso',
17
+ 'sql',
18
+ 'sql_with_record',
19
+ 'convert_none_to_null',
14
20
  'get_env_value',
15
21
  'get_message',
16
22
  'create_error_log',
@@ -1,7 +1,12 @@
1
1
  from datetime import datetime, timezone
2
2
 
3
- def date_time_utc(column):
4
- return 'TO_CHAR({0} at time zone \'UTC\', \'yyyy-mm-dd hh24:mi:ss.ms"Z"\')'.format(column)
5
-
6
3
  def get_utc_date_time():
7
4
  return str(datetime.now(timezone.utc))
5
+
6
+ def seconds_to_utc_timestamp(seconds):
7
+ return str(datetime.fromtimestamp(seconds, tz=timezone.utc))
8
+
9
+ def get_utc_date_from_iso(date_time):
10
+ dt = datetime.fromisoformat(date_time)
11
+ dt_utc = dt.astimezone(timezone.utc)
12
+ return str(dt_utc.date())
atk_common/db_utils.py CHANGED
@@ -0,0 +1,26 @@
1
+ import psycopg2
2
+ from psycopg2.extras import RealDictCursor
3
+
4
+ def sql(connection, sql, get_one):
5
+ with connection:
6
+ with connection.cursor(cursor_factory=RealDictCursor) as cursor:
7
+ cursor.execute(sql)
8
+ if get_one:
9
+ return cursor.fetchone()
10
+ return cursor.fetchall()
11
+
12
+ def sql_with_record(connection, sql, record):
13
+ with connection:
14
+ with connection.cursor(cursor_factory=RealDictCursor) as cursor:
15
+ cursor.execute(sql, record)
16
+ return cursor.fetchone()
17
+
18
+ def convert_none_to_null(value):
19
+ if value is None or value == '':
20
+ return 'null'
21
+ if type(value) is str:
22
+ return '\'' + value + '\''
23
+ return value
24
+
25
+ def date_time_utc_column(column):
26
+ return 'TO_CHAR({0} at time zone \'UTC\', \'yyyy-mm-dd hh24:mi:ss.ms"Z"\')'.format(column)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atk_common
3
- Version: 1.20.0
3
+ Version: 1.22.0
4
4
  Summary: ATK common methods
5
5
  Home-page: https://github.com/pypa/atk_common
6
6
  Author: Roger
@@ -1,6 +1,6 @@
1
- atk_common/__init__.py,sha256=nG-PFquhz5ycFh1zY1zLqAFPOCbalD80_YmLcJ4vqr0,1093
2
- atk_common/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
3
- atk_common/db_utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1
+ atk_common/__init__.py,sha256=1BDL1loiv5TTOOVAXL1ZhJ-yYox3ema2t_mGpNraUYg,1360
2
+ atk_common/datetime_utils.py,sha256=tMXB3ZuRG8GyA25YLaNXhs4cVHF5zWdw9fXOh0Z9kQw,379
3
+ atk_common/db_utils.py,sha256=6S-WlQltnYjrG0AJ1BXwLgkqT4T6cQmHnHI9ksCdy38,869
4
4
  atk_common/docker_utils.py,sha256=nkUhp2OhwJsm41JDujHDY-JxQfdDjy91duprH59Esfk,2084
5
5
  atk_common/env_utils.py,sha256=66v-S0vlkJNaun6ay1XcOGRtYJb4Ce4odJsWxuaHsQc,373
6
6
  atk_common/error_utils.py,sha256=7SN-Jz3i2MGIPqsexnjgbZg5poMnALLEiCJQ4za5im4,2398
@@ -23,7 +23,7 @@ atk_common/enums/section_role_enum.py,sha256=9rwep4Wmvyvnlrey08TRRoi8VQYAPkylpP0
23
23
  atk_common/enums/sensor_type_enum.py,sha256=UBa3LPyGTKgEJV578CqFlwXjnlXqVlybrvzdjsHhjSU,80
24
24
  atk_common/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
25
25
  atk_common/enums/violation_type_enum.py,sha256=01qTHOj-O8bOc-nwIHVnxLosm4cusD_YuqXM3ZsiRRk,86
26
- atk_common-1.20.0.dist-info/licenses/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
26
+ atk_common-1.22.0.dist-info/licenses/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
27
27
  atk_package/__init__.py,sha256=EceDa352WFHTdC_LxYANXf_TS9pGzK3MCx87bwAKTvg,811
28
28
  atk_package/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
29
29
  atk_package/env_utils.py,sha256=bXOrxM3fZUslqfmZt75iphbEJHbG4riJa8XOVzPwIII,313
@@ -36,7 +36,7 @@ atk_package/enums/__init__.py,sha256=oW0aVnwewfH6sNu14jjZ5_uP4iRN4pRmGdTNC204rHo
36
36
  atk_package/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
37
37
  atk_package/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
38
38
  shared_python_atk_enforcement/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
- atk_common-1.20.0.dist-info/METADATA,sha256=tGgmjgTI8pwI6wAhOupxVqT12rZp6CAF-5gkYRk1BoI,1464
40
- atk_common-1.20.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
41
- atk_common-1.20.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
42
- atk_common-1.20.0.dist-info/RECORD,,
39
+ atk_common-1.22.0.dist-info/METADATA,sha256=RR_FNbXxiPxUclSI0J-9jX320CrewoFnDIEw-QUhsgM,1464
40
+ atk_common-1.22.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
41
+ atk_common-1.22.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
42
+ atk_common-1.22.0.dist-info/RECORD,,