yeref 0.24.94__tar.gz → 0.24.96__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.24.94
3
+ Version: 0.24.96
4
4
  Summary: desc-f
5
5
  Author: john smith
6
6
  Dynamic: author
@@ -2,7 +2,7 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='yeref',
5
- version='0.24.94',
5
+ version='0.24.96',
6
6
  description='desc-f',
7
7
  author='john smith',
8
8
  packages=['yeref'],
@@ -15926,7 +15926,7 @@ async def upd_user_data(ENT_TID, data, web_app_init_data, PROJECT_USERNAME, BASE
15926
15926
 
15927
15927
 
15928
15928
  # region unit ecomonics
15929
- async def calc_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
15929
+ async def calc_metrics(bot, PROJECT_USERNAME, dataroom_folder_id, EXTRA_D, BASE_P, CONF_P):
15930
15930
  try:
15931
15931
  schema_name = "USER"
15932
15932
  if PROJECT_USERNAME == 'FereyBotBot':
@@ -16010,6 +16010,71 @@ async def calc_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
16010
16010
  r3 = await return_cohort_metrics(bot, data_users, EXTRA_D)
16011
16011
  r4 = await return_retention_metrics(bot, data_users, EXTRA_D)
16012
16012
  r5 = await return_profit_and_loss_metrics(bot, data_users, EXTRA_D)
16013
+
16014
+ # === НОВЫЙ БЛОК: читаем CSV (r1) и заливаем его в Google‐таблицу ===
16015
+ if r1 and os.path.isfile(r1):
16016
+ # 1) Авторизация в Google Sheets через Service Account
16017
+ scopes = r_conf('scopes', CONF_P)
16018
+ credential_path = os.path.join(EXTRA_D, (r_conf('credential_file', CONF_P))[0])
16019
+ credentials = ServiceAccountCredentials.from_json_keyfile_name(credential_path, scopes)
16020
+ http_auth = credentials.authorize(httplib2.Http())
16021
+ sheets_service = build('sheets', 'v4', http=http_auth, cache_discovery=False)
16022
+
16023
+ # 2) Получаем metadata таблицы, чтобы найти sheetId для «Лист1» (или «Sheet1»)
16024
+ spreadsheet = sheets_service.spreadsheets().get(spreadsheetId=dataroom_folder_id).execute()
16025
+ sheet_id_to_rename = None
16026
+ for sheet in spreadsheet.get('sheets', []):
16027
+ props = sheet.get('properties', {})
16028
+ title = props.get('title', '')
16029
+ # если лист называется «Лист1» (русский по умолчанию) или «Sheet1» (английский)
16030
+ if title in ['Лист1', 'Sheet1']:
16031
+ sheet_id_to_rename = props.get('sheetId')
16032
+ break
16033
+
16034
+ # 3) Переименовываем лист в PROJECT_USERNAME, если нашли нужный sheetId
16035
+ if sheet_id_to_rename is not None:
16036
+ rename_request = {
16037
+ 'requests': [
16038
+ {
16039
+ 'updateSheetProperties': {
16040
+ 'properties': {
16041
+ 'sheetId': sheet_id_to_rename,
16042
+ 'title': PROJECT_USERNAME
16043
+ },
16044
+ 'fields': 'title'
16045
+ }
16046
+ }
16047
+ ]
16048
+ }
16049
+ sheets_service.spreadsheets().batchUpdate(
16050
+ spreadsheetId=dataroom_folder_id,
16051
+ body=rename_request
16052
+ ).execute()
16053
+
16054
+ # 4) Читаем CSV-файл (r1) целиком и собираем список строк
16055
+ with open(r1, newline='', encoding='utf-8') as csvfile:
16056
+ reader = csv.reader(csvfile)
16057
+ all_rows = list(reader)
16058
+
16059
+ # 5) Пишем значения из all_rows в только что переименованный лист (PROJECT_USERNAME), начиная с A1
16060
+ write_body = {
16061
+ 'valueInputOption': 'USER_ENTERED',
16062
+ 'data': [
16063
+ {
16064
+ 'range': f"{PROJECT_USERNAME}!A1",
16065
+ 'majorDimension': 'ROWS',
16066
+ 'values': all_rows
16067
+ }
16068
+ ]
16069
+ }
16070
+ sheets_service.spreadsheets().values().batchUpdate(
16071
+ spreadsheetId=dataroom_folder_id,
16072
+ body=write_body
16073
+ ).execute()
16074
+ logger.info("Activity‐метрики (r1) успешно загружены в Google‐таблицу.")
16075
+ else:
16076
+ logger.warning(f"Файл с метриками не найден или не существует: {r1}")
16077
+
16013
16078
  except Exception as e:
16014
16079
  logger.info(log_ % str(e))
16015
16080
  await asyncio.sleep(round(random.uniform(0, 1), 2))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.24.94
3
+ Version: 0.24.96
4
4
  Summary: desc-f
5
5
  Author: john smith
6
6
  Dynamic: author
File without changes
File without changes
File without changes
File without changes
File without changes