Github project list
September 29, 2010 at 10:24 PM | categories: Website, Version Control | View Comments
Adding in more stuff
It's mostly what I am working on atm for the blog. After using blogofile for a few days now I've really gotten accustomed to writing up new things for it. It is only python after all. So that helps. My newest idea was to have a listing of my github projects in the sidebar.
Seems simple enough
Found a good api in python for this. There was one that used javascript that would have also done the job, but I decided this could be slow and updated when the site was built, instead of needing to be updated real time.
After installing the github2 module, I got right to it and started making a controller for the widget. And I ended up with something like this:
github.py
import logging
from blogofile.cache import bf
github = bf.config.controllers.github
from github2.client import Github
github_api = Github()
config = {
"name": "Github",
"description": "Makes a nice github project listing for the sidebar",
"priority": 90.0,
}
def get_list(user):
"""
Each item in the list has:
name, url, description, forks, watchers, homepage, open_issues
"""
return [g for g in github_api.repos.list(user) if not g.fork]
def run():
github.logger = logging.getLogger(config['name'])
github.repo_list = get_list(github.user)
With a configuration in _config.py like this:
#### github projects ####
controllers.github.enabled = True
github = controllers.github
github.user = "goosemo"
And a simple github.mako file that I used mako's include function for:
<div class="sidebar_item">
<h3>Github Projects</h3>
<ul>
% for project in bf.config.controllers.github.repo_list:
<li><a href="${project.url}" title="${project.name}">
${project.name}</a> ${project.description}</li>
<br/>
% endfor
</ul>
</div>
<br />
I did run into an issue
After getting this all down the site was acting strange. The frontage had the listing of my git repos just as it was supposed to be. But I found that on every other page the github section was blank.
After tweaking and getting a bit frustrated, I read the blogofile code a bit more for the controller sections, and got the idea to up the priority from 70 to 90.
This did the trick, and I figure it was because the permalinks and other page creation work was being done before the github.repo_list could be populated.
Thoughts so far
Overall the process from idea to working in blogofile is straightforward, since it's nothing new in form of coding. Mako and python go well together.
Now I just need to get down a coherent way to publish these little bits I keep adding, and to also make them completely configurable via the _config.py and isolated into their own units so that installation/use is a simple procedure.
Getting twitter feed running for Blogofile
September 28, 2010 at 07:21 PM | categories: Website, Programming | View Comments
A small part to making it match
Wordpress has plugins, lots and lots of plugins. In my conversion from it to blogofile I wanted to make it match my old site as closely as I could. Having a twitter feed of my latest tweets was something I'd have to get on the site.
Fails
I though I might make a python api call and then pipe that into my sidebar. This worked. But it sucked because I'd have to rebuild the page every tweet. I don't mind static content for my posts and navigation and the like. That's just good caching I feel.
Tweets though are a constantly, or would be for anyone else but me, updating service.
In comes the JavaScript
So in looking for simple things to give me a twitter feed I found Remy Sharp's site and his directions on how to put a javascript based feed into a site.
It was simple as could be, and I had a base, but hard coded feed up an running in short order.
Making it better for blogofile users
Part of open source is giving back. Something I really want to do more of, and I feel am getting into the swing of it a bit more. But that's whatever, I found the useful and perfect plugin, and got it working in blogofile without much trouble.
I now started thinking about how others might like to use this and would not really want to hard code it too much. So I made it into a controller, and configurable by the _config.py file. I made it kinda simple, but a bit overkilled with the folder and an __init__.py, but I was aiming for it to be more work.
_controllers/tweets/__init__.py
import logging
from blogofile.cache import bf
config = {
"name": "Twitter",
"description": "Makes a sidebar widget for twitter",
"priority": 70.0,
}
def run():
tweets = bf.config.controllers.tweets
tweets.logger = logging.getLogger(config['name'])
After making it a controller then we're able to put in config vars and set them as we want. Which makes it nice for me later i want to change some things, since all configs are in this one file.
_configure.py
### Twitter Settings ###
controllers.tweets.enabled = True
tweets = controllers.tweets
tweets.username = "morganiangoose"
tweets.count = 3
tweets.enable_links = 'true'
tweets.ignore_replies = 'false'
tweets.template = ('<li><div class="item">%text% <a href="http://twitter.c'
'om/%user_screen_name%/statuses/%id%/">%time%</a></div></li><br/>')
I then threw this, which is pretty much directly from remy's directions with mako var, into my sidebar template.
_templates/sidebar.mako
<div class="sidebar_item">
<h3>Twitter</h3>
<script src="http://twitterjs.googlecode.com/svn/trunk/src/twitter.min.js"
type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
getTwitters('tweet', {
id: '${bf.config.tweets.username}',
count: ${bf.config.tweets.count},
enableLinks: ${bf.config.tweets.enable_links},
ignoreReplies: ${bf.config.tweets.ignore_replies},
clearContents: true,
template: '${bf.config.tweets.template}',
});
</script>
<div id="tweet">
</div>
</div>
<br />
Now when I compile the site it'll just throw all this into the sidebar, which will load up my twitter feed as I described in the template. And I won't have to have a twitter trigger or the like for updating my blog, which is I feel the best of both worlds.
Next Page ยป