Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1823,8 +1823,6 @@ def insert_data_ss(data): | |
| 1823 |  | 
| 1824 |  | 
| 1825 |  | 
| 1826 | 
            -
            # Маршрут для приема GET запроса
         | 
| 1827 | 
            -
            # Маршрут для приема GET запроса
         | 
| 1828 | 
             
            @app.route('/order', methods=['GET'])
         | 
| 1829 | 
             
            def from_shop_st():
         | 
| 1830 | 
             
                try:
         | 
| @@ -1849,11 +1847,13 @@ def from_shop_st(): | |
| 1849 | 
             
                    conn = sqlite3.connect(DATABASE6)
         | 
| 1850 | 
             
                    cursor = conn.cursor()
         | 
| 1851 |  | 
| 1852 | 
            -
                    cursor.execute("SELECT  | 
| 1853 | 
             
                    result = cursor.fetchone()
         | 
| 1854 |  | 
| 1855 | 
             
                    if result:
         | 
| 1856 | 
            -
                         | 
|  | |
|  | |
| 1857 | 
             
                        shop_st_data = json.loads(shop_st)
         | 
| 1858 | 
             
                    else:
         | 
| 1859 | 
             
                        shop_st_data = {}
         | 
| @@ -1870,10 +1870,36 @@ def from_shop_st(): | |
| 1870 |  | 
| 1871 | 
             
                    shop_st_json = json.dumps(shop_st_data)
         | 
| 1872 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1873 | 
             
                    if result:
         | 
| 1874 | 
            -
                        cursor.execute( | 
| 1875 | 
             
                    else:
         | 
| 1876 | 
            -
                         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1877 |  | 
| 1878 | 
             
                    conn.commit()
         | 
| 1879 | 
             
                    conn.close()
         | 
|  | |
| 1823 |  | 
| 1824 |  | 
| 1825 |  | 
|  | |
|  | |
| 1826 | 
             
            @app.route('/order', methods=['GET'])
         | 
| 1827 | 
             
            def from_shop_st():
         | 
| 1828 | 
             
                try:
         | 
|  | |
| 1847 | 
             
                    conn = sqlite3.connect(DATABASE6)
         | 
| 1848 | 
             
                    cursor = conn.cursor()
         | 
| 1849 |  | 
| 1850 | 
            +
                    cursor.execute("SELECT * FROM contacts WHERE email = ? OR phone = ?", (email, phone))
         | 
| 1851 | 
             
                    result = cursor.fetchone()
         | 
| 1852 |  | 
| 1853 | 
             
                    if result:
         | 
| 1854 | 
            +
                        columns = [desc[0] for desc in cursor.description]
         | 
| 1855 | 
            +
                        shop_st_index = columns.index('shop_st')
         | 
| 1856 | 
            +
                        shop_st = result[shop_st_index] if result[shop_st_index] else '{}'
         | 
| 1857 | 
             
                        shop_st_data = json.loads(shop_st)
         | 
| 1858 | 
             
                    else:
         | 
| 1859 | 
             
                        shop_st_data = {}
         | 
|  | |
| 1870 |  | 
| 1871 | 
             
                    shop_st_json = json.dumps(shop_st_data)
         | 
| 1872 |  | 
| 1873 | 
            +
                    # Исключение столбцов
         | 
| 1874 | 
            +
                    excluded_columns = ['b_ban', 'b_baners', 'b_butt', 'b_city', 'b_fin', 'b_ign', 'b_mess', 'canal', 'chat_id', 'curator', 'data_on', 'data_t', 'fin_prog', 'gc_url', 'gcpc', 'key_pr', 'n_con', 'pr1', 'pr2', 'pr3', 'pr4', 'pr5', 'utm_campaign', 'utm_content', 'utm_medium', 'utm_source', 'utm_term', 'vk_id', 'web_st', 'ws_st', 'ws_stop']
         | 
| 1875 | 
            +
                    update_values = [name, phone, email, shop_st_json]
         | 
| 1876 | 
            +
                    update_columns = ['name', 'phone', 'email', 'shop_st']
         | 
| 1877 | 
            +
             | 
| 1878 | 
            +
                    for col in columns:
         | 
| 1879 | 
            +
                        if col not in excluded_columns and col not in update_columns:
         | 
| 1880 | 
            +
                            value = request.args.get(col, None)
         | 
| 1881 | 
            +
                            if value is not None:
         | 
| 1882 | 
            +
                                update_values.append(value)
         | 
| 1883 | 
            +
                                update_columns.append(col)
         | 
| 1884 | 
            +
             | 
| 1885 | 
            +
                    placeholders = ', '.join([f"{col} = ?" for col in update_columns])
         | 
| 1886 | 
            +
                    query = f"UPDATE contacts SET {placeholders} WHERE email = ? OR phone = ?"
         | 
| 1887 | 
            +
                    update_values.extend([email, phone])
         | 
| 1888 | 
            +
             | 
| 1889 | 
             
                    if result:
         | 
| 1890 | 
            +
                        cursor.execute(query, update_values)
         | 
| 1891 | 
             
                    else:
         | 
| 1892 | 
            +
                        insert_columns = ['name', 'phone', 'email', 'shop_st']
         | 
| 1893 | 
            +
                        insert_values = [name, phone, email, shop_st_json]
         | 
| 1894 | 
            +
                        for col in columns:
         | 
| 1895 | 
            +
                            if col not in excluded_columns and col not in insert_columns:
         | 
| 1896 | 
            +
                                value = request.args.get(col, None)
         | 
| 1897 | 
            +
                                if value is not None:
         | 
| 1898 | 
            +
                                    insert_values.append(value)
         | 
| 1899 | 
            +
                                    insert_columns.append(col)
         | 
| 1900 | 
            +
                        insert_placeholders = ', '.join(['?' for _ in insert_columns])
         | 
| 1901 | 
            +
                        insert_query = f"INSERT INTO contacts ({', '.join(insert_columns)}) VALUES ({insert_placeholders})"
         | 
| 1902 | 
            +
                        cursor.execute(insert_query, insert_values)
         | 
| 1903 |  | 
| 1904 | 
             
                    conn.commit()
         | 
| 1905 | 
             
                    conn.close()
         |