def itempage(email, bookName, author, price, condition): if request.method == "GET": info = database.listAll() for i in range(len(info)): if email == info[i]['email'] and bookName == info[i]['bookName'] and author == info[i]['author'] and price == info[i]['price'] and condition == info[i]['condition']: thisBook = info[i] userRating = database.getUserRating(email) currUser = session['email'] return render_template("itempage.html", thisBook=thisBook, userRating=userRating, currUser=currUser) else: search = request.form['searchQuery'] return redirect(url_for('search', query=search))
def main(): all_imgs = [x.split('_')[0] for x in listAll(IMGS)] print(len(all_imgs), 'images on disk') all_docs = listAll(DOCS) print(len(all_docs), 'docs viewed') wows = [] saves = [] with Jdt(len(all_docs), 'filtering', UPP=4) as j: for doc_id in all_docs: j.acc() doc: Doc = loadDoc(doc_id) if doc.response == RES_SAVE: saves.append(doc) elif doc.response == RES_WOW: wows.append(doc) lacks = set([x.id for x in saves]) - set(all_imgs) if lacks: print('Document response is SAVE but image not on disk:') [print(x) for x in lacks] print('Download now?') if input('y/n ').lower() == 'y': for id in lacks: doc = [x for x in saves if x.id == id][0] print('Getting', doc.id, '...') imgs = [getImage(x) for x in doc.img_urls] saveImg(doc, imgs) print('Complete.') p = input('Input path to download to: ') fns = [(osp.join(p, doc.id) + '.' + doc.img_type, doc) for doc in wows] missing_fns = [x for x in fns if not osp.exists(x[0])] print(f'There are {len(fns)} wow ones. {len(missing_fns)} are not on disk.') with Jdt(len(missing_fns)) as j: for fn, doc in missing_fns: j.acc() img = getImage(doc.img_urls[0]) with open(fn, 'wb+') as f: f.write(img) input('Ok. Press enter to quit...')
def main(): print('ls...') overall = loadOverall() baseline = score(overall) tagInfos = [] la = listAll(TAGS) with Jdt(len(la), 'Evaluating...', UPP=8) as j: for i in la: j.acc() ti = load(i) total = 0 for r in ALL_RESPONSES: total += ti.n_responses.get(r, 0) if ti.type == 'artist': if total < ARTIST_TOTAL_THRESHOLD: continue else: if total < 10: continue try: s = score(ti.n_responses) - baseline except ZeroDivisionError: s = 0 if abs(s) > 0.2: tagInfos.append((ti, s)) print('Sorting...') tagInfos.sort(key=lambda x: x[1]) print() FILENAME = 'tags_summary.csv' print(f'writing {FILENAME}...') header = ['Score', 'Type', 'Display', 'Name'] with open(FILENAME, 'w', encoding='utf-8', newline='') as f: c = csv.writer(f) c.writerow(header) for ti, s in tagInfos: c.writerow([ format(s, '+.1f'), str(ti.type), ti.display, ti.name, ]) with open(FILENAME, 'r', encoding='utf-8') as f: c = csv.reader(f) table = [*c] printTable(table)
def buy(): if request.method == "GET": info = database.listAll() actualones = [] ratings = [] for i in range(len(info)): if info[i].get('status', None) == 'available': sellerEmail = info[i]['email'] # remove @stuy.edu (intended for admin email) sellerEmail = sellerEmail.replace( siteAdminEmailService, '' ) rating = database.getUserRating(sellerEmail) info[i]['rating'] = rating print "info rating:" print info[i]['rating'] actualones.append(info[i]) return render_template("buypage.html", info=actualones) else: search = request.form['searchQuery'] return redirect(url_for('search', query=search))
f = open('temp/%s.txt' % doctorName, 'w') for k in range(1,8): store_n = {"morning":{}, "afternoon":{},"night":{}} #f.write("=====(%d)======\n" %k) # for k in range(len(weeksData[lastweek][today])) for i in weeksData[k]: for interval in weeksData[k][i]: for j in weeksData[k][i][interval]: if j not in store_n[interval] : store_n[interval][j] = [] store_n[interval][j].append(weeksData[k][i][interval][j]) else: store_n[interval][j].append(weeksData[k][i][interval][j]) #print(store_n) for inn in store_n: f.write("=====(%d %s)======\n" %(k,inn)) for num in range(len(store_n[inn])): #print (num+1, len(store_n[inn][num+1])) store_n[inn][num+1].sort() size_num = len(store_n[inn][num+1]) f.write('%d\t%.2f\t%d\t%s\n' %(num+1,store_n[inn][num+1][int(size_num/2)], size_num,inn)) f.close() debugFile.close() ########################## ## main ########################## DB.setDBFile('wanfang.db') result = DB.listAll() for doctor in result: generateData(doctor[1])
def listAll(): result = DB.listAll() for row in result: print '%s\t%s' % (unicode(row[0]), unicode(row[1]))