def website_upload(): postJson = json.loads(request.data) app.logger.debug(postJson) if not postJson.has_key('hostname'): return jsonify(status='missing hostname') technologies = [] for t in postJson['technologies']: if not t.has_key('title'): return jsonify(status='missing technology title') if not t.has_key('category'): return jsonify(status='missing technology category') if not t.has_key('url'): t['url'] = None if not t.has_key('detail'): t['detail'] = None # 完全一致的技术 tmpTech = Technology.query.filter_by(title=t['title']).filter_by( category=t['category']).filter_by(detail=t['detail']).first() if tmpTech is None: tmpTech = Technology(category=t['category'], title=t['title'], detail=t['detail'], url=t['url']) db.session.add(tmpTech) technologies.append(tmpTech) upload = Website.query.filter_by(hostname=postJson['hostname'], port=postJson['port']).first() if not upload: upload = Website(hostname=postJson['hostname'], port=postJson['port'], title=postJson['title'], ipaddress=postJson['ipaddress'], geo=postJson['geo'], technologies=technologies) else: upload.last_time = datetime.now() upload.title = postJson['title'] upload.technologies = technologies upload.ipaddress = postJson['ipaddress'] upload.geo = postJson['geo'] upload.frequency = upload.frequency + 1 db.session.add(upload) db.session.commit() return jsonify(status='ok')
def website_upload(): postJson = json.loads(request.data) app.logger.debug(postJson) if not postJson.has_key('hostname'): return jsonify(status = 'missing hostname') technologies = [] for t in postJson['technologies']: if not t.has_key('title'): return jsonify(status = 'missing technology title') if not t.has_key('category'): return jsonify(status = 'missing technology category') if not t.has_key('url'): t['url'] = None if not t.has_key('detail'): t['detail'] = None # 完全一致的技术 tmpTech = Technology.query.filter_by(title = t['title']).filter_by(category = t['category']).filter_by(detail = t['detail']).first() if tmpTech is None: tmpTech = Technology(category = t['category'], title = t['title'], detail = t['detail'], url = t['url']) db.session.add(tmpTech) technologies.append(tmpTech) upload = Website.query.filter_by(hostname = postJson['hostname'], port = postJson['port']).first() if not upload: upload = Website(hostname = postJson['hostname'], port = postJson['port'], title = postJson['title'], ipaddress = postJson['ipaddress'], geo = postJson['geo'], technologies = technologies) else: upload.last_time = datetime.now() upload.title = postJson['title'] upload.technologies = technologies upload.ipaddress = postJson['ipaddress'] upload.geo = postJson['geo'] upload.frequency = upload.frequency + 1 db.session.add(upload) db.session.commit() return jsonify(status = 'ok')