yeref 0.29.26__tar.gz → 0.29.28__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.29.26
3
+ Version: 0.29.28
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.29.26',
5
+ version='0.29.28',
6
6
  description='desc-f',
7
7
  author='john smith',
8
8
  packages=['yeref'],
@@ -7740,98 +7740,6 @@ async def check_webapp_hash(init_data, TOKEN_BOT, BOT_TOKEN_MAIN=None, extra=Non
7740
7740
  return result
7741
7741
 
7742
7742
 
7743
- async def get_vars_web_main(chat_id, username, full_name, lc, is_premium, utm_web, BASE_P, BOT_TOKEN_E18B):
7744
- is_paid = False
7745
- till_paid = ''
7746
- lz = 'en'
7747
- try:
7748
- dt = lz = utm = None
7749
- pays = []
7750
-
7751
- sql = "SELECT USER_TID, USER_LZ, USER_DT, USER_UTM, USER_PAY FROM \"USER\" WHERE USER_TID=$1"
7752
- data_user = await db_select_pg(sql, (chat_id,), BASE_P)
7753
- if len(data_user): USER_TID, lz, dt, utm, pays = data_user[0]
7754
-
7755
- if not dt:
7756
- dt = datetime.now(timezone.utc).strftime('%d-%m-%Y_%H-%M-%S')
7757
- if not utm:
7758
- utm = utm_web
7759
- if not lz:
7760
- if lc in ['zh', 'zh-chs', 'zh-cht', 'ja', 'ko', 'zh-CN', 'zh-TW', 'th', 'vi', 'tw', 'sg']:
7761
- lz = 'zh'
7762
- # arabic # ir, af
7763
- elif lc in ['ar-XA', 'ar', 'tr', 'ur', 'fa', 'tj', 'dz', 'eg', 'iq', 'sy', 'ae', 'sa', 'tn', 'ir', 'af']:
7764
- lz = 'ar'
7765
- # spanish # portugal: 'pt', 'br', 'ao', 'mz'
7766
- elif lc in ['es', 'ar', 'cl', 'co', 'cu', 've', 'bo', 'pe', 'ec', 'pt', 'br', 'ao', 'mz']:
7767
- lz = 'es'
7768
- # french
7769
- elif lc in ['fr', 'ch', 'be', 'ca']:
7770
- lz = 'fr'
7771
- # europe
7772
- elif lc in ['ru', 'kz', 'kg', 'uz', 'tm', 'md', 'am', 'uk-UA', 'uk', 'kk', 'tk', 'ky']:
7773
- lz = 'ru'
7774
- else:
7775
- lz = 'en'
7776
-
7777
- if utm_web not in ['@FereyPostBot', '']:
7778
- sql = """
7779
- INSERT INTO "USER" (USER_TID, USER_USERNAME, USER_FULLNAME, USER_LZ, USER_LC, USER_UTM, USER_ISPREMIUM, USER_DT)
7780
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
7781
- ON CONFLICT (USER_TID)
7782
- DO UPDATE SET
7783
- USER_USERNAME = EXCLUDED.USER_USERNAME,
7784
- USER_FULLNAME = EXCLUDED.USER_FULLNAME,
7785
- USER_LZ = EXCLUDED.USER_LZ,
7786
- USER_LC = EXCLUDED.USER_LC,
7787
- USER_UTM = EXCLUDED.USER_UTM,
7788
- USER_ISPREMIUM = EXCLUDED.USER_ISPREMIUM,
7789
- USER_DT = EXCLUDED.USER_DT
7790
- """
7791
- await db_change_pg(sql, (chat_id, username, full_name, lz, lc, utm, is_premium, dt,), BASE_P)
7792
-
7793
- try:
7794
- print(f"{pays=}")
7795
- if not pays: pays = '[]'
7796
- pays = json.loads(pays)
7797
- except Exception as e:
7798
- logger.info(log_ % str(e))
7799
- pays = []
7800
-
7801
- print(f"{pays=}")
7802
- for pay in pays:
7803
- try:
7804
- if not (pay.get('TYPE', '') == 'SUB' and pay.get('DT_END', '')): continue
7805
- DT_END = datetime.strptime(pay.get('DT_END'), '%d-%m-%Y_%H-%M-%S').replace(tzinfo=timezone.utc)
7806
- print(f"{DT_END=}")
7807
- if datetime.now(timezone.utc) <= DT_END:
7808
- is_paid = True
7809
- till_paid = DT_END.strftime('%d.%m.%Y')
7810
- except Exception as e:
7811
- logger.info(log_ % str(e))
7812
- pass
7813
-
7814
- if not is_paid:
7815
- extra_bot = None
7816
- try:
7817
- lib_id = channel_library_ru if lz == 'ru' else channel_library_en
7818
- print(f"{channel_library_ru=}, {channel_library_en=}")
7819
- extra_bot = Bot(token=BOT_TOKEN_E18B)
7820
- member_ = await extra_bot.get_chat_member(chat_id=lib_id, user_id=chat_id)
7821
- if member_.status in ['member', 'administrator', 'creator']: is_paid = True
7822
- except Exception as e:
7823
- logger.info(log_ % str(e))
7824
- finally:
7825
- if extra_bot: await extra_bot.session.close()
7826
- except TelegramRetryAfter as e:
7827
- logger.info(log_ % f"TelegramRetryAfter {e.retry_after}")
7828
- await asyncio.sleep(e.retry_after + 1)
7829
- except Exception as e:
7830
- logger.info(log_ % str(e))
7831
- await asyncio.sleep(round(random.uniform(0, 1), 2))
7832
- return is_paid, till_paid, lz
7833
-
7834
-
7835
7743
  async def upd_user_data_main(data, web_app_init_data, BASE_P, BOT_TOKEN_E18B, req_url='', utm=''):
7836
7744
  chat_id = int(web_app_init_data.get('user', {}).get('id'))
7837
7745
  username = web_app_init_data.get('user', {}).get('username', None)
@@ -7845,7 +7753,7 @@ async def upd_user_data_main(data, web_app_init_data, BASE_P, BOT_TOKEN_E18B, re
7845
7753
  page = data.get('page', '')
7846
7754
  connectedAddress = data.get('connectedAddress', '')
7847
7755
  USER_TID = chat_id
7848
- USER_HID = USER_LZ = USER_DT = None
7756
+ USER_HID = USER_LZ = None
7849
7757
  USER_VARS = json.loads(USER_VARS_)
7850
7758
  USER_LSTS = json.loads(USER_LSTS_)
7851
7759
  USER_GAMES = {}
@@ -7885,8 +7793,8 @@ async def upd_user_data_main(data, web_app_init_data, BASE_P, BOT_TOKEN_E18B, re
7885
7793
  elif lc in ['ru', 'kz', 'kg', 'uz', 'tm', 'md', 'am', 'uk-UA', 'uk', 'kk', 'tk', 'ky']:
7886
7794
  lz = 'ru'
7887
7795
  USER_LZ = lz
7888
- if not USER_DT:
7889
- USER_VARS['USER_DT'] = USER_DT = datetime.now(timezone.utc).strftime("%d-%m-%Y_%H-%M-%S")
7796
+ if not USER_VARS.get('USER_DT', None):
7797
+ USER_VARS['USER_DT'] = USER_DT.strftime("%d-%m-%Y_%H-%M-%S")
7890
7798
  USER_HID = hashlib.blake2b(f"{'tid'}-{chat_id}".encode('utf-8'), digest_size=4).hexdigest()
7891
7799
  if utm: USER_VARS['USER_UTM'] = utm
7892
7800
 
@@ -7954,9 +7862,9 @@ async def upd_user_data_main(data, web_app_init_data, BASE_P, BOT_TOKEN_E18B, re
7954
7862
  sql = f"""
7955
7863
  INSERT INTO \"USER\" (
7956
7864
  USER_TID, USER_HID, USER_USERNAME, USER_FULLNAME, USER_ISPREMIUM,
7957
- USER_LZ, USER_DT, USER_GAMES, USER_VARS, USER_LSTS
7865
+ USER_LZ, USER_GAMES, USER_VARS, USER_LSTS
7958
7866
  )
7959
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
7867
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
7960
7868
  ON CONFLICT (USER_TID) DO UPDATE
7961
7869
  SET
7962
7870
  USER_HID = EXCLUDED.USER_HID,
@@ -7964,13 +7872,12 @@ async def upd_user_data_main(data, web_app_init_data, BASE_P, BOT_TOKEN_E18B, re
7964
7872
  USER_FULLNAME = EXCLUDED.USER_FULLNAME,
7965
7873
  USER_ISPREMIUM = EXCLUDED.USER_ISPREMIUM,
7966
7874
  USER_LZ = EXCLUDED.USER_LZ,
7967
- USER_DT = EXCLUDED.USER_DT,
7968
7875
 
7969
7876
  USER_GAMES = EXCLUDED.USER_GAMES,
7970
7877
  USER_VARS = EXCLUDED.USER_VARS,
7971
7878
  USER_LSTS = EXCLUDED.USER_LSTS
7972
7879
  """
7973
- await db_change_pg(sql, (USER_TID, USER_HID, username, full_name, is_premium, USER_LZ, USER_DT,
7880
+ await db_change_pg(sql, (USER_TID, USER_HID, username, full_name, is_premium, USER_LZ,
7974
7881
  json.dumps(USER_GAMES, ensure_ascii=False),
7975
7882
  json.dumps(USER_VARS, ensure_ascii=False),
7976
7883
  json.dumps(USER_LSTS, ensure_ascii=False),), BASE_P)
@@ -7994,7 +7901,7 @@ async def upd_user_data(ENT_TID, data, web_app_init_data, PROJECT_USERNAME, BASE
7994
7901
  page = data.get('page', '')
7995
7902
  connectedAddress = data.get('connectedAddress', '')
7996
7903
  USER_TID = chat_id
7997
- USER_HID = USER_LZ = USER_DT = None
7904
+ USER_HID = USER_LZ = None
7998
7905
  USER_VARS = json.loads(USER_VARS_)
7999
7906
  USER_LSTS = json.loads(USER_LSTS_)
8000
7907
  USER_GAMES = {}
@@ -8043,7 +7950,8 @@ async def upd_user_data(ENT_TID, data, web_app_init_data, PROJECT_USERNAME, BASE
8043
7950
  elif lc in ['ru', 'kz', 'kg', 'uz', 'tm', 'md', 'am', 'uk-UA', 'uk', 'kk', 'tk', 'ky']:
8044
7951
  lz = 'ru'
8045
7952
  USER_LZ = lz
8046
- if not USER_DT: USER_VARS['USER_DT'] = USER_DT = datetime.now(timezone.utc).strftime("%d-%m-%Y_%H-%M-%S")
7953
+ if not USER_VARS.get('USER_DT', None):
7954
+ USER_VARS['USER_DT'] = USER_DT.strftime("%d-%m-%Y_%H-%M-%S")
8047
7955
  if not USER_HID: USER_HID = hashlib.blake2b(f"{tid}-{chat_id}".encode('utf-8'), digest_size=4).hexdigest()
8048
7956
 
8049
7957
  now = datetime.now(timezone.utc)
@@ -8080,9 +7988,9 @@ async def upd_user_data(ENT_TID, data, web_app_init_data, PROJECT_USERNAME, BASE
8080
7988
  sql = f"""
8081
7989
  INSERT INTO {schema_name}_{tid}.USER (
8082
7990
  USER_TID, USER_HID, USER_USERNAME, USER_FULLNAME, USER_ISPREMIUM,
8083
- USER_LZ, USER_DT, USER_GAMES, USER_VARS, USER_LSTS
7991
+ USER_LZ, USER_GAMES, USER_VARS, USER_LSTS
8084
7992
  )
8085
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
7993
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
8086
7994
  ON CONFLICT (USER_TID) DO UPDATE
8087
7995
  SET
8088
7996
  USER_HID = EXCLUDED.USER_HID,
@@ -8090,13 +7998,12 @@ async def upd_user_data(ENT_TID, data, web_app_init_data, PROJECT_USERNAME, BASE
8090
7998
  USER_FULLNAME = EXCLUDED.USER_FULLNAME,
8091
7999
  USER_ISPREMIUM = EXCLUDED.USER_ISPREMIUM,
8092
8000
  USER_LZ = EXCLUDED.USER_LZ,
8093
- USER_DT = EXCLUDED.USER_DT,
8094
8001
 
8095
8002
  USER_GAMES = EXCLUDED.USER_GAMES,
8096
8003
  USER_VARS = EXCLUDED.USER_VARS,
8097
8004
  USER_LSTS = EXCLUDED.USER_LSTS
8098
8005
  """
8099
- await db_change_pg(sql, (USER_TID, USER_HID, username, full_name, is_premium, USER_LZ, USER_DT,
8006
+ await db_change_pg(sql, (USER_TID, USER_HID, username, full_name, is_premium, USER_LZ,
8100
8007
  json.dumps(USER_GAMES, ensure_ascii=False),
8101
8008
  json.dumps(USER_VARS, ensure_ascii=False),
8102
8009
  json.dumps(USER_LSTS, ensure_ascii=False),), BASE_P)
@@ -8179,53 +8086,6 @@ async def is_subscription_expired(USER_VARS, USER_LSTS):
8179
8086
 
8180
8087
 
8181
8088
  # region pay
8182
- async def update_subscribe(bot, BASE_P, BOT_TOKEN_E18B):
8183
- result = []
8184
- try:
8185
- dt_ = datetime.now(timezone.utc)
8186
- if not (dt_.hour % 2 == 0 and dt_.minute % 2 == 0 and dt_.second % 2 == 0): return result
8187
- sql = "SELECT USER_TID, USER_LZ, USER_DTPAID, USER_ISPAID FROM USER"
8188
- data = await db_select_pg(sql, (), BASE_P)
8189
-
8190
- for item in data:
8191
- try:
8192
- USER_TID, USER_LZ, USER_DTPAID, USER_ISPAID = item
8193
- dtpt_ = datetime.strptime(USER_DTPAID, '%d-%m-%Y_%H-%M-%S').replace(tzinfo=timezone.utc)
8194
-
8195
- if USER_ISPAID == 1 and USER_DTPAID and (dt_ - dtpt_).days > 31:
8196
- await asyncio.sleep(round(random.uniform(0, 1), 2))
8197
- get_ = await bot.get_chat(chat_id=USER_TID)
8198
- chan_private_donate = channel_library_ru if USER_LZ == 'ru' else channel_library_en
8199
- extra_bot = Bot(token=BOT_TOKEN_E18B)
8200
- get_chat_member_ = await extra_bot.get_chat_member(chat_id=chan_private_donate, user_id=USER_TID)
8201
- await extra_bot.session.close()
8202
-
8203
- if get_chat_member_.status in ['member', 'administrator', 'creator']:
8204
- USER_DTPAID = datetime.now(timezone.utc).strftime('%d-%m-%Y_%H-%M-%S')
8205
- sql = "UPDATE USER SET USER_ISPAID=1, USER_USERNAME=$1, USER_FULLNAME=$2, USER_DTPAID=$3 " \
8206
- "WHERE USER_TID=$4"
8207
- await db_change_pg(sql, (get_.username, get_.full_name, USER_DTPAID, USER_TID,), BASE_P)
8208
- else:
8209
- sql = "UPDATE USER SET USER_ISPAID=0, USER_USERNAME=$1, USER_FULLNAME=$2 WHERE USER_TID=$3"
8210
- await db_change_pg(sql, (get_.username, get_.full_name, USER_TID,), BASE_P)
8211
- elif USER_ISPAID == -1 and USER_DTPAID and (dt_ - dtpt_).days > 31:
8212
- result.append(
8213
- item) # else: # sql = "UPDATE USER SET USER_USERNAME=$1, USER_FULLNAME=$2 WHERE USER_TID=$3" # await db_change_pg(sql, (get_.username, get_.full_name, USER_TID,), BASE_P)
8214
- except TelegramRetryAfter as e:
8215
- logger.info(log_ % f"TelegramRetryAfter {e.retry_after}")
8216
- await asyncio.sleep(e.retry_after + 1)
8217
- except Exception as e:
8218
- logger.info(log_ % str(e))
8219
- await asyncio.sleep(round(random.uniform(0, 1), 2))
8220
- except TelegramRetryAfter as e:
8221
- logger.info(log_ % f"TelegramRetryAfter {e.retry_after}")
8222
- await asyncio.sleep(e.retry_after + 1)
8223
- except Exception as e:
8224
- logger.info(log_ % str(e))
8225
- await asyncio.sleep(round(random.uniform(0, 1), 2))
8226
- return result
8227
-
8228
-
8229
8089
  async def convert_domain_to_currency(domain):
8230
8090
  result = 'EUR'
8231
8091
  try:
@@ -8461,62 +8321,6 @@ async def create_invoice_link_my(BOT_TID, BOT_LC, msg_text, msg_btns, POST_LNK,
8461
8321
  return result
8462
8322
 
8463
8323
 
8464
- async def check_sub_pay(chat_id, lz, BOT_TOKEN_E18B, BASE_P):
8465
- is_paid = False
8466
- till_paid = ''
8467
- try:
8468
- USER_ISPAID = 0
8469
- USER_DTPAID = ''
8470
- dt_now = datetime.now(timezone.utc)
8471
- USER_DT = dt_now.strftime('%d-%m-%Y_%H-%M-%S')
8472
- extra_bot = None
8473
- try:
8474
- lib_id = channel_library_ru if lz == 'ru' else channel_library_en
8475
- extra_bot = Bot(token=BOT_TOKEN_E18B)
8476
- member_ = await extra_bot.get_chat_member(chat_id=lib_id, user_id=chat_id)
8477
- if member_.status in ['member', 'administrator', 'creator']: is_paid = True
8478
- print(f"check_sub_pay {is_paid=}")
8479
- except Exception as e:
8480
- logger.info(log_ % str(e))
8481
- finally:
8482
- if extra_bot: await extra_bot.session.close()
8483
-
8484
- sql = "SELECT USER_ISPAID, USER_DTPAID, USER_TYPAID, USER_DT, USER_LZ FROM USER WHERE USER_TID=$1"
8485
- data_usr = await db_select_pg(sql, (chat_id,), BASE_P)
8486
-
8487
- if not len(data_usr):
8488
- sql = "INSERT INTO USER (USER_TID, USER_DT) VALUES ($1, $2) ON CONFLICT DO NOTHING"
8489
- await db_change_pg(sql, (chat_id, USER_DT,), BASE_P)
8490
- else:
8491
- USER_ISPAID, USER_DTPAID, USER_TYPAID, USER_DT, lz = data_usr[0]
8492
-
8493
- if is_paid:
8494
- sql = "UPDATE USER SET USER_ISPAID=1, USER_DTPAID='', USER_TYPAID='all' WHERE USER_TID=$1"
8495
- await db_change_pg(sql, (chat_id,), BASE_P)
8496
- elif USER_ISPAID and USER_DTPAID:
8497
- till_paid = dt_now.strptime(USER_DTPAID, "%d-%m-%Y_%H-%M-%S").replace(tzinfo=timezone.utc)
8498
- print(f"{till_paid=}")
8499
-
8500
- if dt_now > till_paid:
8501
- sql = "UPDATE USER SET USER_ISPAID=0, USER_DTPAID='', USER_TYPAID='' WHERE USER_TID=$1"
8502
- await db_change_pg(sql, (chat_id,), BASE_P)
8503
- till_paid = ''
8504
- else:
8505
- is_paid = True
8506
- till_paid = till_paid.strftime('%d.%m.%Y')
8507
- else:
8508
- sql = "UPDATE USER SET USER_ISPAID=0, USER_DTPAID='', USER_TYPAID='' WHERE USER_TID=$1"
8509
- await db_change_pg(sql, (chat_id,), BASE_P)
8510
- print(f"check_sub_pay {is_paid=}, {till_paid=}")
8511
- except TelegramRetryAfter as e:
8512
- logger.info(log_ % f"TelegramRetryAfter {e.retry_after}")
8513
- await asyncio.sleep(e.retry_after + 1)
8514
- except Exception as e:
8515
- logger.info(log_ % str(e))
8516
- await asyncio.sleep(round(random.uniform(0, 1), 2))
8517
- return is_paid, till_paid
8518
-
8519
-
8520
8324
  async def pay_handler_for_all(bot, message, ideas_en, ideas_ru, PROJECT_USERNAME, EXTRA_D, BASE_P):
8521
8325
  try:
8522
8326
  successful_payment_data = {k: v for k, v in message.successful_payment.model_dump().items() if v is not None}
@@ -8553,8 +8357,8 @@ async def pay_handler_for_all(bot, message, ideas_en, ideas_ru, PROJECT_USERNAME
8553
8357
  data_usr = await db_select_pg(sql, (chat_id,), BASE_P)
8554
8358
  if not len(data_usr):
8555
8359
  dt_ = datetime.now(timezone.utc).strftime('%d-%m-%Y_%H-%M-%S')
8556
- sql = "INSERT INTO \"USER\" (USER_TID, USER_DT) VALUES ($1, $2) ON CONFLICT DO NOTHING"
8557
- await db_change_pg(sql, (chat_id, dt_,), BASE_P)
8360
+ sql = "INSERT INTO \"USER\" (USER_TID) VALUES ($1) ON CONFLICT DO NOTHING"
8361
+ await db_change_pg(sql, (chat_id,), BASE_P)
8558
8362
  USER_LSTS = json.loads(USER_LSTS_)
8559
8363
  USER_VARS = json.loads(USER_VARS_)
8560
8364
  if payload == 'gift': USER_VARS['USER_UTM'] = 'gift'
@@ -8902,6 +8706,7 @@ async def calc_metrics(bot, PROJECT_USERNAME, dataroom_folder_id, EXTRA_D, BASE_
8902
8706
 
8903
8707
  data_users.append((
8904
8708
  random.randint(100000, 999999),
8709
+ entry_dt_obj,
8905
8710
  json.dumps({"USER_WALLET": wallet, "USER_UTM": utm, "USER_DT": entry_dt}),
8906
8711
  json.dumps({"USER_DAU": user_dau, "USER_MAU": user_mau, "USER_TXS": txs,
8907
8712
  "USER_PAYMENTS": payments, "USER_STATUSES": USER_STATUSES})
@@ -9033,7 +8838,6 @@ async def return_activity_metrics(bot, data_users, EXTRA_D, BASE_P, data_ents, s
9033
8838
  USER_LSTS = json.loads(USER_LSTS or "{}")
9034
8839
  USER_WALLET = USER_VARS.get('USER_WALLET', '')
9035
8840
  USER_UTM = USER_VARS.get('USER_UTM', '')
9036
- USER_DT = USER_VARS.get('USER_DT', '')
9037
8841
  USER_DAU = USER_LSTS.get("USER_DAU", [])
9038
8842
  USER_MAU = USER_LSTS.get("USER_MAU", [])
9039
8843
  USER_TXS = USER_LSTS.get("USER_TXS", [])
@@ -9077,11 +8881,9 @@ async def return_activity_metrics(bot, data_users, EXTRA_D, BASE_P, data_ents, s
9077
8881
  month_key = dt_tx.strftime("%Y-%m")
9078
8882
  metrics_by_month[month_key]["pay"] += 1
9079
8883
 
9080
- if USER_DT:
9081
- dt_obj = datetime.strptime(USER_DT, "%d-%m-%Y_%H-%M-%S")
9082
- month_key = dt_obj.strftime("%Y-%m")
9083
- key = "/startapp" if USER_UTM == "/startapp" else "/start"
9084
- metrics_by_month[month_key][key] += 1
8884
+ month_key = USER_DT.strftime("%Y-%m")
8885
+ key = "/startapp" if USER_UTM == "/startapp" else "/start"
8886
+ metrics_by_month[month_key][key] += 1
9085
8887
 
9086
8888
  process_user_rows(data_users)
9087
8889
 
@@ -9137,15 +8939,13 @@ async def return_unit_metrics(bot, data_users, EXTRA_D):
9137
8939
  for USER_TID, USER_VARS, USER_LSTS in data_users:
9138
8940
  USER_VARS = json.loads(USER_VARS or "{}")
9139
8941
  USER_LSTS = json.loads(USER_LSTS or "{}")
9140
- USER_DT = USER_VARS.get("USER_DT", "")
9141
8942
  USER_PAYMENTS = USER_LSTS.get("USER_PAYMENTS", [])
9142
8943
  USER_STATUSES = USER_LSTS.get("USER_STATUSES", [])
9143
8944
 
9144
- if USER_DT:
9145
- mo = datetime.strptime(USER_DT, "%d-%m-%Y_%H-%M-%S").strftime("%Y-%m")
9146
- if (USER_TID, mo) not in seen_new:
9147
- seen_new.add((USER_TID, mo))
9148
- metrics[mo]["new_users"] += 1
8945
+ mo = USER_DT.strftime("%Y-%m")
8946
+ if (USER_TID, mo) not in seen_new:
8947
+ seen_new.add((USER_TID, mo))
8948
+ metrics[mo]["new_users"] += 1
9149
8949
 
9150
8950
  for pay in USER_PAYMENTS:
9151
8951
  dt_p = datetime.strptime(pay.get("DT_START", ""), "%d-%m-%Y_%H-%M-%S")
@@ -9249,13 +9049,12 @@ async def return_cohort_metrics(bot, data_users, EXTRA_D):
9249
9049
  cohorts = defaultdict(set)
9250
9050
  activity_months = defaultdict(set)
9251
9051
 
9252
- for USER_TID, USER_VARS, USER_LSTS in data_users:
9052
+ for USER_TID, USER_DT, USER_VARS, USER_LSTS in data_users:
9253
9053
  USER_VARS = json.loads(USER_VARS or "{}")
9254
9054
  USER_LSTS = json.loads(USER_LSTS or "{}")
9255
- USER_DT = USER_VARS.get("USER_DT", "")
9256
9055
  USER_DAU = USER_LSTS.get("USER_DAU", [])
9257
9056
 
9258
- entry_mo = datetime.strptime(USER_DT, "%d-%m-%Y_%H-%M-%S").strftime("%Y-%m")
9057
+ entry_mo = USER_DT.strftime("%Y-%m")
9259
9058
  cohorts[entry_mo].add(USER_TID)
9260
9059
 
9261
9060
  for day_str in USER_DAU:
@@ -9338,13 +9137,11 @@ async def return_retention_metrics(bot, data_users, EXTRA_D):
9338
9137
  rev_by_cohort = defaultdict(lambda: defaultdict(float))
9339
9138
  cohort_users = defaultdict(set)
9340
9139
 
9341
- for USER_TID, USER_VARS, USER_LSTS in data_users:
9140
+ for USER_TID, USER_DT, USER_VARS, USER_LSTS in data_users:
9342
9141
  USER_VARS = json.loads(USER_VARS or "{}")
9343
9142
  USER_LSTS = json.loads(USER_LSTS or "{}")
9344
- dt_entry_raw = USER_VARS.get("USER_DT", "").split("_")[0]
9345
- if not dt_entry_raw:
9346
- continue
9347
- cohort_mo = datetime.strptime(dt_entry_raw, "%d-%m-%Y").strftime("%Y-%m")
9143
+
9144
+ cohort_mo = USER_DT.strftime("%Y-%m")
9348
9145
  cohort_users[cohort_mo].add(USER_TID)
9349
9146
 
9350
9147
  for pay in USER_LSTS.get("USER_PAYMENTS", []):
@@ -9431,15 +9228,11 @@ async def return_acquisition_retention_metrics(bot, data_users, EXTRA_D):
9431
9228
  user_signup = {}
9432
9229
  user_activity = defaultdict(set)
9433
9230
 
9434
- for USER_TID, USER_VARS, USER_LSTS in data_users:
9231
+ for USER_TID, USER_DT, USER_VARS, USER_LSTS in data_users:
9435
9232
  vars_ = json.loads(USER_VARS or "{}")
9436
9233
  lsts = json.loads(USER_LSTS or "{}")
9437
- dt0_str = vars_.get("USER_DT", "").split("_")[0]
9438
- if not dt0_str:
9439
- print(f"Skip USER_TID={USER_TID}, no signup date")
9440
- continue
9441
- dt0 = datetime.strptime(dt0_str, "%d-%m-%Y")
9442
- user_signup[USER_TID] = dt0
9234
+
9235
+ user_signup[USER_TID] = USER_DT
9443
9236
  for day in lsts.get("USER_DAU", []):
9444
9237
  try:
9445
9238
  d = datetime.strptime(day, "%Y-%m-%d")
@@ -9454,8 +9247,8 @@ async def return_acquisition_retention_metrics(bot, data_users, EXTRA_D):
9454
9247
 
9455
9248
  # group by cohort month
9456
9249
  cohorts = defaultdict(list)
9457
- for uid, dt0 in user_signup.items():
9458
- mo = dt0.strftime("%Y-%m")
9250
+ for uid, USER_DT in user_signup.items():
9251
+ mo = USER_DT.strftime("%Y-%m")
9459
9252
  cohorts[mo].append(uid)
9460
9253
  print("Cohorts by month:", {k: len(v) for k, v in cohorts.items()})
9461
9254
 
@@ -14482,62 +14275,6 @@ async def lz_code_pg(chat_id, lan, BASE_P):
14482
14275
  return result
14483
14276
 
14484
14277
 
14485
- async def check_sub_pay_pg(chat_id, lz, BOT_TOKEN_E18B, BASE_P):
14486
- is_paid = False
14487
- till_paid = ''
14488
- try:
14489
- USER_ISPAID = 0
14490
- USER_DTPAID = ''
14491
- dt_now = datetime.now(timezone.utc)
14492
- USER_DT = dt_now.strftime('%d-%m-%Y_%H-%M-%S')
14493
- extra_bot = None
14494
- try:
14495
- lib_id = channel_library_ru if lz == 'ru' else channel_library_en
14496
- extra_bot = Bot(token=BOT_TOKEN_E18B)
14497
- member_ = await extra_bot.get_chat_member(chat_id=lib_id, user_id=chat_id)
14498
- if member_.status in ['member', 'administrator', 'creator']: is_paid = True
14499
- print(f"check_sub_pay {is_paid=}")
14500
- except Exception as e:
14501
- logger.info(log_ % str(e))
14502
- finally:
14503
- if extra_bot: await extra_bot.session.close()
14504
-
14505
- sql = "SELECT USER_ISPAID, USER_DTPAID, USER_TYPAID, USER_DT, USER_LZ FROM \"USER\" WHERE USER_TID=$1"
14506
- data_usr = await db_select_pg(sql, (chat_id,), BASE_P)
14507
-
14508
- if not len(data_usr):
14509
- sql = "INSERT INTO \"USER\" (USER_TID, USER_DT) VALUES ($1, $2) ON CONFLICT DO NOTHING"
14510
- await db_change_pg(sql, (chat_id, USER_DT,), BASE_P)
14511
- else:
14512
- USER_ISPAID, USER_DTPAID, USER_TYPAID, USER_DT, lz = data_usr[0]
14513
-
14514
- if is_paid:
14515
- sql = "UPDATE \"USER\" SET USER_ISPAID=1, USER_DTPAID='', USER_TYPAID='all' WHERE USER_TID=$1"
14516
- await db_change_pg(sql, (chat_id,), BASE_P)
14517
- elif USER_ISPAID and USER_DTPAID:
14518
- till_paid = dt_now.strptime(USER_DTPAID, "%d-%m-%Y_%H-%M-%S").replace(tzinfo=timezone.utc)
14519
- print(f"{till_paid=}")
14520
-
14521
- if dt_now > till_paid:
14522
- sql = "UPDATE \"USER\" SET USER_ISPAID=0, USER_DTPAID='', USER_TYPAID='' WHERE USER_TID=$1"
14523
- await db_change_pg(sql, (chat_id,), BASE_P)
14524
- till_paid = ''
14525
- else:
14526
- is_paid = True
14527
- till_paid = till_paid.strftime('%d.%m.%Y')
14528
- else:
14529
- sql = "UPDATE \"USER\" SET USER_ISPAID=0, USER_DTPAID='', USER_TYPAID='' WHERE USER_TID=$1"
14530
- await db_change_pg(sql, (chat_id,), BASE_P)
14531
- print(f"check_sub_pay {is_paid=}, {till_paid=}")
14532
- except TelegramRetryAfter as e:
14533
- logger.info(log_ % f"TelegramRetryAfter {e.retry_after}")
14534
- await asyncio.sleep(e.retry_after + 1)
14535
- except Exception as e:
14536
- logger.info(log_ % str(e))
14537
- await asyncio.sleep(round(random.uniform(0, 1), 2))
14538
- return is_paid, till_paid
14539
-
14540
-
14541
14278
  async def no_new_text(txt):
14542
14279
  result = txt
14543
14280
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yeref
3
- Version: 0.29.26
3
+ Version: 0.29.28
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