yeref 0.24.29__py3-none-any.whl → 0.24.32__py3-none-any.whl

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.
yeref/yeref.py CHANGED
@@ -15511,7 +15511,7 @@ async def get_vars_web_main(chat_id, username, full_name, lc, is_premium, utm_we
15511
15511
  return is_paid, till_paid, lz
15512
15512
 
15513
15513
 
15514
- async def upd_user_data_main(data, web_app_init_data, BASE_P, BOT_TOKEN_E18B, req_url=''):
15514
+ async def upd_user_data_main(data, web_app_init_data, BASE_P, BOT_TOKEN_E18B, req_url='', utm=''):
15515
15515
  chat_id = int(web_app_init_data.get('user', {}).get('id'))
15516
15516
  username = web_app_init_data.get('user', {}).get('username', None)
15517
15517
  first_name = web_app_init_data.get('user', {}).get('first_name', '')
@@ -15570,10 +15570,12 @@ async def upd_user_data_main(data, web_app_init_data, BASE_P, BOT_TOKEN_E18B, re
15570
15570
  USER_VARS['USER_ISPREMIUM'] = is_premium
15571
15571
  lz = USER_VARS.get('USER_LZ', 'en')
15572
15572
 
15573
- if USER_VARS['USER_DT'] == '':
15573
+ print(f"before {USER_VARS=}")
15574
+ if not USER_VARS.get('USER_DT') and not USER_VARS.get('USER_UTM') and utm:
15575
+ USER_VARS['USER_UTM'] = utm
15576
+ if not USER_VARS.get('USER_DT'):
15574
15577
  USER_VARS['USER_DT'] = datetime.now(timezone.utc).strftime("%d-%m-%Y_%H-%M-%S")
15575
- # if utm != '':
15576
- # USER_VARS['USER_UTM'] = utm
15578
+ print(f"after {USER_VARS=}")
15577
15579
  # endregion
15578
15580
 
15579
15581
  # region tx
@@ -15814,6 +15816,117 @@ async def upd_user_data(ENT_TID, data, web_app_init_data, PROJECT_USERNAME, BASE
15814
15816
  # endregion
15815
15817
 
15816
15818
 
15819
+ # region unit ecomonics
15820
+ async def return_view_metrics(bot, PROJECT_USERNAME, EXTRA_D, BASE_P):
15821
+ try:
15822
+ schema_name = "USER"
15823
+ if PROJECT_USERNAME == 'FereyBotBot':
15824
+ schema_name = "BOT"
15825
+ elif PROJECT_USERNAME == 'FereyChannelBot':
15826
+ schema_name = "CHANNEL"
15827
+ elif PROJECT_USERNAME == 'FereyGroupBot':
15828
+ schema_name = "GROUPP"
15829
+
15830
+ sql = f"SELECT {schema_name}_TID FROM \"{schema_name}\""
15831
+ data_ents = await db_select_pg(sql, (), BASE_P)
15832
+
15833
+ metrics_by_month = defaultdict(lambda: {
15834
+ "dau": 0,
15835
+ "mau": 0,
15836
+ "wallets": 0,
15837
+ "tx": 0,
15838
+ "tvl": 0,
15839
+ "/start": 0,
15840
+ "/startapp": 0
15841
+ })
15842
+ seen_mau = set()
15843
+ seen_dau = set()
15844
+ wallets_set = set()
15845
+ users_set = set()
15846
+
15847
+ def process_user_rows(rows):
15848
+ for USER_TID, USER_VARS, USER_LSTS in rows:
15849
+ USER_VARS = json.loads(USER_VARS or "{}")
15850
+ USER_LSTS = json.loads(USER_LSTS or "{}")
15851
+ USER_WALLET = USER_VARS.get('USER_WALLET', '')
15852
+ USER_UTM = USER_VARS.get('USER_UTM', '')
15853
+ USER_DT = USER_VARS.get('USER_DT', '')
15854
+ USER_DAU = USER_LSTS.get("USER_DAU", [])
15855
+ USER_MAU = USER_LSTS.get("USER_MAU", [])
15856
+ USER_TXS = USER_LSTS.get("USER_TXS", [])
15857
+
15858
+ if USER_WALLET: wallets_set.add(USER_WALLET)
15859
+ users_set.add(USER_TID)
15860
+
15861
+ for day_str in USER_DAU:
15862
+ dt_day = datetime.strptime(day_str, "%Y-%m-%d")
15863
+ month_key = dt_day.strftime("%Y-%m")
15864
+ if (USER_TID, month_key) not in seen_dau:
15865
+ seen_dau.add((USER_TID, month_key))
15866
+ metrics_by_month[month_key]["dau"] += 1
15867
+
15868
+ for mo_str in USER_MAU:
15869
+ dt_m = datetime.strptime(mo_str + "-01", "%Y-%m-%d")
15870
+ month_key = dt_m.strftime("%Y-%m")
15871
+ if (USER_TID, month_key) not in seen_mau:
15872
+ seen_mau.add((USER_TID, month_key))
15873
+ metrics_by_month[month_key]["mau"] += 1
15874
+ if USER_WALLET:
15875
+ metrics_by_month[month_key]["wallets"] += 1
15876
+
15877
+ for tx in USER_TXS:
15878
+ dt_start = tx.get("DT_START", "")
15879
+ amount = int(tx.get("AMOUNT", "0"))
15880
+ dt_tx = datetime.strptime(dt_start, "%d-%m-%Y_%H-%M-%S")
15881
+ month_key = dt_tx.strftime("%Y-%m")
15882
+ metrics_by_month[month_key]["tx"] += 1
15883
+ metrics_by_month[month_key]["tvl"] += amount
15884
+
15885
+ if USER_DT:
15886
+ dt_obj = datetime.strptime(USER_DT, "%d-%m-%Y_%H-%M-%S")
15887
+ month_key = dt_obj.strftime("%Y-%m")
15888
+ key = "/startapp" if USER_UTM == "/startapp" else "/start"
15889
+ metrics_by_month[month_key][key] += 1
15890
+
15891
+ for item in data_ents:
15892
+ ENT_TID = item[0]
15893
+ sql = f'SELECT USER_TID, USER_VARS, USER_LSTS FROM {schema_name}_{ENT_TID}.USER'
15894
+ data_users = await db_select_pg(sql, (), BASE_P)
15895
+ process_user_rows(data_users)
15896
+
15897
+ sql = f"SELECT USER_TID, USER_VARS, USER_LSTS FROM \"USER\""
15898
+ data_users = await db_select_pg(sql, (), BASE_P)
15899
+ process_user_rows(data_users)
15900
+
15901
+ all_months = sorted(metrics_by_month.keys())
15902
+ f_name = os.path.join(EXTRA_D, "1_metrics.csv")
15903
+ with open(f_name, mode="w", encoding="utf-8", newline="") as csvfile:
15904
+ writer = csv.writer(csvfile, delimiter=',')
15905
+ writer.writerow(["MO", "DAU", "MAU", "Wallets", "Transactions", "TVL", "/start", "/startapp"])
15906
+ for ym in all_months:
15907
+ row = [
15908
+ ym,
15909
+ metrics_by_month[ym]["dau"],
15910
+ metrics_by_month[ym]["mau"],
15911
+ metrics_by_month[ym]["wallets"],
15912
+ metrics_by_month[ym]["tx"],
15913
+ "",
15914
+ metrics_by_month[ym]["/start"],
15915
+ metrics_by_month[ym]["/startapp"],
15916
+ ]
15917
+ writer.writerow(row)
15918
+ f.write("\n")
15919
+ f.write(f"Unique wallet count: {len(wallets_set)}\n")
15920
+ f.write(f"Unique users count: {len(users_set)}\n")
15921
+
15922
+ thumb = types.FSInputFile(os.path.join(EXTRA_D, 'parse.jpg'))
15923
+ await bot.send_document(chat_id=my_tid, document=types.FSInputFile(f_name), thumbnail=thumb)
15924
+ except Exception as e:
15925
+ logger.info(log_ % str(e))
15926
+ await asyncio.sleep(round(random.uniform(0, 1), 2))
15927
+ # endregion
15928
+
15929
+
15817
15930
  # region pst
15818
15931
  async def ch_games(USER_GAMES, game, condition, balls=-1):
15819
15932
  try:
@@ -15982,7 +16095,7 @@ async def post_save(bot, data_user, data_web, MEDIA_D, BASE_P, KEYS_JSON, PROJEC
15982
16095
  print(f"--------------------------------------------------------")
15983
16096
  print(f"after {POST_MEDIA=}")
15984
16097
 
15985
- if PROJECT_USERNAME == 'FereyPostBot' and POST_TYPE in ['voice', 'audio'] and 'filev_id' not in POST_MEDIA[0]:
16098
+ if PROJECT_USERNAME == 'FereyPostBot' and POST_TYPE in ['voice', 'audio'] and len(POST_MEDIA) == 1 and 'filev_id' not in POST_MEDIA[0]:
15986
16099
  asyncio.create_task(convert_to_vinyl(bot, chat_id, ENT_TID, POST_TID, MEDIA_D, EXTRA_D, POST_MEDIA, BASE_P))
15987
16100
 
15988
16101
  # region pay
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.24.29
3
+ Version: 0.24.32
4
4
  Summary: desc-f
5
5
  Author: john smith
6
6
  Dynamic: author
@@ -0,0 +1,8 @@
1
+ yeref/__init__.py,sha256=Qpv3o6Xa78VdLcsSRmctGtpnYE9btpAkCekgGhgJyXM,49
2
+ yeref/l_.py,sha256=LMX_olmJwq-tgoALJCnhV_fGrL_i_43yBLkLIcEVqGo,1176743
3
+ yeref/tonweb.js,sha256=Jf6aFOQ1OIY4q7fINYz-m5LsI3seMus124M5SYYZmtE,443659
4
+ yeref/yeref.py,sha256=4-MPeYeY_tGffgs27L5-p17A05-o-23XPZjgK_r_tTs,1026521
5
+ yeref-0.24.32.dist-info/METADATA,sha256=3XWVL0VpNNaZCK47VF0sZWRukFrE5WD4Owj2jQNEwIw,119
6
+ yeref-0.24.32.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ yeref-0.24.32.dist-info/top_level.txt,sha256=yCQKchWHbfV-3OuQPYRdi2loypD-nmbDJbtt3OuKKkY,6
8
+ yeref-0.24.32.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- yeref/__init__.py,sha256=Qpv3o6Xa78VdLcsSRmctGtpnYE9btpAkCekgGhgJyXM,49
2
- yeref/l_.py,sha256=LMX_olmJwq-tgoALJCnhV_fGrL_i_43yBLkLIcEVqGo,1176743
3
- yeref/tonweb.js,sha256=Jf6aFOQ1OIY4q7fINYz-m5LsI3seMus124M5SYYZmtE,443659
4
- yeref/yeref.py,sha256=gBDcnH3mwyStCrtRCu6UiWjyMWRN4DXzH3SJ1BEev10,1021632
5
- yeref-0.24.29.dist-info/METADATA,sha256=1KyJakayLd9pWD9VdCi6y0U__hVwzGpIwNNLUa_ZT48,119
6
- yeref-0.24.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- yeref-0.24.29.dist-info/top_level.txt,sha256=yCQKchWHbfV-3OuQPYRdi2loypD-nmbDJbtt3OuKKkY,6
8
- yeref-0.24.29.dist-info/RECORD,,