def mission(connection, pack): mission_data = pack.data #mission_save = str(packet.Packet("mission_save", name=name,\ # desc=info, poi=poi.unique_id )) mission_data["created"] = float(datetime.now().strftime("%s")) mission_data["changed"] = float(datetime.now().strftime("%s")) mission_data["unique_id"] = get_unique_id() mission_data["status"] = "active" print "fick ett mission, infos: %s" % mission_data s = get_session() try: poi = s.query(POI).filter(POI.unique_id==mission_data["poi"]).one() except: logging.error("servern hade inte den POI:en.") return print "Poi: %s" % poi miss = Mission(mission_data["name"], mission_data["created"], mission_data["changed"]) miss.status = mission_data["status"] miss.desc = mission_data["desc"] miss.unique_id = mission_data["unique_id"] miss.poi = poi s.add(miss) s.commit() mission_response = packet.Packet("mission_response") mission_response.data = mission_data for connection in connections.values(): connection.out_queue.put(mission_response)
# -*- coding: utf-8 -* import socket, threading, sys, select, struct, time from Queue import Queue from os import popen from shared import buffrify, packet from shared.data.serverdb import get_session, create_tables from shared.data.serverdb.defs import * from shared.settings import HOST_IP, HOST_PORT import logging from util import require_login from datetime import datetime print "gör session" session = get_session() print "gör tables" create_tables() units = session.query(Unit).all() if "exempeldata" in sys.argv and len(units) == 0: #POIType sjukhus = POIType(u"sjukhus1", "static/ikoner/sjukhus.png") hinder = POIType(u"hinder", "static/ikoner/cancel.png") session.add(sjukhus) session.add(hinder) #Lägger till alla poi's sjuk = POI(15.6001709, 58.40633172, u"Sjukhus", sjukhus, datetime.now(), datetime.now(), 501) session.add(sjuk)