Created
May 20, 2014 16:20
-
-
Save nicpottier/086715b6e42cdd072a3d to your computer and use it in GitHub Desktop.
Generating Documentation from UserVoice Knowledge Base Articles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_docs(): # pragma: no cover | |
""" | |
Generates a single html file that contains all the knowledge base articles we have on | |
UserVoice, organized by topic. | |
""" | |
config = settings.USERVOICE_CONFIG | |
client = uservoice.Client(config['SUBDOMAIN_NAME'], | |
config['API_KEY'], | |
config['API_SECRET']) | |
# read our css, we include it inline so it looks good even offline | |
with open('./static/css/docs.css') as css_file: | |
css = css_file.read() | |
topics = [] | |
for topic in client.get_collection("/api/v1/topics.json"): | |
if int(topic['article_count']) > 0: | |
# grab all the articles for this topic | |
articles = [a for a in client.get_collection("/api/v1/topics/%d/articles.json?filter=published" % topic['id'])] | |
# sort them by position | |
topic['articles'] = sorted(articles, key=lambda article: article['position']) | |
# now remap any internal links in the text to be internal instead | |
for article in topic['articles']: | |
article['formatted_text'] = re.sub(r'http://feedback.textit.in/knowledgebase/articles/(\d+)[^"]*', | |
"#article_\\1", article['formatted_text']) | |
topics.append(topic) | |
# load our template | |
template = loader.get_template('docs/docs_frame.html') | |
context = Context(dict(css=css, topics=topics, now=timezone.now())) | |
# and render it | |
return template.render(context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment