DmitrMakeev
commited on
Commit
•
7e0b45c
1
Parent(s):
462deca
Update app.py
Browse files
app.py
CHANGED
@@ -1754,6 +1754,102 @@ def add_data_ver():
|
|
1754 |
|
1755 |
|
1756 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1757 |
|
1758 |
|
1759 |
|
|
|
1754 |
|
1755 |
|
1756 |
|
1757 |
+
|
1758 |
+
|
1759 |
+
|
1760 |
+
|
1761 |
+
|
1762 |
+
|
1763 |
+
|
1764 |
+
|
1765 |
+
|
1766 |
+
|
1767 |
+
|
1768 |
+
|
1769 |
+
|
1770 |
+
# Пример шаблона сопоставления для настройки переменных записываемых в базу данных. - Не проверин
|
1771 |
+
mapping_template3 = {
|
1772 |
+
'name': 'name',
|
1773 |
+
'phone': 'phone',
|
1774 |
+
'email': 'email',
|
1775 |
+
'vk_id': 'vk_id',
|
1776 |
+
'chat_id': 'chat_id',
|
1777 |
+
'ws_st': 'ws_st',
|
1778 |
+
'ws_stop': 'ws_stop',
|
1779 |
+
'web_st': 'web_st',
|
1780 |
+
'fin_prog': 'fin_prog',
|
1781 |
+
'b_city': 'b_city',
|
1782 |
+
'b_fin': 'b_fin',
|
1783 |
+
'b_ban': 'b_ban',
|
1784 |
+
'b_ign': 'b_ign',
|
1785 |
+
'b_baners': 'b_baners',
|
1786 |
+
'b_butt': 'b_butt',
|
1787 |
+
'b_mess': 'b_mess',
|
1788 |
+
'shop_st': 'shop_st',
|
1789 |
+
'curator': 'curator',
|
1790 |
+
'pr1': 'pr1',
|
1791 |
+
'pr2': 'pr2',
|
1792 |
+
'pr3': 'pr3',
|
1793 |
+
'pr4': 'pr4',
|
1794 |
+
'pr5': 'pr5',
|
1795 |
+
'ad_url': 'ad_url',
|
1796 |
+
'key_pr': 'key_pr',
|
1797 |
+
'n_con': 'n_con',
|
1798 |
+
'canal': 'canal',
|
1799 |
+
'data_t': 'data_t'
|
1800 |
+
}
|
1801 |
+
|
1802 |
+
def add_user_bot(db_name, user_data, mapping_template3):
|
1803 |
+
conn = sqlite3.connect(db_name)
|
1804 |
+
cursor = conn.cursor()
|
1805 |
+
|
1806 |
+
# Преобразование данных пользователя на основе шаблона сопоставления
|
1807 |
+
transformed_data = {db_column: user_data.get(json_key, "") for json_key, db_column in mapping_template.items()}
|
1808 |
+
|
1809 |
+
columns = ', '.join(transformed_data.keys())
|
1810 |
+
placeholders = ', '.join('?' for _ in transformed_data)
|
1811 |
+
insert_query = f"INSERT INTO contacts ({columns}) VALUES ({placeholders})"
|
1812 |
+
insert_values = list(transformed_data.values())
|
1813 |
+
|
1814 |
+
cursor.execute(insert_query, insert_values)
|
1815 |
+
conn.commit()
|
1816 |
+
conn.close()
|
1817 |
+
|
1818 |
+
@app.route('/add_user_bot', methods=['GET'])
|
1819 |
+
def add_user_bot_route():
|
1820 |
+
db_name = request.args.get('db_name', 'data_gc.db') # Имя базы данных из параметра запроса
|
1821 |
+
user_data = {key: request.args.get(key, "") for key in mapping_template.keys()}
|
1822 |
+
|
1823 |
+
try:
|
1824 |
+
add_user_bot(db_name, user_data, mapping_template)
|
1825 |
+
return jsonify({'status': 'success', 'message': f'User added to {db_name}'})
|
1826 |
+
except Exception as e:
|
1827 |
+
logging.error(f"Error adding user: {e}")
|
1828 |
+
return jsonify({'status': 'error', 'message': str(e)}), 500
|
1829 |
+
|
1830 |
+
|
1831 |
+
|
1832 |
+
# Конец примера шаблона сопоставления для настройки переменных записываемых в базу данных.
|
1833 |
+
|
1834 |
+
|
1835 |
+
|
1836 |
+
|
1837 |
+
|
1838 |
+
|
1839 |
+
|
1840 |
+
|
1841 |
+
|
1842 |
+
|
1843 |
+
|
1844 |
+
|
1845 |
+
|
1846 |
+
|
1847 |
+
|
1848 |
+
|
1849 |
+
|
1850 |
+
|
1851 |
+
|
1852 |
+
|
1853 |
|
1854 |
|
1855 |
|