def send_msg(request): print request.POST recv_data = request.POST.get('data') data = json.loads(recv_data) to_id = data.get('to_id') user_obj = models.bbs_models.UserProfile.objects.get(id=to_id) contact_type = data.get('contact_type') data['dtime'] = datetime.datetime.now().strftime("%F %T") if contact_type == 'single': if not global_msg_dic.has_key(to_id): global_msg_dic[to_id] = utils.Chat() global_msg_dic[to_id].msg_queue.put(data) elif contact_type == 'group': group_obj = models.CGroup.objects.get(id=to_id) for member in group_obj.members.select_related(): if not member.id == request.user.userproile.id: if not global_msg_dic.has_key(member.id): global_msg_dic[member.id] = utils.Chat() global_msg_dic[member.id].msg_queue.put(data) # print "Message ID: %s Username: %s" %(user_obj.id, user_obj.name) return HttpResponse({'state': 'OK'})
def main(): os.chdir(os.path.dirname(sys.argv[0])) # Инициализация базы данных db = database.SQLiteDatabase('mydatabase.db') # Создание интерфейса типа: сессия - база данных. Session\Database Interface sdi = database.SessionDatabaseInterface(db) # Инициализация сессии и подключение базы данных к ней session = utils.Session(sdi) # Создание интерфейса типа: чат - база данных. Chat\Database Interface cdi = database.ChatDatabaseInterface(db) # Инициализация чата и подключение базы данных к нему chat = utils.Chat(cdi) # Инициализация обработчика и передача ему объектов класса Session и Chat handler = Handler(session, chat) # handler.set_admin_panel(panels.AdminPanel(session)) handler.set_moder_panel(panels.ModerPanel(session)) if (WEBHOOK_DOMAIN != ''): bot.remove_webhook() time.sleep(1) bot.set_webhook(url=WEBHOOK_HOST) app.run(host=WEBHOOK_LISTEN, port=WEBHOOK_PORT, debug=True) else: bot.polling(none_stop=True, interval=0)
def getContactsMsgs(request): user_id = request.GET.get('user_id') if not msg_queue.has_key(user_id): print '--no msg queue for user :'******'\033[31;1m [%s] get msg data:\033[0m' % request.user.userprofile.name ,msg_data return HttpResponse(msg_data)
def get_msg(request): uid = request.GET.get('uid') if uid: res = [] if global_msg_dic.has_key(uid): res = global_msg_dic[uid].get_qmsg(request) return HttpResponse(json.dumps(res)) else: global_msg_dic[uid] = utils.Chat() return HttpResponse(json.dumps({}))
def get_msg(request): uid = request.GET.get('uid') if uid: res = [] if not global_msg_dic.has_key(uid): global_msg_dic[uid] = utils.Chat() res = global_msg_dic[uid].get_msg(request) return HttpResponse(json.dumps(res)) else: return HttpResponse(json.dumps("uid not provided!!"))
def send_msg(request): print request.POST data = request.POST.get('data') data = json.loads(data) data['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") to_id = data.get('to_id') user_obj = models.my_models.User_Profile.objects.get(id=to_id) contact_type = data.get('contact_type') if contact_type == 'single': if not global_msg_dic.has_key(to_id): global_msg_dic[to_id] = utils.Chat() global_msg_dic[to_id].msg_queue.put(data) # print '\033[32;1mPush msg [%s] into user [%s] queue' % (data['msg'], user_obj.name) elif contact_type == 'group': group_obj = models.QQgroup.objects.get(id=to_id) for member in group_obj.members.select_related(): if member.id != request.user.user_profile.id: if not global_msg_dic.has_key(member.id): global_msg_dic[member.id] = utils.Chat() global_msg_dic[member.id].msg_queue.put(data) return HttpResponse("ok!")
def send_msg(request): print request.POST data = request.POST.get("data") data = json.loads(data) data["date"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") to_id = data.get("to_id") user_obj = models.bbs_models.UserProfile.objects.get(id=to_id) contact_type = data.get("contact_type") if contact_type == "single": if not global_msg_dic.has_key(to_id): global_msg_dic[to_id] = utils.Chat() global_msg_dic[to_id].msg_queue.put(data) print "\033[31;1mPush msg [%s] into user [%s] queue" % (data["msg"],user_obj) elif contact_type == "group": group_obj = models.QQGroup.objects.get(id = to_id) for member in group_obj.members.select_related(): if member.id != request.user.userprofile.id: if not global_msg_dic.has_key(member.id): global_msg_dic[member.id] = utils.Chat() global_msg_dic[member.id].msg_queue.put(data) print "\033[31;1mPush msg [%s] into user [%s] queue" % (data["msg"], member.name) return HttpResponse("dddddddddddddd")
def send_msg(request): data = request.POST.get("data") data = json.loads(data) to_id = data.get("to_id") user_obj = models.workflow_models.UserInfo.objects.get(id=to_id) contact_type = data.get("contact_type") data["date"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") if not global_msg_dic.has_key(request.user.id): global_msg_dic[to_id] = utils.Chat() global_msg_dic[to_id].msg_queue.put(data) print "\033[32;1mI Push msg [%s] into user [%s] queue" % (data["msg"], user_obj.name) print "global_msg_dic = ", global_msg_dic return HttpResponse("ddddd")
def get_msg(request): uid = request.GET.get("uid") # new_msgs = [] if uid: # try: # if not global_msg_dic.has_key(uid): # global_msg_dic[uid] = utils.Chat() # new_msgs = global_msg_dic[uid].get_msg(request) # except ObjectDoesNotExist,e: # print '\033[41;1m%s\033[0m' % str(e) # return HttpResponse(json.dumps(new_msgs)) res = [] if not global_msg_dic.has_key(uid): global_msg_dic[uid] = utils.Chat() res = global_msg_dic[uid].get_mmsg(request) return HttpResponse(json.dumps(res)) else: return HttpResponse(json.dumps("uid not provided"))