def POST(self): web.header('Content-Type', 'application/json') data = json.loads(web.data()) if 'tag_id' not in data: return json.dumps({ 'response': "404, but not really", 'message': "missing tag_id" }) password_secret = "moja_mami" password = data['tag_id'] + password_secret password = password.encode() salt = os.urandom(16) kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000, backend=default_backend()) key = base64.urlsafe_b64encode(kdf.derive(password)) string_key = key.decode("utf-8") if 'location' in data: new_tag = Tag(tag_id=data['tag_id'], location=data['location'], tag_key=string_key) else: new_tag = Tag(tag_id=data['tag_id'], tag_key=string_key) return json.dumps({ 'response': "SAVE SUCCESS.", 'new_tag': str(new_tag) })
def create_tag(tag: RequestTagObject) -> ResultWithData[str]: tag_id = short_unique_id() tag_created = Tag(tag_id=tag_id, name=tag.name, pretty_name_sv=tag.pretty_name_sv, pretty_name_en=tag.pretty_name_en) return get_result_with_data(tag_created.tag_id)
def make_tag_if_not_exists_and_return_tag_object(self, tag_name): res = self.get_tag(tag_name) if not res: res = Tag(seq('tags'), tag_name) self.session.add(res) return res
def create_tag(label): new_tag = Tag( label=label ) db.session.add(new_tag) db.session.commit() return new_tag.serialize()
def create_tag(): body = json.loads(request.data) title = body.get("title") if title is None: return failure_response("Invalid field!") new_tag = Tag(title=title) db.session.add(new_tag) db.session.commit() return success_response(new_tag.serialize(), 201)
def get_nearest_cafe(lat, lng): geo_json = get_cafe_json(lat, lng) if not geo_json: return cafes = [] tags_and_cafes = {} for data in geo_json.get('results'): cafe = Cafe(name=data['name'], lat=data['geometry']['location']['lat'], lng=data['geometry']['location']['lng'], rating=data.get('rating'), address=data['vicinity']) saved_cafe = Cafe.query.filter(Cafe.lat == cafe.lat and Cafe.lng == cafe.lng).first() if saved_cafe: cafe = saved_cafe else: db_session.add(cafe) db_session.commit() cafes.append(cafe) for type_name in data.get('types'): tags_and_cafes.setdefault(type_name, []) tags_and_cafes[type_name].append(cafe.id) for tag_name in tags_and_cafes.keys(): tag = Tag(tag_name=tag_name, localized_name='') db_session.add(tag) db_session.commit() for cafe_id in tags_and_cafes[tag_name]: tag_to_add = TagsForCafe(tag_id=tag.id, cafe_id=cafe_id) db_session.add(tag_to_add) db_session.commit() return cafes
def create_tags(): for name in ['python', 'linux', 'java', 'mysql', 'lisp']: tag = Tag(name=name) session.add(tag)
import xmltodict import sys sys.path.append('../') from db import Tag, Word with open('wordbook.xml', encoding='utf8') as fd: doc = xmltodict.parse(fd.read()) for item in doc['wordbook']['item']: num = Tag.query_count(tag=item['tags']) if num == 0: tag = Tag(tag=item['tags']) Tag.insert(tag) else: tag = Tag.query_one(tag=item['tags']) wordNum = Word.query_count(word=item['word']) if wordNum == 0: word = Word(word=item['word'], explanation=item['trans']) else: continue word.tags.append(tag) Word.insert(word)
def create_tag(body): tag = Tag(description=body.get("description")) db.session.add(tag) db.session.commit() return tag.serialize()
def post(self): data = request.get_json(force=True) tag = Tag(**data) print(to_dict(tag))