def search(request): try: username = request.session['username'] \ + "@" + settings.LOGMODULE_HOSTNAME c_query = request.GET.get('searchterm', '') if c_query: logmod = logmodule.LogModule() dp_ok = logmod.setDataDirectory(settings.LOGMODULE_DATA_PATH) ip_ok = logmod.setIndexDirectory(settings.LOGMODULE_INDEX_PATH) if dp_ok and ip_ok: search_cons = logmod.searchMessages(username, c_query) if search_cons == False: message = "No logged conversations" response = ServerStatus("success", message, []) else: response = ServerStatus("success", "", search_cons) else: message = "Log path settings are invalid" response = ServerStatus("failure", message, None) else: message = "Empty query" response = ServerStatus("failure", message, None) except KeyError: message = "Not logged in" response = ServerStatus("failure", message, None) return HttpResponse(convertToJSON(response), mimetype="text/plain")
def recent(request): try: username = request.session['username'] \ + "@" + settings.LOGMODULE_HOSTNAME logmod = logmodule.LogModule() dp_ok = logmod.setDataDirectory(settings.LOGMODULE_DATA_PATH) ip_ok = logmod.setIndexDirectory(settings.LOGMODULE_INDEX_PATH) if dp_ok and ip_ok: recent_cons = logmod.getRecentConversations(username) if recent_cons == False: message = "No logged conversations" response = ServerStatus("success", message, []) else: response = ServerStatus("success", "", recent_cons) else: message = "Log path settings are invalid" response = ServerStatus("failure", message, None) except KeyError: message = "Not logged in" response = ServerStatus("failure", message, None) return HttpResponse(convertToJSON(response), mimetype="text/plain")
# -*- coding: utf-8 -*- import os import time import requests from lxml import etree import logmodule from config import doubanurl, filepath logger = logmodule.LogModule() group_dict = dict() def get_cookies(): # 获取豆瓣登录Cookie信息 cookies = {} with open(filepath.cookie_txt, "r") as f_cookie: douban_cookies = f_cookie.readlines()[0].split("; ") for line in douban_cookies: key, value = line.split("=", 1) cookies[key] = value return cookies def get_active_group_set(): # 获取所有非常活跃小组的id,存入set中 active_group_set = set() with open(filepath.active_group_id_txt, "r") as f_agit: for line in f_agit.readlines():
like [email protected] """ import logmodule import time import calendar import os import sys #Deal with command line arguments if len(sys.argv) != 4: print "Usage:", sys.argv[0], "[data directory]", "[index directory]", print "[hostname]" else: #Prepare the logger module logmod = logmodule.LogModule() logmod.setDataDirectory(sys.argv[1]) logmod.setIndexDirectory(sys.argv[2]) hostname = sys.argv[3] while True: #Get the length of the incoming packet length_chunk = sys.stdin.read(2) if len(length_chunk) < 2: break mlength = ord(length_chunk[1]) + (ord(length_chunk[0]) << 8) data_chunk = sys.stdin.read(mlength) #Get the fields from the chunk raw_chunk = data_chunk.split("\n", 3)