本文整理汇总了Python中TrackerRestApi.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addLocation
def addLocation(user_id, points):
session = Session()
if session.query(TrUser).get(user_id) is None:
raise ServerError("User does not exist")
if len(points) <= 0:
raise ServerError("Points is empty.")
location = []
for point in points:
location.append(TrULocation(lat_log=point['location'], accuracy=point['accuracy'],
creation_time=datetime.datetime.fromtimestamp(int(point['timestamp'])).strftime('%Y-%m-%d %H:%M:%S'),
battery=point['properties'].get('battery'),
speed=point['properties'].get('speed'),
user_id=user_id))
try:
session.add_all(location)
session.commit()
except:
session.rollback()
raise ServerError("Can't add new locations")
finally:
session.close()
return True
示例2: getDLocation
def getDLocation(user_id, device_id, since):
session = Session()
if session.query(TrUser).get(user_id) is None:
raise ServerError("User does not exist")
lst = []
locs = session.query(TrDLocation).join(TrDevice, TrDLocation.device_id == TrDevice.device_ID).\
filter(TrDLocation.device_id == device_id).\
filter(TrDLocation.creation_time > datetime.datetime.fromtimestamp(since)).\
filter(TrDevice.device_userID == user_id).all()
for loc in locs:
lst.append({
"lat_log": loc.lat_log,
"creation_date": int(loc.creation_time.strftime("%s")),
"speed": loc.speed,
"sensors": {
"battery": 10,
"accel": True,
"temp": -19}
})
session.close()
return lst
示例3: getFGeos
def getFGeos(user_id, follower_id):
session = Session()
if session.query(TrUser).get(user_id) is None:
raise ServerError("User does not exist")
follower = session.query(TrFollower).filter(TrFollower.id == follower_id).first()
if follower is None:
raise ServerError('Follower does not exist')
lst = []
for geo in follower.geos:
lst.append({
"id": geo.id,
"name": geo.name,
"state": geo.state,
"shape": geo.shape,
"center": geo.center,
"radius": geo.radius,
"color": geo.color
})
session.close()
return lst
示例4: getRoad
def getRoad(user_id, since):
session = Session()
news = session.query(TrRoadNews).filter(TrRoadNews.creation_date > datetime.datetime.fromtimestamp(since)).all()
lst = [fillNews(n) for n in news]
return lst
示例5: getAccList
def getAccList(user_id, list):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
us = session.query(TrUser).filter(TrUser.login.in_(list.split(','))).all()
lst = [fillUser(u) for u in us]
session.close()
return lst
示例6: getPlaces
def getPlaces(user_id):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
pls = session.query(TrPlace).filter(TrPlace.user_id == uid).all()
lst = [fillPlaceResponse(p) for p in pls]
session.close()
return lst
示例7: getDevices
def getDevices(user_id):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
t = session.query(TrVehicle.id).filter(TrVehicle.user_id == uid).subquery('t')
devs = session.query(TrDevice).filter(TrDevice.vehicle_id == t.c.id).all()
lst = [fillDeviceResponse(dev) for dev in devs]
session.close()
return lst
示例8: getComments
def getComments(user_id, group_id):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
t = session.query(association_table_user_group).filter(association_table_user_group.user_id == uid).\
filter(association_table_user_group.group_id == group_id).subquery('t')
ms = session.query(TrGroupComment).filter(TrGroupComment.user_group_id == t.c.id).all()
lst = [fillGroupMessageResponse(m, current_user) for m in ms]
session.close()
return lst
示例9: getGroups
def getGroups(user_id):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
t = session.query(association_table_user_group).filter_by(user_id=uid).subquery('t')
gs = session.query(TrGroup).filter(TrGroup.id == t.c.group_id).all()
lst = [fillGroupResponse(g) for g in gs]
gsa = session.query(TrGroup).filter(TrGroup.user_id == uid).all()
lst_admin = [fillGroupResponse(ga, True) for ga in gsa]
return lst + lst_admin
示例10: getHelps
def getHelps(user_id, vehicle_id, lat_log):
session = Session()
#TODO:: sql request nearby helps
helps = []
help1 = {"message": "Hey guys, What's up!", "lat_log": "54.123,55.1231", "timestamp": 12345678}
help2 = {"message": u'Тест', "lat_log": "55.123,34.345", "timestamp": 12345678}
helps.append(help1)
helps.append(help2)
session.close()
return helps
示例11: getFeedNews
def getFeedNews(user_id, since):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
t = session.query(association_table_user_feed).filter_by(user_id=uid).subquery('t')
fs = session.query(TrFeedNews, TrUserFeedFav.id).outerjoin(TrUserFeedFav).filter(TrFeedNews.feed_id == t.c.feed_id).\
filter(TrFeedNews.published > datetime.datetime.fromtimestamp(since)).all()
lst = [fillFeedResponse(f[0], f[1] is not None) for f in fs]
lst = [fillFeedResponse(f) for f in fs]
session.close()
return lst
示例12: getDealers
def getDealers(user_id, vehicle_id, location, radius):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
v = session.query(TrVehicle).filter(TrVehicle.user_id == uid).\
filter(TrVehicle.id == vehicle_id).first()
if v is None:
session.close()
raise ServerError("Vehicle doesn't exist.")
lat_lon = location.split(',')
base_point = GeoLocation.from_degrees(float(lat_lon[0]), float(lat_lon[1]))
sw, ne = base_point.bounding_locations(radius)
print sw.deg_lat
print sw.deg_lon
print ne.deg_lat
print ne.deg_lon
ds = session.query(TrDealer).filter(TrDealer.maker == v.car_model.marka_name).\
filter(TrDealer.latitude > sw.deg_lat).filter(TrDealer.longitude > sw.deg_lon).\
filter(TrDealer.latitude < ne.deg_lat).filter(TrDealer.longitude < ne.deg_lon).all()
ret = [fillDealerResponse(d) for d in ds]
session.close()
return ret
示例13: __doCalcTax
def __doCalcTax(region, power, year):
session = Session()
regs = session.query(TrRegion).all()
for r in regs:
if region in r.region_ids.split(","):
reg = r.title
r_id = r.id
break
tx = session.query(TrVehicleTax).filter(TrVehicleTax.region_id == r_id).first()
if tx is None:
return None
session.close()
return 1800, reg
示例14: logout
def logout():
s = Session()
u = current_user
u.authenticated = False
s.merge(u)
s.commit()
s.close()
logout_user()
return True
示例15: getConfigTest
def getConfigTest(hw_id):
session = Session()
followers = session.query(TrFollower).filter(TrFollower.master_id == 998).\
filter(TrFollower.slave_id > 963).\
filter(TrFollower.slave_id < 975).all()
x = [int(f.slave_id) for f in followers if f.hw_id == hw_id]
if len(x) == 1:
user_id = x[0]
elif len(x) == 0:
folls = [f for f in followers if f.hw_id is None]
if len(folls) == 0:
# no available slots for testers
raise ServerError("Can't add new tester. No available slots.")
else:
foll = folls[0]
setattr(foll, 'hw_id', hw_id)
try:
session.merge(foll)
session.commit()
user_id = foll.slave_id
except:
session.rollback()
raise ServerError("Can't update. Server is unavailable.")
finally:
session.close()
else:
raise ServerError("Double hw_id.")
conf = {
"user_id": user_id,
"accuracy": 200,
"updates_on": True,
"server_update_sec": 300,
"location_update_sec": 60
}
return conf