Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1689,6 +1689,7 @@ def add_data_ver_cur(): | |
| 1689 |  | 
| 1690 | 
             
            DATABASE2 = 'data_gc.db'
         | 
| 1691 |  | 
|  | |
| 1692 | 
             
            def verify_phone_number2(phone_number):
         | 
| 1693 | 
             
                if verifikation_start == "1":
         | 
| 1694 | 
             
                    full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
         | 
| @@ -1703,6 +1704,7 @@ def verify_phone_number2(phone_number): | |
| 1703 | 
             
                else:
         | 
| 1704 | 
             
                    return "false"
         | 
| 1705 |  | 
|  | |
| 1706 | 
             
            def parse_csv_data(data):
         | 
| 1707 | 
             
                parsed_data = []
         | 
| 1708 | 
             
                for item in data:
         | 
| @@ -1712,6 +1714,7 @@ def parse_csv_data(data): | |
| 1712 | 
             
                        parsed_data.append(dict(zip(headers, row)))
         | 
| 1713 | 
             
                return parsed_data
         | 
| 1714 |  | 
|  | |
| 1715 | 
             
            def insert_data2(data, template_key):
         | 
| 1716 | 
             
                global current_curator_index
         | 
| 1717 | 
             
                conn = sqlite3.connect(DATABASE2)
         | 
| @@ -1783,11 +1786,13 @@ def insert_data2(data, template_key): | |
| 1783 | 
             
                finally:
         | 
| 1784 | 
             
                    conn.close()
         | 
| 1785 |  | 
|  | |
| 1786 | 
             
            def verify_api_key():
         | 
| 1787 | 
             
                api_key = request.args.get('api_sys')
         | 
| 1788 | 
             
                if api_key != "fasSd345D":
         | 
| 1789 | 
             
                    return jsonify({"error": "Invalid API key"}), 403
         | 
| 1790 |  | 
|  | |
| 1791 | 
             
            @app.route('/upload_csv', methods=['POST'])
         | 
| 1792 | 
             
            def upload_csv():
         | 
| 1793 | 
             
                if 'file' not in request.files:
         | 
| @@ -1800,7 +1805,7 @@ def upload_csv(): | |
| 1800 | 
             
                    csv_input = csv.DictReader(stream)
         | 
| 1801 | 
             
                    data = [row for row in csv_input]
         | 
| 1802 | 
             
                    parsed_data = parse_csv_data(data)
         | 
| 1803 | 
            -
                    insert_data2(parsed_data, 'avp') | 
| 1804 | 
             
                    return jsonify({"message": "Data uploaded and inserted successfully"})
         | 
| 1805 | 
             
                return jsonify({"error": "Invalid file format"}), 400
         | 
| 1806 |  | 
|  | |
| 1689 |  | 
| 1690 | 
             
            DATABASE2 = 'data_gc.db'
         | 
| 1691 |  | 
| 1692 | 
            +
            # Функция для верификации номера телефона через внешний API
         | 
| 1693 | 
             
            def verify_phone_number2(phone_number):
         | 
| 1694 | 
             
                if verifikation_start == "1":
         | 
| 1695 | 
             
                    full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
         | 
|  | |
| 1704 | 
             
                else:
         | 
| 1705 | 
             
                    return "false"
         | 
| 1706 |  | 
| 1707 | 
            +
            # Функция для парсинга данных из CSV
         | 
| 1708 | 
             
            def parse_csv_data(data):
         | 
| 1709 | 
             
                parsed_data = []
         | 
| 1710 | 
             
                for item in data:
         | 
|  | |
| 1714 | 
             
                        parsed_data.append(dict(zip(headers, row)))
         | 
| 1715 | 
             
                return parsed_data
         | 
| 1716 |  | 
| 1717 | 
            +
            # Функция для вставки данных в базу данных
         | 
| 1718 | 
             
            def insert_data2(data, template_key):
         | 
| 1719 | 
             
                global current_curator_index
         | 
| 1720 | 
             
                conn = sqlite3.connect(DATABASE2)
         | 
|  | |
| 1786 | 
             
                finally:
         | 
| 1787 | 
             
                    conn.close()
         | 
| 1788 |  | 
| 1789 | 
            +
            # Функция для проверки API ключа
         | 
| 1790 | 
             
            def verify_api_key():
         | 
| 1791 | 
             
                api_key = request.args.get('api_sys')
         | 
| 1792 | 
             
                if api_key != "fasSd345D":
         | 
| 1793 | 
             
                    return jsonify({"error": "Invalid API key"}), 403
         | 
| 1794 |  | 
| 1795 | 
            +
            # Маршрут для загрузки CSV файла и вставки данных в базу данных
         | 
| 1796 | 
             
            @app.route('/upload_csv', methods=['POST'])
         | 
| 1797 | 
             
            def upload_csv():
         | 
| 1798 | 
             
                if 'file' not in request.files:
         | 
|  | |
| 1805 | 
             
                    csv_input = csv.DictReader(stream)
         | 
| 1806 | 
             
                    data = [row for row in csv_input]
         | 
| 1807 | 
             
                    parsed_data = parse_csv_data(data)
         | 
| 1808 | 
            +
                    insert_data2(parsed_data, 'avp')
         | 
| 1809 | 
             
                    return jsonify({"message": "Data uploaded and inserted successfully"})
         | 
| 1810 | 
             
                return jsonify({"error": "Invalid file format"}), 400
         | 
| 1811 |  |