This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from andrew4ever/dev
Patches
- Loading branch information
Showing
8 changed files
with
93 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 1 | ||
update_configs: | ||
- package_manager: "python" | ||
directory: "/" | ||
update_schedule: "daily" | ||
default_labels: | ||
- "dependencies" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
tinydb | ||
pytelegrambotapi | ||
tinydb==3.15.2 | ||
pyTelegramBotAPI==3.6.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
import datetime | ||
from datetime import datetime, timedelta | ||
import logging | ||
import time | ||
|
||
from services.is_business_day import is_business_day | ||
|
||
from pprint import pprint | ||
def is_business_day(date): | ||
return date.weekday() < 5 | ||
|
||
|
||
def execute_at(wake_time: datetime.time, callback, only_business, args=(), kwargs={}): | ||
def execute_at(wake_time: datetime.time, callback, only_business: bool, | ||
args=(), kwargs={}, interval=timedelta(days=1)): | ||
wake_time = datetime.combine(datetime.now(), wake_time) | ||
|
||
while True: | ||
time.sleep(0.9) | ||
now = datetime.datetime.now() | ||
time.sleep(1) | ||
now = datetime.now() | ||
|
||
if only_business and not is_business_day(now): | ||
continue | ||
|
||
if now.hour == wake_time.hour \ | ||
and now.minute == wake_time.minute \ | ||
and now.second == wake_time.second: | ||
time.sleep(1) # without delay it triggers many times a second | ||
if now >= wake_time: | ||
callback(*args, **kwargs) | ||
wake_time += interval | ||
|
||
logging.info('Executing %s at %r', callback.__name__, wake_time) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
from collections import Counter | ||
def generate_users_str(db, config, with_orders=False, with_ids=False): | ||
base = '' | ||
|
||
for user in db: | ||
base += user['telegram_id'] + ' - ' if with_ids else '' | ||
base += user['name'] | ||
base += ' - ' + str(user.get('order_food', | ||
config['DEFAULT_ORDER'])) if with_orders else '' | ||
base += '\n' | ||
|
||
def generate_users_str(db, config, with_orders=False, with_ids=False): | ||
p_list = '\n'.join([((user['telegram_id'] + ' - ') if with_ids else '') | ||
+ user['name'] + | ||
((' - ' + str(user.get('order_food', | ||
config['DEFAULT_ORDER']))) if with_orders else '') | ||
for user in db]) | ||
if not len(db): | ||
return config['BOT']['EMPTY'] | ||
|
||
total_orders = base.count('True') | ||
|
||
total_orders = Counter(p_list.split())['True'] | ||
base += '\n' + config['BOT']['TOTAL_USERS'] + str(len(db)) | ||
base += '\n' + config['BOT']['TOTAL_ORDERS'] + \ | ||
str(total_orders) if with_orders else '' | ||
|
||
return (p_list + '\n\n' + config['BOT']['TOTAL_USERS'] + str(len(db)) + | ||
(('\n' + config['BOT']['TOTAL_ORDERS'] + str(total_orders)) if with_orders else '')) \ | ||
if len(p_list) else config['BOT']['EMPTY'] | ||
return base |
This file was deleted.
Oops, something went wrong.