def update_bookmark(oid, bookmark): if oid and bookmark: blitem = Blitem.get({'_id': ObjectId(oid)}) print str(blitem) items = blitem['i'] for item in items: # type = item['t'] # if ControlType.is_bookmark(type): item['v'] = bookmark # logger.debug(str(blitem)) Blitem.save(blitem)
def updateTwitterItem(user_list, namesBag): for user in user_list: name = user.get('screen_name') u_id = getObjectId(name, namesBag) if u_id is not None: logger.debug('Update Item ' + str(u_id) + ' with ' + str(user)) blitem = Blitem.get({'_id': ObjectId(u_id)}) items = blitem['i'] for item in items: type = item['t'] if ControlType.is_twitter(type): item['cv'] = user logger.debug(str(blitem)) Blitem.save(blitem)
def send_message(): blitem_id = request.form['id'] transaction = request.form['transaction'] app_token = request.form['app_token'] if is_valid_id(blitem_id): blitem = Blitem.get({'_id': ObjectId(blitem_id), 'i.v': transaction}) if blitem: flat = Blitem.flat_object(blitem) current_app.logger.info(flat) template = read_file('/bsm/templates/mysecretvalentine.html') html_mail = template.decode('utf-8') html_mail = html_mail.replace("*|IMAGE|*", flat['url']) # html_mail = html_mail.replace("*|URL|*", 'http://blibb.net/go/' + flat['url_id']) html_mail = html_mail.replace("*|MESSAGE|*", flat['message']) mail = { 'to_address': flat['to'], 'from_name': 'Your Secret Valentine', 'from': '*****@*****.**', 'subject': 'Your Secret Valentine', 'txt_body': flat['message'], 'html_body': html_mail } print 'Mail sent to ' + mail['to_address'] sendgrid_user = get_config_value('SENDGRID_USER') sendgrid_password = get_config_value('SENDGRID_PASSWORD') s = sendgrid.Sendgrid(sendgrid_user, sendgrid_password, secure=True) message = sendgrid.Message((mail['from'], mail['from_name']), mail['subject'], mail['txt_body'], mail['html_body']) message.add_to(mail['to_address'], '') s.web.send(message) # return jsonify({'return': 'success'}) return html_mail abort(401) abort(400)