本文整理汇总了Python中models.Site.create方法的典型用法代码示例。如果您正苦于以下问题:Python Site.create方法的具体用法?Python Site.create怎么用?Python Site.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Site
的用法示例。
在下文中一共展示了Site.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: seed_node
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import create [as 别名]
def seed_node(site_id = None, alias = None, latitude = None, longitude = None):
if site_id:
site = Site.query.filter_by(id = site_id).first()
else:
site = Site.create(name = 'Techrice site {}'.format(uuid4().hex))
if not alias:
alias = 'Techrice node {}'.format(uuid4().hex)
node = Node.create(name = alias, site = site, latitude = latitude, longitude = longitude)
solar = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'solar voltage').first(), name = 'vsol')
battery = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'battery voltage').first(), name = 'vbat')
temperature = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'DHT11 temperature').first(), name = 'temperature')
humidity = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'DHT11 humidity').first(), name = 'humidity')
sonar = Sensor.create(node = node, sensortype = SensorType.query.filter_by(name = 'sonar HC SR-04').first(), name = 'sonar')
header = Header.get_header(node_id = node.id)
print header
return {
'node': 'name: {}, id: {}, longitude: {}, latitude: {}'.format(node.name, node.id, node.longitude, node.latitude),
'sensors': map(lambda s: 'name: {}, id: {}'.format(s.name, s.id), node.sensors),
'header' : header
}
示例2: create
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import create [as 别名]
def create(request):
url = request.GET.get('url', None)
if url[:2] != 'http':
url = 'http://' + url
if url:
try:
site = Site()
site.create(url=url)
except ValueError, e:
return HttpResponse(e)
return HttpResponse(
simplejson.dumps({'hash': site.hash}),
content_type = 'application/javascript; charset=utf8'
)
示例3: post
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import create [as 别名]
def post(self):
parser = reqparse.RequestParser(bundle_errors = True)
parser.add_argument('name', type=str, location='form', required=True, help='<str> name required')
args = parser.parse_args()
site = Site.create(name = args['name'])
if site:
return jsonify(ApiObjects(site.json()))
else:
return jsonify(ApiObjects())
示例4: seed_site
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import create [as 别名]
def seed_site(sensors = 1, days = 7, interval_seconds = 3600):
site = Site.create(name = 'seeded_site')
node = Node.create(name = 'seeded_node', site = site, latitude = 35.146623 + random() / 100.0, longitude = 139.9835682 + random() / 100.0)
sensortype = SensorType.create(name = 'HC SR-04', unit = 'cm')
for i in range(sensors):
sensor = Sensor.create(sensortype = sensortype, node = node, name = 'water distance %s'%i)
timestamp = datetime.utcnow() - timedelta(days = 7)
data = loggeobrowngen()
n_readings = 0
while timestamp < datetime.utcnow():
Reading.create(sensor = sensor, value = data.next(), timestamp = timestamp)
timestamp += timedelta(seconds = interval_seconds)
n_readings += 1
data.close()
return {'site': site, 'node': node}
示例5: except
# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import create [as 别名]
MAIN_USER = None
MAIN_SITE = None
try:
MAIN_USER = User.get(User.email == MAIN_EMAIL)
MAIN_SITE = Site.get(Site.user == MAIN_USER)
except (User.DoesNotExist, Site.DoesNotExist) as e:
with db.transaction():
try:
if not MAIN_USER:
MAIN_USER = User.create(email=MAIN_EMAIL,
password=md5(MAIN_PASSWORD.encode('utf-8')).hexdigest(),
name=MAIN_NAME,
active=True)
if not MAIN_SITE:
MAIN_SITE = Site.create(user=MAIN_USER,
site_email=MAIN_EMAIL,
active=True)
except IntegrityError as ex:
print("Main Data Fail:", ex)
# Verify Main Site Data
if (not MAIN_USER) or (not MAIN_SITE):
print("Main User and Main Site not defined.")
sys.exit(-1)
@route('/', method='GET')
@require_site_registered()
@require_site_activated()
@require_csrf(token_id='csrf_index')