def send_updates(bot, job): #for chat_id in subscribers: for user in get_subscribers(db): # в цикле перебираем подписчиков try: # если ошибок нет bot.sendMessage(chat_id=user['chat_id'], text='текст') except error.BadRequest: print('Chat {} not found'.format(user['chat_id']))
def send_reminder(context): for user in get_subscribers(db): try: context.bot.send_message(chat_id=user['chat_id'], text='Напоминаю о мероприятии.') except error.BadRequest: print('Chat {} not found'.format(user['chat_id']))
def send_updates(bot, job): for user in get_subscribers(db): try: bot.send_message(user['chat_id'], 'F**K') except error.BadRequest: print('Chat {} not found'.format(user['chat_id'])) toggle_subscription(db, user)
def gates_sensor_handler(gpio): global bot if (c.DEVELOPER_COMPUTER != '64bit'): pin = int(gpio.getPin()) new_state = gpio.read() else: pin = 45 new_state = 1 gate = -1 for i in range(len(c.GPIOREAD_LIST)): if (pin == c.GPIOREAD_LIST[i]): gate = i break if (gate >= 0 and bot != None): subscribers = db.get_subscribers(gate) if (new_state == c.OPEN_GPIO): send_to_subscribers( bot, subscribers, "Informacion: Porton " + str(gate) + " fue abierto") Thread(target=timer_close_gate, args=( bot, gate, )).start() elif (new_state == c.CLOSED_GPIO): send_to_subscribers( bot, subscribers, "Informacion: Porton " + str(gate) + " fue cerrado") else: send_to_subscribers( bot, subscribers, "Informacion: Porton " + str(gate) + " estado desconocido") else: print(pin, new_state, gate) print("Error no encontro puerta") db.add_event(new_state, gate)
def timer_close_gate(bot, num): count = 0 ## First: wait MAX_TIME_WAIT minutes for i in range(c.MAX_TIME_WAIT * 4): sleep(15) # sleep 15 seconds count += 15 if (gpio.read_gpio(num) == c.CLOSED_GPIO): return count # Send First Alert subscribers = db.get_subscribers(num) send_to_subscribers( bot, subscribers, "Alerta: Porton " + str(num) + " sigue abierto luego de " + str(count / 60) + " minutos") ## Second: Wait each DELAY_ALERT minutes to send MAX_ALERT_MESSAGES alert messages each MAX_TIME seconds while (gpio.read_gpio(num) != c.CLOSED_GPIO): for i in range(c.DELAY_ALERT * 4): sleep(15) count += 15 if (gpio.read_gpio(num) == c.CLOSED_GPIO): return count for i in range(c.MAX_ALERT_MESSAGES): send_to_subscribers( bot, subscribers, "Alerta: Porton " + str(num) + " sigue abierto luego de " + str(count / 60) + " minutos!!!!") sleep(c.MAX_TIME) count += c.MAX_TIME if (gpio.read_gpio(num) == c.CLOSED_GPIO): return count return count
def send_updates(bot, job): for user in get_subscribers(db): try: bot.sendMessage(chat_id=user['chat_id'], text="BUZZZ!") except error.BadRequest: print('Chat {} not found'.format(user['chat_id']))
def send_updates(bot, job): for user in get_subscribers(db):
def send_updates(bot, job): for user in get_subscribers(db): bot.sendMessage(chat_id=user['chat_id'], text='fuuuu!')
def send_updates(bot, job): for user in get_subscribers(db): try: bot.send_message(chat_id=user['chat_id'], text='Auto messages...') except error.BadRequest: print('Чат {}, не найден'.format(user['chat_id']))
def send_updates(context): for user in get_subscribers(db): try: context.bot.sendMessage(chat_id=user['chat_id'], text='BUZZZ!') except error.BadRequest: print(f'Chat {user["chat_id"]} not found!')
def send_updates(context): for user in get_subscribers(db): try: context.bot.sendMessage(chat_id=user['chat_id'], text="Buzzi") except error.BadRequest: print('Kasachok')
def emailNotifierV2(dbGen, prevAvailabilitySumDict: Dict[str, Dict[str, Dict[int, int]]]): DB = next(dbGen) dbSubs = get_subscribers(DB) visited_params = {} # to check for visited pincode/district dataCollectDict = {} for dbSub in dbSubs: searchType = dbSub.search_type isDistrict = dbSub.search_type == "STDIS" param = dbSub.district_id if isDistrict else dbSub.pincode email = dbSub.email logger.debug(f'Email: {email}') if (visited_params.get(searchType) is None or (visited_params.get(searchType) is not None and visited_params[searchType].get(param) is None)): # requesting data from a district or pincode for the first time availSessions, availSum = searchForAvailability( param, dbSub.search_type, dbSub.min_age) visited_params[searchType] = { **visited_params.get(searchType, {}), **dict(zip([param], [(availSessions, availSum)])) } # Condition to check available and to also check prevAvailability with current one if len(visited_params[searchType][param][0]) > 0: sT = {} pD = {} availableSum = visited_params[searchType][param][1] pD[param] = { 'sessions': visited_params[searchType][param][0], 'availabilitySum': availableSum } sT[searchType] = pD # if ( # email not in prevAvailabilitySumDict or # searchType not in prevAvailabilitySumDict[email] or # param not in prevAvailabilitySumDict[email][searchType] or # (param in prevAvailabilitySumDict[email][searchType] and # prevAvailabilitySumDict[email][searchType].get(param) != availableSum)): # # Send an email to the address comprising of all the details # dataCollectDict[email] = { **dataCollectDict.get(email, {}), **sT } # # This is needed for conditional check # prevAvailabilitySumDict[email] = { **prevAvailabilitySumDict.get(email, {}), **sT } isChange = False if email not in prevAvailabilitySumDict: prevAvailabilitySumDict[email] = sT dataCollectDict[email] = sT isChange = True elif searchType not in prevAvailabilitySumDict[email]: prevAvailabilitySumDict[email] = { **prevAvailabilitySumDict[email], **sT } isChange = True dataCollectDict[email] = {**dataCollectDict[email], **sT} elif param not in prevAvailabilitySumDict[email][searchType] or ( param in prevAvailabilitySumDict[email][searchType] and prevAvailabilitySumDict[email][searchType][param] ['availabilitySum'] != availableSum): prevAvailabilitySumDict[email][searchType] = { **prevAvailabilitySumDict[email][searchType], **sT.get(searchType) } isChange = True if isChange: if email not in dataCollectDict: dataCollectDict[email] = sT elif searchType not in dataCollectDict[email]: dataCollectDict[email] = {**dataCollectDict[email], **sT} else: dataCollectDict[email][searchType] = { **dataCollectDict.get(email, {}).get(searchType, {}), **sT.get(searchType) } # logger.debug(prevAvailabilitySumDict) return dataCollectDict