DmitrMakeev
commited on
Commit
•
f4372e1
1
Parent(s):
5eab77b
Update app.py
Browse files
app.py
CHANGED
@@ -1525,10 +1525,24 @@ mapp_templates = {
|
|
1525 |
|
1526 |
DATABASE_NAME3 = 'data_gc.db'
|
1527 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1528 |
|
1529 |
-
|
1530 |
-
|
1531 |
-
def add_or_update_contact(contact_data):
|
1532 |
conn = sqlite3.connect(DATABASE_NAME3)
|
1533 |
cursor = conn.cursor()
|
1534 |
|
@@ -1562,24 +1576,14 @@ def add_or_update_contact(contact_data):
|
|
1562 |
|
1563 |
conn.commit()
|
1564 |
conn.close()
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
headers = {'Content-Type': 'application/json'}
|
1570 |
-
|
1571 |
-
logging.debug(f"Sending request to {full_url_ver} with payload: {payload}")
|
1572 |
-
|
1573 |
-
response = requests.post(full_url_ver, headers=headers, json=payload)
|
1574 |
-
|
1575 |
if response.status_code == 200:
|
1576 |
-
|
1577 |
-
logging.debug(f"Response from API: {response_body}")
|
1578 |
-
return response_body.get('existsWhatsapp', 'false')
|
1579 |
else:
|
1580 |
-
logging.error(f"
|
1581 |
-
return "Error"
|
1582 |
-
|
1583 |
|
1584 |
@app.route('/add_data_ver_cur', methods=['GET'])
|
1585 |
def add_data_ver_cur():
|
@@ -1604,17 +1608,17 @@ def add_data_ver_cur():
|
|
1604 |
logging.error("Phone number is empty")
|
1605 |
return jsonify({'status': 'error', 'message': 'Phone number is empty'}), 400
|
1606 |
|
1607 |
-
phone_verification_response =
|
1608 |
if phone_verification_response is not None:
|
1609 |
user_data['ws_st'] = phone_verification_response
|
1610 |
|
1611 |
try:
|
1612 |
-
|
1613 |
if curator_on_off == "1":
|
1614 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
1615 |
|
1616 |
# Отправка данных в Google Forms
|
1617 |
-
|
1618 |
|
1619 |
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1620 |
except Exception as e:
|
@@ -1627,6 +1631,19 @@ def add_data_ver_cur():
|
|
1627 |
|
1628 |
|
1629 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1630 |
|
1631 |
DATABASE2 = 'data_gc.db'
|
1632 |
|
|
|
1525 |
|
1526 |
DATABASE_NAME3 = 'data_gc.db'
|
1527 |
|
1528 |
+
def verify_phone_number_v2(phone_number):
|
1529 |
+
full_url_ver = f"{wa_url}{wa_ak}{ws_url_ver}{wa_api_key}"
|
1530 |
+
payload = {"phoneNumber": phone_number}
|
1531 |
+
headers = {'Content-Type': 'application/json'}
|
1532 |
+
|
1533 |
+
logging.debug(f"Sending request to {full_url_ver} with payload: {payload}")
|
1534 |
+
|
1535 |
+
response = requests.post(full_url_ver, headers=headers, json=payload)
|
1536 |
+
|
1537 |
+
if response.status_code == 200:
|
1538 |
+
response_body = response.json()
|
1539 |
+
logging.debug(f"Response from API: {response_body}")
|
1540 |
+
return response_body.get('existsWhatsapp', 'false')
|
1541 |
+
else:
|
1542 |
+
logging.error(f"API request failed with status code {response.status_code}: {response.text}")
|
1543 |
+
return "Error"
|
1544 |
|
1545 |
+
def add_or_update_contact_v2(contact_data):
|
|
|
|
|
1546 |
conn = sqlite3.connect(DATABASE_NAME3)
|
1547 |
cursor = conn.cursor()
|
1548 |
|
|
|
1576 |
|
1577 |
conn.commit()
|
1578 |
conn.close()
|
1579 |
+
def send_to_google_forms_v2(user_data, gog_url):
|
1580 |
+
logging.debug(f"Sending data to Google Forms: {user_data}")
|
1581 |
+
url = gog_url.format(**user_data)
|
1582 |
+
response = requests.post(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
1583 |
if response.status_code == 200:
|
1584 |
+
logging.debug(f"Data sent to Google Forms successfully for user: {user_data.get('email')}")
|
|
|
|
|
1585 |
else:
|
1586 |
+
logging.error(f"Failed to send data to Google Forms for user: {user_data.get('email')}. Response: {response.text}")
|
|
|
|
|
1587 |
|
1588 |
@app.route('/add_data_ver_cur', methods=['GET'])
|
1589 |
def add_data_ver_cur():
|
|
|
1608 |
logging.error("Phone number is empty")
|
1609 |
return jsonify({'status': 'error', 'message': 'Phone number is empty'}), 400
|
1610 |
|
1611 |
+
phone_verification_response = verify_phone_number_v2(phone_number)
|
1612 |
if phone_verification_response is not None:
|
1613 |
user_data['ws_st'] = phone_verification_response
|
1614 |
|
1615 |
try:
|
1616 |
+
add_or_update_contact_v2(user_data)
|
1617 |
if curator_on_off == "1":
|
1618 |
current_curator_index = (current_curator_index + 1) % len(curators)
|
1619 |
|
1620 |
# Отправка данных в Google Forms
|
1621 |
+
send_to_google_forms_v2(user_data, gog_url)
|
1622 |
|
1623 |
return jsonify({'status': 'success', 'message': f'User added with curator {user_data.get("curator", "not assigned")}'})
|
1624 |
except Exception as e:
|
|
|
1631 |
|
1632 |
|
1633 |
|
1634 |
+
|
1635 |
+
|
1636 |
+
|
1637 |
+
|
1638 |
+
|
1639 |
+
|
1640 |
+
|
1641 |
+
|
1642 |
+
|
1643 |
+
|
1644 |
+
|
1645 |
+
|
1646 |
+
|
1647 |
|
1648 |
DATABASE2 = 'data_gc.db'
|
1649 |
|