Update app.py
Browse files
app.py
CHANGED
|
@@ -724,9 +724,6 @@ def data_gc_tab_out():
|
|
| 724 |
|
| 725 |
DATABASE_NAME = 'data_gc.db'
|
| 726 |
|
| 727 |
-
gog_url = "https://docs.google.com/formResponse/d/e/1FAIpQLSc-JbmXvgpgGq6KrkXsYSsfMACVMyIDnNqrHy6jImGeSRcpiQ/{viewform}?usp=pp_url&entry.1556100878={name}&entry.1477412341={email}&entry.1634985541={phone}&entry.1736544219={vk_id}&entry.62153872={chat_id}&entry.1913752768={ws_st}&entry.1768186232={ws_stop}&entry.1198983592={web_st}&entry.994770784={fin_prog}&entry.910932310={b_city}&entry.1923801792={b_fin}&entry.2005444720={b_ban}&entry.741087361={b_ign}&entry.1316159837={b_baners}&entry.355123557={b_butt}&entry.395996312={b_mess}&entry.646571729={shop_st}&entry.578527800={curator}&entry.1936838964={pr1}&entry.1375537366={pr2}&entry.1249356084={pr3}&entry.752547226={pr4}&entry.704766458={pr5}&entry.1837661={gc_url}&entry.398837750={key_pr}&entry.225564240={n_con}&entry.1642320872={canal}&entry.1581826411={data_t}&entry.311131724={utm_source}&entry.1904279859={utm_medium}&entry.740234546={utm_campaign}&entry.880981295={utm_term}&entry.431306383={utm_content}"
|
| 728 |
-
|
| 729 |
-
|
| 730 |
def update_or_insert_user(db_name, user_data, mapping_template):
|
| 731 |
conn = sqlite3.connect(db_name)
|
| 732 |
cursor = conn.cursor()
|
|
@@ -826,19 +823,52 @@ def update_or_insert_user(db_name, user_data, mapping_template):
|
|
| 826 |
conn.close()
|
| 827 |
logging.debug(f"User with email {email} processed successfully")
|
| 828 |
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 835 |
if response.status_code == 200:
|
| 836 |
-
logging.info(
|
| 837 |
else:
|
| 838 |
-
logging.error(f"Failed to send
|
| 839 |
|
| 840 |
@app.route('/send_request', methods=['POST'])
|
| 841 |
-
def
|
| 842 |
token = request.form.get('token')
|
| 843 |
min_date = request.form.get('minDate')
|
| 844 |
type = request.form.get('type')
|
|
@@ -894,6 +924,7 @@ def send_get_request():
|
|
| 894 |
email = user_data.get('email')
|
| 895 |
if email and email not in processed_emails:
|
| 896 |
update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
|
|
|
|
| 897 |
processed_emails.add(email)
|
| 898 |
|
| 899 |
return jsonify({'status': 'User data saved successfully'})
|
|
@@ -943,50 +974,13 @@ def webhookbz():
|
|
| 943 |
email = user_data.get('email')
|
| 944 |
if email and email not in processed_emails:
|
| 945 |
update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
|
|
|
|
| 946 |
processed_emails.add(email)
|
| 947 |
|
| 948 |
return jsonify({'status': 'User data saved successfully'})
|
| 949 |
else:
|
| 950 |
return jsonify({'error': 'Failed to fetch data from the API'}), response.status_code
|
| 951 |
|
| 952 |
-
def generate_gog_url(user_data):
|
| 953 |
-
url = gog_url.format(
|
| 954 |
-
viewform='viewform',
|
| 955 |
-
name=quote(str(user_data.get('name', ''))),
|
| 956 |
-
email=quote(str(user_data.get('email', ''))),
|
| 957 |
-
phone=quote(str(user_data.get('phone', ''))),
|
| 958 |
-
vk_id=quote(str(user_data.get('vk_id', ''))),
|
| 959 |
-
chat_id=quote(str(user_data.get('chat_id', ''))),
|
| 960 |
-
ws_st=quote(str(user_data.get('ws_st', ''))),
|
| 961 |
-
ws_stop=quote(str(user_data.get('ws_stop', ''))),
|
| 962 |
-
web_st=quote(str(user_data.get('web_st', ''))),
|
| 963 |
-
fin_prog=quote(str(user_data.get('fin_prog', ''))),
|
| 964 |
-
b_city=quote(str(user_data.get('b_city', ''))),
|
| 965 |
-
b_fin=quote(str(user_data.get('b_fin', ''))),
|
| 966 |
-
b_ban=quote(str(user_data.get('b_ban', ''))),
|
| 967 |
-
b_ign=quote(str(user_data.get('b_ign', ''))),
|
| 968 |
-
b_baners=quote(str(user_data.get('b_baners', ''))),
|
| 969 |
-
b_butt=quote(str(user_data.get('b_butt', ''))),
|
| 970 |
-
b_mess=quote(str(user_data.get('b_mess', ''))),
|
| 971 |
-
shop_st=quote(str(user_data.get('shop_st', ''))),
|
| 972 |
-
curator=quote(str(user_data.get('curator', ''))),
|
| 973 |
-
pr1=quote(str(user_data.get('pr1', ''))),
|
| 974 |
-
pr2=quote(str(user_data.get('pr2', ''))),
|
| 975 |
-
pr3=quote(str(user_data.get('pr3', ''))),
|
| 976 |
-
pr4=quote(str(user_data.get('pr4', ''))),
|
| 977 |
-
pr5=quote(str(user_data.get('pr5', ''))),
|
| 978 |
-
gc_url=quote(str(user_data.get('gc_url', ''))),
|
| 979 |
-
key_pr=quote(str(user_data.get('key_pr', ''))),
|
| 980 |
-
n_con=quote(str(user_data.get('n_con', ''))),
|
| 981 |
-
canal=quote(str(user_data.get('canal', ''))),
|
| 982 |
-
data_t=quote(str(user_data.get('data_t', ''))),
|
| 983 |
-
utm_source=quote(str(user_data.get('utm_source', ''))),
|
| 984 |
-
utm_medium=quote(str(user_data.get('utm_medium', ''))),
|
| 985 |
-
utm_campaign=quote(str(user_data.get('utm_campaign', ''))),
|
| 986 |
-
utm_term=quote(str(user_data.get('utm_term', ''))),
|
| 987 |
-
utm_content=quote(str(user_data.get('utm_content', '')))
|
| 988 |
-
)
|
| 989 |
-
return url
|
| 990 |
|
| 991 |
|
| 992 |
|
|
|
|
| 724 |
|
| 725 |
DATABASE_NAME = 'data_gc.db'
|
| 726 |
|
|
|
|
|
|
|
|
|
|
| 727 |
def update_or_insert_user(db_name, user_data, mapping_template):
|
| 728 |
conn = sqlite3.connect(db_name)
|
| 729 |
cursor = conn.cursor()
|
|
|
|
| 823 |
conn.close()
|
| 824 |
logging.debug(f"User with email {email} processed successfully")
|
| 825 |
|
| 826 |
+
def send_to_google_forms(data):
|
| 827 |
+
form_url = (
|
| 828 |
+
"https://docs.google.com/forms/d/e/1FAIpQLSc-JbmXvgpgGq6KrkXsYSsfMACVMyIDnNqrHy6jImGeSRcpiQ/viewform?"
|
| 829 |
+
"usp=pp_url"
|
| 830 |
+
f"&name={data.get('name', '')}"
|
| 831 |
+
f"&email={data.get('email', '')}"
|
| 832 |
+
f"&phone={data.get('phone', '')}"
|
| 833 |
+
f"&vk_id={data.get('vk_id', '')}"
|
| 834 |
+
f"&chat_id={data.get('chat_id', '')}"
|
| 835 |
+
f"&ws_st={data.get('ws_st', '')}"
|
| 836 |
+
f"&ws_stop={data.get('ws_stop', '')}"
|
| 837 |
+
f"&web_st={data.get('web_st', '')}"
|
| 838 |
+
f"&fin_prog={data.get('fin_prog', '')}"
|
| 839 |
+
f"&b_city={data.get('b_city', '')}"
|
| 840 |
+
f"&b_fin={data.get('b_fin', '')}"
|
| 841 |
+
f"&b_ban={data.get('b_ban', '')}"
|
| 842 |
+
f"&b_ign={data.get('b_ign', '')}"
|
| 843 |
+
f"&b_baners={data.get('b_baners', '')}"
|
| 844 |
+
f"&b_butt={data.get('b_butt', '')}"
|
| 845 |
+
f"&b_mess={data.get('b_mess', '')}"
|
| 846 |
+
f"&shop_st={data.get('shop_st', '')}"
|
| 847 |
+
f"&curator={data.get('curator', '')}"
|
| 848 |
+
f"&pr1={data.get('pr1', '')}"
|
| 849 |
+
f"&pr2={data.get('pr2', '')}"
|
| 850 |
+
f"&pr3={data.get('pr3', '')}"
|
| 851 |
+
f"&pr4={data.get('pr4', '')}"
|
| 852 |
+
f"&pr5={data.get('pr5', '')}"
|
| 853 |
+
f"&gc_url={data.get('gc_url', '')}"
|
| 854 |
+
f"&key_pr={data.get('key_pr', '')}"
|
| 855 |
+
f"&n_con={data.get('n_con', '')}"
|
| 856 |
+
f"&canal={data.get('canal', '')}"
|
| 857 |
+
f"&data_t={data.get('data_t', '')}"
|
| 858 |
+
f"&utm_source={data.get('utm_source', '')}"
|
| 859 |
+
f"&utm_medium={data.get('utm_medium', '')}"
|
| 860 |
+
f"&utm_campaign={data.get('utm_campaign', '')}"
|
| 861 |
+
f"&utm_term={data.get('utm_term', '')}"
|
| 862 |
+
f"&utm_content={data.get('utm_content', '')}"
|
| 863 |
+
)
|
| 864 |
+
response = requests.post(form_url)
|
| 865 |
if response.status_code == 200:
|
| 866 |
+
logging.info("Data successfully sent to Google Forms")
|
| 867 |
else:
|
| 868 |
+
logging.error(f"Failed to send data to Google Forms: {response.status_code}")
|
| 869 |
|
| 870 |
@app.route('/send_request', methods=['POST'])
|
| 871 |
+
def send_request():
|
| 872 |
token = request.form.get('token')
|
| 873 |
min_date = request.form.get('minDate')
|
| 874 |
type = request.form.get('type')
|
|
|
|
| 924 |
email = user_data.get('email')
|
| 925 |
if email and email not in processed_emails:
|
| 926 |
update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
|
| 927 |
+
send_to_google_forms(user_data)
|
| 928 |
processed_emails.add(email)
|
| 929 |
|
| 930 |
return jsonify({'status': 'User data saved successfully'})
|
|
|
|
| 974 |
email = user_data.get('email')
|
| 975 |
if email and email not in processed_emails:
|
| 976 |
update_or_insert_user(DATABASE_NAME, user_data, mapping_template)
|
| 977 |
+
send_to_google_forms(user_data)
|
| 978 |
processed_emails.add(email)
|
| 979 |
|
| 980 |
return jsonify({'status': 'User data saved successfully'})
|
| 981 |
else:
|
| 982 |
return jsonify({'error': 'Failed to fetch data from the API'}), response.status_code
|
| 983 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 984 |
|
| 985 |
|
| 986 |
|