DmitrMakeev commited on
Commit
5dddc13
·
verified ·
1 Parent(s): b57de85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -27
app.py CHANGED
@@ -166,35 +166,32 @@ for db in DATABASES:
166
 
167
  init_settings_db()
168
  DATABASE_NEW = 'data_gc.db'
 
 
169
  def load_settings():
170
- conn = sqlite3.connect(SETTINGS_DB)
171
- cursor = conn.cursor()
172
- cursor.execute('SELECT * FROM settings')
173
- settings = cursor.fetchone()
174
- conn.close()
175
- if settings is None:
176
- return {
177
- 'api_key_auth': '',
178
- 'crypto_key_auth': '',
179
- 'crypto_key_url': '',
180
- 'vk_api_key': '',
181
- 'senler_token': '',
182
- 'wa_ak': '',
183
- 'wa_api_key': '',
184
- 'curators': '',
185
- 'call_api_key': ''
186
- }
187
- return {
188
- 'api_key_auth': settings[1] if settings[1] is not None else '',
189
- 'crypto_key_auth': settings[2] if settings[2] is not None else '',
190
- 'crypto_key_url': settings[3] if settings[3] is not None else '',
191
- 'vk_api_key': settings[4] if settings[4] is not None else '',
192
- 'senler_token': settings[5] if settings[5] is not None else '',
193
- 'wa_ak': settings[6] if settings[6] is not None else '',
194
- 'wa_api_key': settings[7] if settings[7] is not None else '',
195
- 'curators': settings[8] if settings[8] is not None else '',
196
- 'call_api_key': settings[9] if settings[9] is not None else ''
197
  }
 
 
 
 
 
 
 
 
 
 
 
 
198
  def save_settings(settings_dict):
199
  # Удаляем api_key_sys из словаря перед сохранением
200
  if 'api_key_sys' in settings_dict:
 
166
 
167
  init_settings_db()
168
  DATABASE_NEW = 'data_gc.db'
169
+
170
+
171
  def load_settings():
172
+ default_settings = {
173
+ 'api_key_auth': '',
174
+ 'crypto_key_auth': '',
175
+ 'crypto_key_url': '',
176
+ 'vk_api_key': '',
177
+ 'senler_token': '',
178
+ 'wa_ak': '',
179
+ 'wa_api_key': '',
180
+ 'curators': '',
181
+ 'call_api_key': ''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
+
184
+ with sqlite3.connect(SETTINGS_DB) as conn:
185
+ cursor = conn.cursor()
186
+ cursor.execute('SELECT * FROM settings')
187
+ settings = cursor.fetchone()
188
+
189
+ if settings is None:
190
+ return default_settings
191
+
192
+ # Создание словаря с использованием значений по умолчанию
193
+ return {key: settings[i + 1] or '' for i, key in enumerate(default_settings)}
194
+
195
  def save_settings(settings_dict):
196
  # Удаляем api_key_sys из словаря перед сохранением
197
  if 'api_key_sys' in settings_dict: