DmitrMakeev commited on
Commit
91794fe
1 Parent(s): 1d0efde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -16
app.py CHANGED
@@ -4,35 +4,37 @@ import os
4
  import random
5
  import requests
6
  import time
 
 
 
 
7
 
 
8
 
9
- api_key_sys = os.getenv('api_key_sys')
 
10
 
11
- gc_url = os.getenv('gc_url')
12
- gc_api = os.getenv('gc_api')
13
 
14
- wa_url = os.getenv('wa_url')
15
- wa_api_key = os.getenv('wa_api_key')
16
-
17
-
18
- up_db = os.getenv('up_db')
19
 
 
 
20
 
 
 
21
 
 
22
 
 
23
 
24
  json_data = '''
25
  {"success":true,"error_message":"","error":false,"info": {"fields":["id","Email","Тип регистрации","Создан","Последняя активность","Имя","Фамилия","Телефон","Дата рождения","Возраст","Страна","Город","От партнера","Руч продлен Клуба","Промокод","bonus_05_23","Клуб 255 - колл. оплат","Согласен с договором оферты и политикой конфиденциальности","Согласен на рассылку","vk_id","chat_id","ws_st","ws_stop","web_st","fin_prog","shop_st","curator","pr1","pr2","pr3","pr4","pr5","ad_url","Ответ сервера","Откуда пришел","utm_source","utm_medium","utm_campaign","utm_term","utm_content","utm_group","ID партнера","Email партнера","ФИО партнера","ФИО менеджера","VK-ID","ID группы","Добавлен в группу"],"items": [["296260454","Lelechka18-05@mail.ru","Зарегистрировался самостоятельно","2023-02-13 22:20:42","2024-07-05 10:21:18","Ольга","Горшкова","79150408998","1988-05-18","36","Россия","Москва","","","PSYDM5_0","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","2993783","2023-09-03 12:19:08"],["315668856","julia20041986@mail.ru","Зарегистрировался самостоятельно","2023-05-25 16:05:43","2024-07-10 16:43:06","Юлия","Грищук","+79527936944","1986-11-13","38","Германия","Калининград ","","","","","","","","","","","","","","","","","","","","","","","https:\/\/webinar.riverpsy.com\/","telegram-bot","","","","","","","","","","","2993783","2023-09-03 12:19:08"],["316251009","elenakrylova9@gmail.com","Зарегистрировался самостоятельно","2023-05-29 13:26:11","2024-07-13 10:49:42","Елена","","+33614075834","","","Франция","","","","","","","","","","","","","","","","","","","","","","","","","telegram-channel","","","","","","","","","","","2993783","2023-09-03 12:19:08"],["323062565","Cboyak@mail.ru","Зарегистрировался самостоятельно","2023-07-05 11:08:11","2024-07-05 22:28:50","Старухина","Ксения","79872598129","","","Россия","","","","","","","","","","","","","","","","","","","","","","","","https:\/\/www.google.ru\/","google*","organic","","","","","","","","","20712833","2993783","2023-09-03 12:19:08"],["392646517","Skryabina.irina82@gmail.com","Приглашен администратором","2024-06-03 19:11:09","2024-07-10 13:54:45","Ирина","сотрудник","79124871139","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","2993783","2024-06-03 19:24:01"]]}}
26
-
27
-
28
-
29
-
30
-
31
  '''
32
 
33
-
34
-
35
-
36
  app = Flask(__name__, template_folder="./")
37
  app.config['DEBUG'] = True
38
  UPLOAD_FOLDER = 'static'
@@ -73,9 +75,65 @@ def init_db(db_name):
73
  for db in DATABASES:
74
  init_db(db)
75
 
 
 
 
 
 
 
 
 
76
 
 
 
77
 
 
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
 
81
 
 
4
  import random
5
  import requests
6
  import time
7
+ import re
8
+ import json
9
+ import base64
10
+ from unidecode import unidecode
11
 
12
+ api_key_sys = os.getenv('api_key_sys')
13
 
14
+ gc_api = os.getenv('gc_api') # Good
15
+ gc_url = os.getenv('gc_url_use')
16
 
17
+ gc_url_gru = os.getenv('gc_url_gru') # Good
18
+ gc_url_export = os.getenv('gc_url_export')
19
 
20
+ id_gru = os.getenv('id_gru')
21
+ # Дата
22
+ date_from = "2022-01-01"
 
 
23
 
24
+ # Статус
25
+ status = "active"
26
 
27
+ wa_url = os.getenv('wa_url')
28
+ wa_api_key = os.getenv('wa_api_key')
29
 
30
+ start_up = os.getenv('start_up')
31
 
32
+ export_id = ""
33
 
34
  json_data = '''
35
  {"success":true,"error_message":"","error":false,"info": {"fields":["id","Email","Тип регистрации","Создан","Последняя активность","Имя","Фамилия","Телефон","Дата рождения","Возраст","Страна","Город","От партнера","Руч продлен Клуба","Промокод","bonus_05_23","Клуб 255 - колл. оплат","Согласен с договором оферты и политикой конфиденциальности","Согласен на рассылку","vk_id","chat_id","ws_st","ws_stop","web_st","fin_prog","shop_st","curator","pr1","pr2","pr3","pr4","pr5","ad_url","Ответ сервера","Откуда пришел","utm_source","utm_medium","utm_campaign","utm_term","utm_content","utm_group","ID партнера","Email партнера","ФИО партнера","ФИО менеджера","VK-ID","ID группы","Добавлен в группу"],"items": [["296260454","Lelechka18-05@mail.ru","Зарегистрировался самостоятельно","2023-02-13 22:20:42","2024-07-05 10:21:18","Ольга","Горшкова","79150408998","1988-05-18","36","Россия","Москва","","","PSYDM5_0","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","2993783","2023-09-03 12:19:08"],["315668856","julia20041986@mail.ru","Зарегистрировался самостоятельно","2023-05-25 16:05:43","2024-07-10 16:43:06","Юлия","Грищук","+79527936944","1986-11-13","38","Германия","Калининград ","","","","","","","","","","","","","","","","","","","","","","","https:\/\/webinar.riverpsy.com\/","telegram-bot","","","","","","","","","","","2993783","2023-09-03 12:19:08"],["316251009","elenakrylova9@gmail.com","Зарегистрировался самостоятельно","2023-05-29 13:26:11","2024-07-13 10:49:42","Елена","","+33614075834","","","Франция","","","","","","","","","","","","","","","","","","","","","","","","","telegram-channel","","","","","","","","","","","2993783","2023-09-03 12:19:08"],["323062565","Cboyak@mail.ru","Зарегистрировался самостоятельно","2023-07-05 11:08:11","2024-07-05 22:28:50","Старухина","Ксения","79872598129","","","Россия","","","","","","","","","","","","","","","","","","","","","","","","https:\/\/www.google.ru\/","google*","organic","","","","","","","","","20712833","2993783","2023-09-03 12:19:08"],["392646517","Skryabina.irina82@gmail.com","Приглашен администратором","2024-06-03 19:11:09","2024-07-10 13:54:45","Ирина","сотрудник","79124871139","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","2993783","2024-06-03 19:24:01"]]}}
 
 
 
 
 
36
  '''
37
 
 
 
 
38
  app = Flask(__name__, template_folder="./")
39
  app.config['DEBUG'] = True
40
  UPLOAD_FOLDER = 'static'
 
75
  for db in DATABASES:
76
  init_db(db)
77
 
78
+ code_executed = False
79
+
80
+ # Переменная для хранения данных
81
+ export_data_var = None
82
+
83
+ def fetch(url):
84
+ response = requests.get(url)
85
+ return response.json()
86
 
87
+ def main():
88
+ global code_executed, export_data_var
89
 
90
+ print(f"start_up: {start_up}, code_executed: {code_executed}")
91
 
92
+ if start_up == '1' and not code_executed:
93
+ print("start_up равен '1' и код еще не выполнялся.")
94
+ # Формирование URL для первого запроса
95
+ url_template = f"{gc_url_gru}/{id_gru}/users?key={gc_api}&created_at[from]={date_from}&status={status}"
96
+ print(f"URL первого запроса: {url_template}")
97
+
98
+ # Отправка первого запроса к серверу
99
+ data = fetch(url_template)
100
+ print("Первый запрос отправлен.")
101
+
102
+ if data.get("success"):
103
+ export_id = data.get("info", {}).get("export_id", "")
104
+ print("Export ID:", export_id)
105
+
106
+ # Задержка в 5 минут перед вторым запросом (в секундах)
107
+ time_delay = 5 * 60
108
+ print(f"Ждем {time_delay} секунд перед вторым запросом...")
109
+ time.sleep(time_delay)
110
+
111
+ # Формирование URL для второго запроса по export_id
112
+ export_url_template = f"{gc_url_export}/{export_id}?key={gc_api}"
113
+ print(f"URL второго запроса: {export_url_template}")
114
+
115
+ # Отправка второго запроса к серверу по export_id
116
+ export_data = fetch(export_url_template)
117
+ print("Второй запрос отправлен.")
118
+
119
+ if export_data.get("success"):
120
+ print("Полученные данные по export_id:", export_data)
121
+
122
+ # Сохранение данных в переменную
123
+ export_data_var = export_data
124
+
125
+ # Пример использования переменной export_data_var
126
+ # Здесь вы можете выполнять любые операции с данными
127
+ print("Пример использования переменной export_data_var:")
128
+ print(export_data_var)
129
+
130
+ code_executed = True # Устанавливаем флаг выполнения кода
131
+ else:
132
+ print(f"Ошибка при выполнении второго запроса по export_id, статус код: {export_data.get('status_code')}")
133
+ else:
134
+ print("Ошибка в ответе от сервера:", data.get("error_message"))
135
+ else:
136
+ print("Системная переменная start_up не равна '1' или код уже выполнялся при старте сервера.")
137
 
138
 
139