def updateRecentStateDetails(): url = 'https://api.covidtracking.com/v1/states/daily.json' data = requests.get(url).json() for each in data: date = datetime.strptime(str(each['date']), r'%Y%m%d') mostRecent = Details.query.order_by(-Details.update_time).first().update_time if date == mostRecent: break state = each['state'] confirm = each['positive'] confirm_add = each['positiveIncrease'] dead = each['death'] heal = each['recovered'] detail = Details() detail.update_time = date detail.state = state detail.confirm=confirm detail.confirm_add=confirm_add detail.heal=heal detail.dead=dead db.session.add(detail) db.session.commit()
def delete_user(): phoneno=request.form['phoneno'] User=Details.objects(phoneno=phoneno).first() if User is None: return "<h2 style='color:red'>No user match</h2><h5><a href='/delete'>Go back</a></h5>" User.delete() return "<h2 style='color:red'>Deleted User</h2>"
def create_specimen_details(): """Last form to create specimen - enter site details""" form = CollectionDetailsForm() if session.get("link") is not None and session.get("species") is not None: if form.validate_on_submit(): session["date"] = form.date.data session["location"] = form.location.data session["county"] = form.county.data session["state"] = form.state.data session["habitat"] = form.habitat.data session["notes"] = form.notes.data user_id = current_user.id new_image = Specimen(link=session["link"], user_id=user_id) db.session.add(new_image) db.session.commit() specimen = Specimen.query.filter_by(link=session["link"]).first() new_specimen_taxonomy = Taxonomy( common_name=session["common_name"], specimen_id=specimen.id, species=session["species"], genus=session["genus"], family=session["family"], order=session["order"], phylum=session["phylum"], kingdom=session["kingdom"], authorship=session["authorship"], ) new_specimen_details = Details( specimen_id=specimen.id, date=session["date"], location=session["location"], habitat=session["habitat"], county=session["county"], state=session["state"], notes=session["notes"], ) db.session.add(new_specimen_taxonomy) db.session.add(new_specimen_details) db.session.commit() clear_specimen_session() flash(f"{specimen.taxonomy.common_name} specimen created!", "success") return redirect(f"/specimen/{specimen.id}") else: return render_template("newspecimen.html", form=form, step="collection_details") else: return ("", 403)
def setUp(self): """Creates test user and specimens""" db.drop_all() db.create_all() user1 = User.signup("tester1", "password1", None, None, None) user1id = 11 user1.id = user1id specimen1 = Specimen( link="https://i.imgur.com/pMkflKn.jpg", user_id=11, ) specimen1id = 12 specimen1.id = specimen1id specimen1taxonomy = Taxonomy( common_name="Red Oak", specimen_id=12, species="Quercus rubra", genus="Quercus", family="Fagaceae", order="Fagales", phylum="Tracheophyta", kingdom="Plantae", authorship="L.", ) specimen1details = Details( specimen_id=12, date="3-12-2019", location="Rock Bridge State Park", habitat="NE-facing slope", county="Boone", state="Missouri", notes="No Notes", ) collection1 = Collection( user_id=11, name="Test Collection", info="Here is some generic test text about this collection.", ) collection1id = 13 collection1.id = collection1id db.session.add_all( [specimen1, specimen1taxonomy, specimen1details, collection1]) db.session.commit()
def extract_details_info(details_site): soup = BeautifulSoup(details, 'lxml') all_charges = soup.find_all('div', class_='chargesContainer') for charge in all_charges: charge_table = charge.find( 'table', class_='collapse centered_table shadow responsive') tbody = charge_table.find('tbody', class_='single') charges_trs = tbody.find_all('tr') for charges_tr in charges_trs: details_info_cells = charges_tr.find_all('td', class_='two td_left') Details.create( case_num=details_info_cells[0].text.strip(), charge_description=details_info_cells[1].text.strip(), charge_status=details_info_cells[2].text.strip(), bail_amount=details_info_cells[3].text.strip(), bond_type=details_info_cells[4].text.strip(), court_date=details_info_cells[5].text.strip(), court_time=details_info_cells[6].text.strip(), court_of_jurisdiction=details_info_cells[7].text.strip())
def add_course(self, course_key, completed=True): if not isinstance(course_key, Key): raise ValueError("course_key must be a Key of a Course instance") # don't append if in list courses = self.get_all_courses() if any([c.course == course_key and c.completed == completed for c in courses]): return None c = Details.CourseAttempt( course=course_key, completed=completed, student=self.key ) k = c.put() return k
def test_no_link_fields(self): """Test entering no info on non-nullable fields (image link)""" specimen3 = Specimen( link=None, user_id=11, ) specimen3id = 14 specimen3.id = specimen3id specimen3taxonomy = Taxonomy( common_name=None, specimen_id=14, species=None, genus=None, family=None, order=None, phylum=None, kingdom=None, authorship=None, ) specimen3details = Details( specimen_id=14, date="3-12-2019", location=None, habitat="", county=None, state=None, notes=None, ) db.session.add_all([ specimen3, specimen3taxonomy, specimen3details, ]) with self.assertRaises(exc.IntegrityError) as context: db.session.commit()
def post(self): # parsing arguments args = parser.parse_args() FirstName = args['FirstName'] LastName = args['LastName'] Email = args['Email'] Password = args['Password'] Mobile = args['Mobile'] DateOfBirth = args['DateOfBirth'] Address = args['Address'] Is_Admin = args['Is_Admin'] user_details = Details( FirstName=FirstName, LastName=LastName, Email=Email, DateOfBirth=DateOfBirth, Mobile=Mobile, Address=Address ) user_credentials = Credentials( Email=Email, Password=Password ) user_Role = Role( Email=Email, Is_Admin=Is_Admin ) my_session.add(user_details) my_session.commit() my_session.add(user_credentials) my_session.commit() my_session.add(user_Role) my_session.commit() employee = my_session.query(Details).filter(Details.Email == Email).first() return employee, 201
def _save_Details(name,group,dept,gender,phone,year): if Details.objects(phoneno=phone).first() is None: Detail=Details() Detail.name=name Detail.group=group Detail.dept=dept Detail.phoneno=phone if int(gender) is 1: Detail.gender="Male" elif int(gender) is 2: Detail.gender="Female" else: print ("Error. Wrong Gender specified") Detail.year=year Detail.save() return "<h2 style='color:green'> Data Registered. </h2><h5><a href='EnterDetails'>Go back</a></h5>" return "<h2 style='color:red'>Error</h2><h2>Possibly a duplicate... </h2><h5><a href='EnterDetails'>Go back</a></h5>"
def place_order(netid): receipt = {} receipt['items'] = [] if request.method == 'POST': eastern = pytz.timezone('US/Eastern') try: incoming = request.get_json() except Exception as e: return jsonify(error=True), 400 if incoming is None: return jsonify(error=True), 400 if incoming['time'] == 'Now': currenttime = eastern.localize(datetime.datetime.now()) # for delayed ordering else: # get the year, month, and day for today to make datetime object year = datetime.date.today().year month = datetime.date.today().month day = datetime.date.today().day timestamp = incoming['time'].split(':') currenttime = eastern.localize( datetime.datetime(year, month, day, int(timestamp[0]), int(timestamp[1]))) # check whether the items ordered are in stock for i in incoming['items']: query = db.session.query(Menu).filter_by( item=i['item']['name']).first() if query is None: return jsonify(error=True), 408 if query.availability is False: return jsonify(availability=False, item=query.item), 200 for add in i['addons']: addon = add['name'] query = db.session.query(Menu).filter_by(item=addon).first() if query is None: return jsonify(error=True), 408 if query.availability is False: return jsonify(availability=False, item=query.item), 200 # add item to the History table order = History(netid=netid, time=currenttime, cost=incoming['cost'], payment=incoming['payment'], status=incoming['status'], order_status=0) try: db.session.add(order) db.session.commit() except Exception as e: return jsonify(error=True), 408 # add the order details to the dictionary receipt for email receipt['netid'] = netid receipt['cost'] = incoming['cost'] receipt['time'] = currenttime.strftime("%H:%M") receipt['type_payment'] = incoming['payment'] query = db.session.query(History).order_by( History.orderid.desc()).first() if query is None: return jsonify(error=True), 408 id = query.orderid item_id = 0 # add items to order details table for i in incoming['items']: addon_list = '' count = 0 for add in i['addons']: addon = add['name'] if count is 0: addon_list += addon else: addon_list += ', ' + addon count += 1 if i['sp'] == 'Small' or i['sp'] == 'Large': item_detail = i['sp'] + ' ' + i['item']['name'] if len(addon_list) > 0: item_detail += ' w/ ' + addon_list else: item_detail = i['item']['name'] if len(addon_list) > 0: item_detail += ' w/ ' + addon_list object = Details(id=id, item=item_detail, item_id=item_id) try: db.session.add(object) db.session.commit() # append items to the receipt receipt['items'].append(item_detail) item_id += 1 except Exception as e: return jsonify(error=True), 408 confirmation(receipt) return jsonify(availability=True, item=None), 201 else: return jsonify(error=True), 405
def setUp(self): """create test user and specimens""" # db.session.close() db.session.close() db.drop_all() db.create_all() user1 = User.signup("tester1", "password1", None, None, None) user1id = 11 user1.id = user1id specimen1 = Specimen( link="https://i.imgur.com/pMkflKn.jpg", user_id=11, ) specimen1id = 12 specimen1.id = specimen1id specimen1taxonomy = Taxonomy( common_name="Red Oak", specimen_id=12, species="Quercus rubra", genus="Quercus", family="Fagaceae", order="Fagales", phylum="Tracheophyta", kingdom="Plantae", authorship="L.", ) specimen1details = Details( specimen_id=12, date="3-12-2019", location="Rock Bridge State Park", habitat="NE-facing slope", county="Boone", state="Missouri", notes="No Notes", ) specimen2 = Specimen( link="https://i.imgur.com/pMkflKn.jpg", user_id=11, ) specimen2id = 13 specimen2.id = specimen2id specimen2taxonomy = Taxonomy( common_name=None, specimen_id=13, species=None, genus=None, family=None, order=None, phylum=None, kingdom=None, authorship=None, ) specimen2details = Details( specimen_id=13, date="3-12-2019", location=None, habitat="", county=None, state=None, notes=None, ) db.session.add_all([ specimen1, specimen1taxonomy, specimen1details, specimen2, specimen2taxonomy, specimen2details, ]) db.session.commit()