class LinkedMarkMail: def __init__(self, base="http://linkedmarkmail.wikier.org", log="linkedmarkmail.log"): self.base = base self.api = MarkMail("http://markmail.org") self.cache = Cache() self.cache.register(Post, "message-%s.rdf") self.cache.register(Thread, "thread-%s.rdf") logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s: %(message)s", filename=log) logging.info("Created a new instance of LinkedMarkMail at %s" % datetime.now().strftime("%Y-%m-%d %H:%M:%S")) def search(self, query): search = self.api.search(query) return "" #FIXME def get_message(self, key): if (self.cache.is_cached(key, Post)): logging.info("Recovering message %s from cache..." % key) return self.cache.read(key, Post) else: logging.info("Trying to get message %s from MarkMail..." % key) message = self.api.get_message(key) if (message != None): url = "%s/message/%s" % (self.base, key) post = Post(url, key, message["title"], message["content"]) triples = len(post) #if (not self.cache.is_cached(post.get_key(), post.__class__)): # self.cache.write(post) # logging.info("Updated cache of post %s (%d triples)" % (key, triples)) logging.info("Returning %d triples of post %s" % (triples, key)) return post.get_data_xml() else: logging.error("Post %s not found" % key) return None def get_thread(self, key): logging.info("Trying to get thread %s" % key) thread = self.api.get_thread(key) if (thread != None): siocThread = Thread(self.base, key, thread["subject"], thread["permalink"], thread["atomlink"], thread["messages"]["message"]) triples = len(siocThread) if (self.cache.is_dirty(siocThread)): self.cache.update(siocThread) logging.info("Updated cache of thread %s (%d triples)" % (key, triples)) logging.info("Returning %d triples of thread %s" % (triples, key)) return siocThread.get_data_xml() else: logging.error("Thread %s not found" % key) return None
if (sys.argv[1] == None): exit(1) msg = 'subject:/"' + urllib.parse.quote( sys.argv[1] ) + '/"%20list:com.xensource.lists.xen-devel%20order:date-forward' while True: messages = markmail.search(msg, page) print(json.dumps(messages, indent=4, sort_keys=True)) if (page > int(messages['search']['numpages'])): break page = page + 1 for result in messages['search']['results']['result']: print(json.dumps(thread, indent=4, sort_keys=True)) thread = markmail.get_thread(result['thread_id']) if (thread not in thread_list): thread_list.append(thread) print(json.dumps(thread, indent=4, sort_keys=True)) for thread_msg in thread['messages']['message']: message = markmail.get_message(thread_msg['id']) #print(json.dumps(message, indent=4, sort_keys=True)) parser.feed(message['content'])