-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
247 lines (198 loc) · 7.12 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import dataset
import psycopg2
import sqlalchemy
import sqlalchemy as sql
from dbfread import DBF
import os
import json
import glob
import sys
import pathlib
# db = sql.create_engine('postgresql+psycopg2://postgres:admin@localhost/data')
# connect = db.connect()
# if connect:
# print('succes')
# else:
# print('dont connected')
# Для подключение MSSQL
def create_psql_conf():
global config_dir
config_dir = 'config_sql' #Имя config файла psql
config_dir = 'config' #Имя config файла psql
config_txt = 'config.txt'
directory_path = os.getcwd()
path = os.path.join(directory_path, config_dir)
print("Текущая деректория:", directory_path)
if not os.path.isdir(config_dir):
os.mkdir(config_dir)
os.chdir(directory_path+f'\\{config_dir}')
print('Следующая директория' + os.getcwd())
if not os.path.exists(config_txt):
text_file = open(config_txt, "w", encoding='utf-8')
text_file.write('{"username":"postgres", "password":"admin", "host":"host", "database":"data"}')
# create_psql_conf()
def create_txt_file():
"""
Чтобы иницилизировать файл для получения информации о sql данных
This function for creating a txt file for information of sql
"""
text_psql = '{"username":"postgres", "password":"admin", "host":"localhost", "database":"data"}'
text_msql = '{"username":"beksultan", "password":"beksultan", "host":"127.0.0.1", "database":"data","port":"1433","sqldriver":"SQL Server", "server":"DESKTOP-OG81R5M\\SQLEXPRESS"}'
print("Я на директории ", os.getcwd())
if not os.path.isfile('config.txt') or os.path.isfile('config_msql.txt'):
text_psql_file = open('config.txt',"w")
text_psql_file.write(text_psql)
text_msql_file = open('config_msql.txt', 'w')
text_msql_file.write(text_msql)
def create_folder():
if not os.path.isdir("folder"):
os.mkdir("folder")
else:
os.chdir('folder')
print("Я в директории ",os.getcwd())
create_txt_file()
create_folder()
#
# def read_sql_conf():
# print("После создания txt файла ", os.getcwd())
# print(os.listdir()) #Проверка файла txt
#
# # os.chdir(a+f'\\{config_dir}')
# with open("config.txt", "r", encoding='utf-8') as f: # Чтобы вытаскывать все данные
# for l in f:
# print(l)
# data = l
# a = json.loads(data)
# print(type(a))
# print(a, '\n', a['username'])
#
# def read_psql_conf():
# global config_dir
# a = os.getcwd()
# for path in sys.path:
# if os.path.exists(os.path.join(path, 'config/config.txt')):
# print('some_module is heresdf safd asdfsfd : {}'.format(path))
# a = path
#
# print('desktop бул',a)
# print(os.getcwd())
# os.chdir(a+'\\config')
# print(os.getcwd())
# print("После создания txt файла ", os.getcwd())
# print(os.listdir()) #Проверка файла txt
# с = os.chdir(b)
# print('Теперь 3 директория', с)
# os.chdir(a+'\\config')
# with open("config.txt", "r", encoding='utf-8') as f:
# for l in f:
# print(l)
# data = l
# a = json.loads(data)
# # print(type(a))
# # print(a, '\n', a['username'])
# return a
# create_psql_conf()
# read_psql_conf()
# print(type(a))
# print(a['username'])
#
# import sys
# import os
#
# print(os.getcwd())
# for path in sys.path:
# if os.path.exists(os.path.join(path, 'config/config.txt')):
# print('some_module is heresdf safd asdfsfd : {}'.format(path))
#
# import os
# from os.path import join
# import fnmatch
# lookfor = "config.txt"
# for root, dirs, files in os.walk('C:\\'):
# for found in fnmatch.filter(files, lookfor):
# print("found: %s" % join(root, found))
#
# filename = 'config.txt'
# for root, dirnames, filenames in os.walk('/config'):
# for file in filenames:
# if file == filename:
# print(os.path.join(root, file))
# conf_sql = read_psql_conf()
# conn = psycopg2.connect(f"dbname={conf_sql['database']} user={conf_sql['username']} password={conf_sql['password']} host={conf_sql['host']}")
# if conn:
# print('Подключено к PSQL')
# Для подключение MSSQL
# def create_msql_conf():
# global config_dir
# config_txt = 'config_msql.txt'
# directory_path = os.getcwd()
#
# path = os.path.join(directory_path, config_dir)
# print("Текущая деректория:", directory_path)
# if not os.path.isdir(config_dir):
# os.mkdir(config_dir)
#
# os.chdir(directory_path+f'\\{config_dir}')
# print('Следующая директория' + os.getcwd())
#
# if not os.path.exists(config_txt):
# text_file = open(config_txt, "w", encoding='utf-8')
# text_file.write('{"username":"postgres", "password":"admin", "host":"host", "database":"data"}')
# def psql():
# try:
# conn = psycopg2.connect("dbname=data user=postgres password=admin")
# return True
# except:
# return False
# print(psql())
# db = dataset.connect(url= 'postgresql://postgres:admi@localhost/data')
# if db:
# print('succesfully connected')
# else:
# print('don"t connected')
#
# table = db.create_table('population')
# table = db['popuion']
# for record in DBF('oked.dbf'):
# table.insert(record)
# {"username":"postgres", "password":"admin", "host":"host", "database":"data"}
#
# def file_path():
# while True:
# name_file = input('1) Показать файлы \n'
# '2) Выбрать файл \n'
# '3) Вернуться в меню \n'
# '4) чтобы выйти нажмите любую клавишу \n \n'
# ' Введите путь к файлу: \n ')
#
# if os.path.exists(name_file):
# print(f'{name_file} указанный файл существует {name_file} обработан \n')
# elif name_file == '1':
# print(os.listdir(), '\n')
# elif name_file == '3':
# return file_path()
# else:
# print(f"{name_file} файл не существует \n")
#
#
# file_path()
# os.getcwd() показывает текущий путь
# engine = create_engine('postgresql+psycopg2://postgres:admin@localhost/dbf')
# conn = engine.connect()
# if conn:
# print('sub')
# f = sqlalchemy
# a=f.create_engine("postgresql+psycopg2://postgres:admin@host:5432/dbf")
# if a:
# print('succesfully connected')
# db = dataset.connect("postgresql+psycopg2://postgres:admin@host:5432/dbf")
# if db:
# print('sfsf')
# table = db['person']
# table.insert(dict(name='S'))
# db = dataset.connect("postgresql+psycopg2://postgres:admin@/dbf")
# db = create_engine("postgresql+psycopg2://postgres:admin@host:5432/dbf")
# if db is True:
# print('succesfull')
#
# db.create_table('population')