import
datetime
import
pytz
from
sqlalchemy
import
*
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declarative_base
base_class
=
declarative_base()
class
Employee(base_class):
__tablename__
=
'employee'
id
=
Column(Integer, primary_key
=
True
)
name
=
Column(String(
50
))
age
=
Column(Integer)
salary
=
Column(DECIMAL)
hire_date
=
Column(Date)
hire_time
=
Column(Time)
time_zone
=
Column(String(
500
))
Session
=
sessionmaker(bind
=
engine)
session
=
Session()
print
(
"connection established..."
)
base_class.metadata.create_all(engine)
print
(
"table created..."
)
Obj1
=
datetime.datetime(year
=
2020
, month
=
5
, day
=
23
, hour
=
10
,
minute
=
30
, second
=
30
, tzinfo
=
pytz.timezone(
"Europe/London"
))
Obj2
=
datetime.datetime(year
=
2022
, month
=
12
, day
=
30
, hour
=
18
,
minute
=
30
, second
=
30
, tzinfo
=
pytz.timezone(
"America/New_York"
))
Obj3
=
datetime.datetime.now()
todayDate
=
Obj3.date()
todayTime
=
Obj3.time()
currentTimeZone
=
current_timezone
=
pytz.timezone(
pytz.country_timezones[
'IN'
][
0
])
print
(
"currnet time zone="
, currentTimeZone)
employee1
=
Employee(
id
=
1
, name
=
"Alice"
, age
=
25
, salary
=
50000
,
hire_date
=
Obj1.date(), hire_time
=
Obj1.time(), time_zone
=
Obj1.tzinfo)
employee2
=
Employee(
id
=
2
, name
=
"Bod"
, age
=
34
, salary
=
55000
,
hire_date
=
todayDate, hire_time
=
todayTime, time_zone
=
Obj1.tzinfo)
employee3
=
Employee(
id
=
3
, name
=
"Dhoni"
, age
=
54
, salary
=
75000
,
hire_date
=
Obj2.date(), hire_time
=
Obj2.time(), time_zone
=
Obj2.tzinfo)
employee4
=
Employee(
id
=
4
, name
=
"Kohli"
, age
=
55
, salary
=
150000
,
hire_date
=
todayDate, hire_time
=
todayTime, time_zone
=
Obj2.tzinfo)
employee5
=
Employee(
id
=
5
, name
=
"Raju"
, age
=
35
, salary
=
65000
, hire_date
=
Obj1.date(
), hire_time
=
Obj1.time(), time_zone
=
currentTimeZone)
employee6
=
Employee(
id
=
6
, name
=
"Ravi"
, age
=
45
, salary
=
25000
,
hire_date
=
todayDate, hire_time
=
todayTime, time_zone
=
currentTimeZone)
session.add_all([employee1, employee2, employee3,
employee4, employee5, employee6])
print
(
"successfully data added to session"
)
session.commit()
print
(
"successfully inserted data"
)
session.close()
print
(
"DB connection closed"
)