def update(args): operation = args['update_op'] id = args['listing_id'] listing = Listing.objects.get(listing_id=id) if operation == 'status': if int(args['status']) == 2: if not listing.last_accepted_bid: # Check to make sure at least one bid has been accepted return False, ERROR_NO_BID_MADE try: chosen_bid = Bid.objects.get(bid_id=listing.last_accepted_bid) except Bid.DoesNotExist: return False, ERROR_BID_DOES_NOT_EXIST try: bidder = Profile.objects.get(email=chosen_bid.bidder_email) except Profile.DoesNotExist: return False, ERROR_BID_DOES_NOT_EXIST locale.setlocale(locale.LC_ALL, '') notification_title = 'Your offer was accepted!' notification_description = 'Your bid of %s for %s was accepted! Click to get in contact.' % (locale.currency(float(chosen_bid.amount)), listing.job_title) notification.create(notification_title, notification_description, bidder.email, bidder.password, None) listing.__dict__['status'] = args['status'] listing.save() return True, None return False, 0
def accept(args): bid = Bid.objects.get(bid_id=args['bid_id']) bid.__dict__['status'] = 1 bid.save() bidder_profile = None try: bidder_profile = Profile.objects.get(email=bid.bidder_email) except Profile.DoesNotExist: return False, ERROR_NO_SUCH_PROFILE recent_jobs = json.loads(bidder_profile.recent_jobs) if len(recent_jobs) == NUM_RECENT_JOBS: del recent_jobs[0] recent_jobs.append(bid.listing_id) bidder_profile.__dict__['recent_jobs'] = json.dumps(recent_jobs) bidder_profile.save() listing = Listing.objects.get(listing_id=bid.listing_id) listing.__dict__['current_bid'] = bid.amount listing.__dict__['last_accepted_bid'] = bid.bid_id listing.save() locale.setlocale(locale.LC_ALL, '') notification_title = 'Bid Accepted!' notification_description = 'Your bid of %s for %s was accepted!' % (locale.currency(float(bid.amount)), listing.job_title) notification.create(notification_title, notification_description, bidder_profile.email, bidder_profile.password, None) return True, None
def addEvent(): form = eventForm() if request.method == "POST": title = request.form.get('title') description = request.form.get('description') start = request.form.get('start') end = request.form.get('end') datetimeStart = datetime.datetime.strptime( start, '%d-%m-%Y %H:%M').isoformat() datetimeEnd = datetime.datetime.strptime(end, '%d-%m-%Y %H:%M').isoformat() sizeForm = len(request.form) attendees = [] if (sizeForm >= 6): for i in range(5, sizeForm): dictTemp = {} index = i - 4 dictTemp['email'] = request.form['mail' + str(index)] attendees.append(dictTemp) service = getGoogleCalendarService() event = { 'summary': title, 'description': description, 'start': { 'dateTime': datetimeStart, 'timeZone': 'Europe/Paris', }, 'end': { 'dateTime': datetimeEnd, 'timeZone': 'Europe/Paris', }, 'attendees': attendees, 'reminders': { 'useDefault': False, 'overrides': [ { 'method': 'email', 'minutes': 24 * 60 }, { 'method': 'popup', 'minutes': 10 }, ], }, } event = service.events().insert(calendarId='primary', body=event).execute() for aMail in attendees: notification.create( mysql, aMail['email'], 'invitation à l\'évènement ' + event["summary"] + " de " + current_user.email + " le " + start, event["id"], "en attente de réponse") return redirect(url_for("showEvents")) return render_template('add.html', form=form, name=current_user.name + ' ' + current_user.familly_name.upper())
def find_or_create_notification(mon_client, name, email): notif = notification.find_by_name(mon_client, name) if notif is not None: if notif['address'] != email: print('Notification named %s exists but address is %s not %s' % (name, notif['address'], email), file=sys.stderr) return None return notif['id'] else: return notification.create(mon_client, name, email)
def decline(args): bid = Bid.objects.get(bid_id=args['bid_id']) bid.__dict__['status'] = 2 bid.save() bidder_profile = None try: bidder_profile = Profile.objects.get(email=bid.bidder_email) except Profile.DoesNotExist: return False, ERROR_NO_SUCH_PROFILE listing = Listing.objects.get(listing_id=bid.listing_id) locale.setlocale(locale.LC_ALL, '') notification_title = 'Bid Declined' notification_description = 'Your bid of %s for %s was declined.' % (locale.currency(float(bid.amount)), listing.job_title) notification.create(notification_title, notification_description, bidder_profile.email, bidder_profile.password, None) return True, None
def make_bid(args): listing_id = args['listing_id'] bidder_email = args['bidder_email'] bid_amount = args['bid_amount'] listing = Listing.objects.filter(listing_id=listing_id) bidder_profile = Profile.objects.get(email=bidder_email) if len(listing) == 0: return False, ERROR_NO_SUCH_LISTING bids = Bid.objects.filter(listing_id=listing_id) bid_id = str(listing_id) + str(len(bids)) bid = Bid(listing_id=listing_id, bid_id=bid_id, bidder_email=bidder_email, amount=bid_amount, status=0) bid.save() recent_bids = json.loads(str(bidder_profile.recent_bids)) if len(recent_bids) == NUM_RECENT_BIDS: del recent_bids[0] recent_bids.append(listing_id) bidder_profile.__dict__['recent_bids'] = json.dumps(recent_bids) bidder_profile.save() listing = listing[0] listing_bids = json.loads(listing.bids) listing_bids.append(bid_id) listing.__dict__['bids'] = json.dumps(listing_bids) listing.save() owner = Profile.objects.get(profile_id=listing.profile_id) locale.setlocale(locale.LC_ALL, '') notification_title = 'Someone made a bid!' notification_description = '%s made a bid of %s!' % (bidder_email, locale.currency(float(bid_amount))) extras = {'bid_id' : bid_id} notification.create(notification_title, notification_description, owner.email, owner.password, extras) return True, None
def logic(interaction, message): user_id = message.get('user_id') user_context = conversation.context(user_id) current_user_id = user_context.get('redirect_user') if current_user_id is not None: current_user_name = user_context['redirect_name'] current_user_phone = user_context['redirect_phone'] notification.create(user_id, current_user_id, 0, settings = {'minutes': 5}) reply_text = 'Acabas de poner un timer de 5 min con en tu (conversación) con {current_user_name} ({current_user_phone})' chat_api.reply(reply_text, message) new_message_user = user_context.get('last_message_user') user_new_message = user.get(new_message_user) if new_message_user is None: chat_api.reply('Falle en encontrar el usuario para hablar', message) return True new_message_name = user_context['last_message_name'] new_message_phone = user_context['last_message_phone'] conversation.update_context(user_id, 'redirect_user', new_message_user) conversation.update_context(user_id, 'redirect_name', new_message_name) conversation.update_context(user_id, 'redirect_phone', new_message_phone) conversation.update_context(user_id, 'conversational_level', 'user') # Code shared with switch if user_found.get('owner') is None: user.update(redirect_user_id, { 'owner': user_id } ) chat_api.reply('La conversación con este usuario es:', message) user_messages = conversation.get_printable_conversation(redirect_user_id) chat_api.reply(user_messages, message) return True
def create(user_id, user_data = {}, user_source = 'inbound'): user_type = get_user_type(user_id) if user_type == 'agent': name, uuid, phone = fetch_agent(user_id) else: if len(user_data.keys())>0: name, uuid, phone = fetch_user_data(user_data) else: name, uuid, phone = fetch_user(user_id) if phone: country = get_country_name_and_flag(phone) user = { 'id': user_id, 'source': user_source, 'type': user_type, 'name': name, 'uuid': uuid, 'phone': phone, 'country': country, 'created_at': datetime.now(), 'owner': None, 'threads': [], 'answering': False, 'current_thread': None, } if 'owner' in user_data: user['owner'] = user_data.get('owner') users.insert_one(user) message = { 'user_id': user_id, 'message': 'initial_message', 'created_at': datetime.now() } if user_source == 'inbound': message['text'] = 'Start message user' conversation.create(message) else: message['text'] = 'Start message bot' conversation.create(message, user_type= 'bot', message_type= 'bot_utterance', interaction_name = 'finish_conversation') # Add pending conversation if the given user model is a client if user_type == 'user': if user_data.get('owner'): owners_pending_convo = [user_data.get('owner')] else: owners_pending_convo = [] pending_conversations.create(user_id, owners = owners_pending_convo) if user_type == 'agent': for hour in [9, 17]: notification.create( user_id, notification_type = 'set_time', notification_nature = 'timed', settings = { 'hour': hour, 'minute': 0 } ) clean_agent_index() clean_user_index() return True
def main(): if len(sys.argv) == 1: print('usage: %s count [alarm-id]' % sys.argv[0], file=sys.stderr) return 1 if not utils.ensure_has_notification_engine(): return 1 mon_client = utils.create_mon_client() num_cycles = int(sys.argv[1]) alarm_name = 'notification_cycleTest' alarm_json = alarm.find_alarm_byname(mon_client, alarm_name) if alarm_json is not None: alarm_id = alarm_json['id'] else: existing = notification.find_by_name(mon_client, alarm_name) if existing is not None: notification_id = existing['id'] else: notification_id = notification.create(mon_client, alarm_name, "root@localhost") alarm_id = alarm.create(mon_client, alarm_name, None, 'max(cc) > 100', notification_id, notification_id, notification_id) user = '******' start_time = time.time() initial_state = alarm.get_state(mon_client, alarm_id) state = initial_state existing_notifications = utils.find_notifications(alarm_id, user) notifications_sent = num_cycles * 2 for _ in range(0, notifications_sent): if state == 'OK': state = 'ALARM' else: state = 'OK' if not alarm.set_state(mon_client, alarm_id, state): return 1 print("Took %d seconds to send %d alarm state changes" % ((time.time() - start_time), num_cycles * 2)) for i in range(0, 30): notifications = utils.find_notifications(alarm_id, user) notifications_found = len(notifications) - len(existing_notifications) if notifications_found >= notifications_sent: break print('Found %d of %d expected notifications so far' % (notifications_found, notifications_sent)) time.sleep(1) if notifications_found < notifications_sent: print('Expected %d notifications but found %d' % (notifications_sent, notifications_found), file=sys.stderr) return 1 print('Took %d seconds for notifications to fully arrive' % i) result = 0 return result
def createNotification(email, content, idEvent, accepted): notification.create(mysql, email, content, idEvent, accepted)