Protoball:ChronSite.py

From Protoball
Jump to navigation Jump to search
class ChronSite(mwclient.Site):

	def parse(self, text, title = None):
		kwargs = {}
		if title is None: kwargs['title'] = title
		result = self.api('parse', text = text, **kwargs)
		return result['parse']

	def get_titles(self, filter):
		ask = "{{{{#ask: {0}|sort=Year|link=none|limit=10000|headers=hide}}}}".format(filter)
		result = self.parse(ask)['text']['*']
		titles = result[3:result.find("\n</p>")].split(", ")
		return titles

	def get_page_info(self, page):
		text = page.edit()
		text = text[len("{{Chronology Entry\n|"):-3]
		page_info = {}
		for info in text.split("\n|"):
			if not "=" in info:
				print title + " missing data"
				continue
			key, data = info.split("=", 1)
			page_info[key] = data
		return page_info