def communicate_post(): requested_books = request.form.getlist('wanted') if len(requested_books) == 0: entries = books return render_template("comm.html", entries=books) else: list_of_books = '' for isbn in requested_books: list_of_books += redis.get(isbn).decode('utf-8') + "\n" name = request.form['name'] email = request.form['email'] msg = Message("Hello here are the requested books", sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = name + " who can be contacted at " + email + " wants:\n" msg.body += list_of_books mail.send(msg) name = request.form['name'] email = request.form['email'] msg = Message("Hello here are the books you requested", sender="*****@*****.**", recipients=[email]) #msg.body = name + " who can be contacted at " + email + " wants:\n" msg.body = '' for isbn in requested_books: msg.body += redis.get(isbn).decode('utf-8').split(':::')[0] + "\n" mail.send(msg) return 'Thank you! An email is being sent to you about the books.'
def add_user_to_g(): """If we're logged in, add curr user to Flask global.""" #if "username" in session: if redis.get('username').decode('utf-8') != "": g.user = User.query.get(redis.get('username').decode('utf-8')) else: g.user = None
def _get_last_tweeted(self): if not hasattr(self, '_last_tweeted_date'): data = redis.get('last_tweeted_date') if data is None: raise LastTweetedDateNotSet() self._last_tweeted_date = dateutil_parse(data).date() return self._last_tweeted_date
def search_url(kw): h = json.loads(redis.get('people.json'), 'utf8') rx = re.compile(kw.strip(), re.IGNORECASE | re.UNICODE) for p in h.values(): if 'fuzzy' in p and re.search(rx, p['fuzzy']): return p['url']
def light_book(): isbn = request.form['isbn'] shelf_num = redis.get(isbn+":on_shelf") book_title = redis.get(isbn+":book_title") if shelf_num == "False": flash("This book is not on any shelf.") else: try: url_str = daemon_light_url + str(shelf_num) print url_str u = urlopen(url_str) flash("The shelf with \""+book_title+"\" was lit up.") except: flash("Error connecting to daemon.") return redirect(url_for('show_entries'))
def unlink(): fbId = getFbId() if not fbId: return "", 403 key = redis.get(fbId) redis.delete(fbId) plaid = Plaid(PLAID_ID, PLAID_KEY, key) plaid.delete() return redirect("/", code=302)
def communicate_post(): if request.form['my-form'] == 'Send': name = request.form['text'] redis.set('name',name) return render_template("communicate.html", name=name) elif request.form['my-form'] == 'Refresh': name = redis.get('name').decode('utf-8') return render_template("communicate.html", name=name) else: return "Something went wrong"
def mfa(): fbId = getFbId() if not fbId: return "", 403 key = redis.get(fbId) answer = request.form['answer'] plaid = Plaid(PLAID_ID, PLAID_KEY, key) plaid_resp = plaid.answerMFA('chase', answer) if not plaid_resp: return "", 403 return "", 200
def delete_book_isbn(isbn): clear_caches() rfid_id = redis.delete(isbn+":rfid_num") redis.delete(isbn+":on_shelf") book_title = redis.get(isbn+":book_title") redis.delete(isbn+":book_title") redis.delete(isbn+":author") redis.delete(isbn+":pic_url") try: redis.delete('rfid_id:'+rfid_id) except: pass
def books_on_shelf_changed(): clear_caches() rfid_id = request.args['scanid'] rfid_num = request.args['tagid'] # Scanner is a number (or a string?) indicating scanner ID # Tag is the tag number of the book books_prev_on_shelf = set([]) try: books_prev_on_shelf = set(redis.get("rfid:"+rfid_id).split(':')) except: # no books have ever been added to this shelf pass # old book vs. new book isbn = redis.get("rfid_id:"+rfid_num) if isbn == None: # associate tag with book in the system isbn = redis.get("rfid_most_recent_isbn") redis.set("rfid_id:"+rfid_num, isbn) redis.set(isbn+":rfid_num", rfid_num) book_was_removed = rfid_num in books_prev_on_shelf if not book_was_removed: # book added print "adding book", isbn, rfid_num, "to shelf", rfid_id redis.set(str(isbn)+":on_shelf", rfid_id) books_rfids_currently_on_shelf = books_prev_on_shelf | set([rfid_num]) else: # book removed print "removing book", isbn, rfid_num, "from shelf", rfid_id redis.set(isbn+":on_shelf", False) books_rfids_currently_on_shelf = books_prev_on_shelf - set([rfid_num]) shelf_string = ":".join(books_rfids_currently_on_shelf) redis.set("rfid:"+rfid_id, shelf_string) return redirect(url_for('show_entries'))
def add_to_shelf_with_tag(isbn, shelf, rfid_num): clear_caches() isbn = str(isbn) shelf = str(shelf) rfid_num = str(rfid_num) redis.set(isbn+":on_shelf", shelf) redis.set(isbn+":rfid_num", rfid_num) books_prev_on_shelf = set([]) try: books_prev_on_shelf = set(redis.get("rfid:"+shelf).split(':')) except: # no books have ever been added to this shelf pass books_rfids_currently_on_shelf = books_prev_on_shelf | set([rfid_num]) shelf_string = ":".join(books_rfids_currently_on_shelf) redis.set("rfid:"+shelf, shelf_string) redis.set("rfid_id:"+rfid_num, isbn)
def transactions(): print "Called transactions" fbId = getFbId() if not fbId: return "", 403 key = redis.get(fbId) daterange = request.form['daterange'] dates = daterange.split("-") start = "-".join(dates[0].split("/")) end = "-".join(dates[1].split("/")) plaid = Plaid(PLAID_ID, PLAID_KEY, key) transactions = plaid.getTransactions(options={ 'gte':start, 'lte':end }) if not transactions: return "", 403 print(transactions) map_key = os.environ.get("GOOGLE_KEY", "") return render_template('map.html', map_key=map_key, transactions=json.dumps(transactions['transactions']))
def collect_data(): if caches_defined(): global entries_cache, all_attributes_strings_cache return (entries_cache, all_attributes_strings_cache) entries = {} all_attributes_strings = [] for k in redis.keys(): a = redis.get(k) if k[0:4] == "rfid": continue try: [isbn, field] = k.split(":") try: entries[isbn][field] = a except: entries[isbn] = {} entries[isbn][field] = a if field == "author" or field == "book_title": all_attributes_strings.append(a) except: continue # reshape entry_list = [] for isbn in entries.keys(): field_dict = entries[isbn] field_dict['isbn'] = isbn entry_list.append(field_dict) # sort try: sorted_entry_list = sorted(entry_list, key=lambda dicty: dicty['book_title']) except: sorted_entry_list = [] entries_cache = sorted_entry_list all_attributes_strings_cache = json.dumps(all_attributes_strings).encode('utf8') return (entries_cache, all_attributes_strings_cache)
import sys from store import redis isbns = [line.rstrip() for line in sys.argv[1:]] for isbn in isbns: a = redis.get(isbn) b = redis.srem("books",a) if b != True: raise ValueError(isbn + " might not be in the table")
def hello(): name = redis.get('name').decode('utf-8') return render_template("communicate.html", name=name)
def add_to_shelf_wizard_prog(shelf): clear_caches() isbn = redis.get("rfid_most_recent_isbn") redis.set(isbn+":on_shelf", shelf)