43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
|
import pyodbc
|
||
|
|
||
|
# region constant values
|
||
|
# این توکن بسیار مهم است. چون هر از گاهی این توکن منقضی می شود
|
||
|
# و باید توکن معتبر جدید از سایت قوانین درحالت لاگین شده،
|
||
|
# دریافت شود و به جای توکن زیر جایگزین شود
|
||
|
TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MjA1MDUwMzAsImp0aSI6ImxPYVpGUWRhZXlSVkVUY3NNeUp2bUNTNXhHbmJZSTBHIiwiaXNzIjoiaHR0cHM6XC9cL2NwLnRhdmFzaS5pciIsImV4cCI6MTcyMTgwNTAyOSwiYXVkIjoiaHR0cHM6XC9cL2NwLnRhdmFzaS5pciIsImRhdGEiOnsiaWQiOjEsImZpcnN0X25hbWUiOiJcdTA2MjhcdTA2MzFcdTA2NDZcdTA2MjdcdTA2NDVcdTA2NDcgXHUwNjQ2XHUwNjQ4XHUwNmNjXHUwNjMzIiwibGFzdF9uYW1lIjoiXHUwNjQxXHUwNjQ2XHUwNmNjIiwiZW1haWwiOiJkZXZAZ21haWwuY29tIiwidXNlcm5hbWUiOiJkZXYiLCJ1c2VyX2xldmVsIjoyfX0.PBIThW_3mG29ZPHiYH3wfwbBLN5jkG_q1qv6IFkwYz8'
|
||
|
ACCEPT = "application/json"
|
||
|
HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT}
|
||
|
# endregion
|
||
|
|
||
|
def create_cursor(dbname = ''):
|
||
|
if dbname == '':
|
||
|
dbname = "Qavanin"
|
||
|
|
||
|
# server = "DESKTOP-ENVCI85"
|
||
|
# database = dbname
|
||
|
# username = "Mofid3"
|
||
|
# password = "12345"
|
||
|
|
||
|
# ******** مهم *********
|
||
|
# uncomment for jokar pc
|
||
|
server = "MOFID5"
|
||
|
database = dbname
|
||
|
username = "Mofid5"
|
||
|
password = "12345"
|
||
|
|
||
|
# ENCRYPT defaults to yes starting in ODBC Driver SQL Server. It's good to always specify ENCRYPT=yes on the client side to avoid MITM attacks.
|
||
|
cnxn = pyodbc.connect(
|
||
|
"DRIVER={SQL Server};SERVER="
|
||
|
+ server
|
||
|
+ ";DATABASE="
|
||
|
+ database
|
||
|
+ ";Trusted_Connection=yes;UID="
|
||
|
+ username
|
||
|
+ ";PWD="
|
||
|
+ password
|
||
|
)
|
||
|
# cnxn = pyodbc.connect('DSN=sqldsn;')
|
||
|
cursor = cnxn.cursor()
|
||
|
return cursor, cnxn
|
||
|
|