Skip to content

Instantly share code, notes, and snippets.

@danbst
Created March 20, 2020 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbst/86c68616e37df60b6439db7cb5d2e629 to your computer and use it in GitHub Desktop.
Save danbst/86c68616e37df60b6439db7cb5d2e629 to your computer and use it in GitHub Desktop.
str gen
def generate_users_str(db, config, with_orders=False, with_ids=False):
all_s = []
total_orders = 0
if with_orders:
for user in db:
id_prefix = f"{user['telegram_id']} - " if with_ids else ""
is_ordered = user.get('order_food', config['DEFAULT_ORDER'])
if is_ordered:
total_orders += 1
all_s.append(f"{id_prefix}{user['name']} - {is_ordered}")
all_s.append("\n")
all_s.append(f"{config['BOT']['TOTAL_USERS']}{len(db)})
all_s.append(f"{config['BOT']['TOTAL_ORDERS']}{total_orders})
return "\n".join(all_s)
else:
for user in db:
id_prefix = f"{user['telegram_id']} - " if with_ids else ""
all_s.append(f"{id_prefix}{user['name']}")
all_s.append("\n")
all_s.append(f"{config['BOT']['TOTAL_USERS']}{len(db)})
return "\n".join(all_s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment