RSS

Tag Archives: twitter

Flask, Pystache and Bootstrap

[Update 2012-05-14] RDO pointed out that there were some changes in pystache. The first and foremost is that they changed the API structure entirely. While I might not have actually implemented that best practices as there are a number of ways to accomplish the same thing. I was more interested in staying try to the initial project structure.  So if you read the pystache Renderer class you’ll probably see everything you need. And to round the changes out I found a few bugs in the MANIFEST.in and __init__.py that have been corrected here. This code runs although it’s not loading any of the images and some of the css… as I have not updated the html to work the way it should. But it’s easy enough for the reader now that the rest is working. (One final note, edit the fluid.html file and change ../assets/ to /static/) 

I’m using flask, pystache and bootstrap in order to build a fast prototype. I’ve already written a little about this but the text was getting long in the tooth so I cut it off short of a complete description. I decided to break the work into a separate text… as it’s more manageable. Some of these instructions will vary if you are using virtualenv.

- download bootstrap

cd ${HOME}
mkdir -p git
cd ${HOME}/git
git clone https://github.com/twitter/bootstrap.git

- download the latest pystatche (pip does not have the latest code so go to github for it)

cd ${HOME}
mkdir -p git
cd ${HOME}/git
git clone https://github.com/defunkt/pystache.git
cd pystache
sudo python ./setup.py install

- download and install flask

sudo pip install flask

- download and install ‘modern-package-template’

sudo pip install modern-package-template

- create your project (answer the questions as best as you can)

cd ${HOME}
mkdir -p hg
cd ${HOME}/hg
paster create -t modern_package helloworld

- now you need to do a number of things in order to get pystache to work with bootstrap. I’m going to list them out and give examples where I can.

  • copy the ‘examples’ directory from bootstrap to the ‘src/helloworld’ directory
  • create a ‘static’ directory in the ’src/helloworld’ directory
  • copy the css and JS directory from the bootstrap directory to the static folder
  • update the MANIFEST.in file to include the examples and static directories
  • update src/helloworld/__init__.py
  • update src/helloworld/hello.py

FILE: src/helloworld/__init__.py

from helloworld import hello
def main():
    hello.main()

FILE: src/helloworld/hello.py

from pystache.loader import Loader
from pystache.renderer import Renderer
from flask import Flask, url_for

app = Flask(__name__)
@app.route("/simple")
def simple():
    loader = Loader(extension='html', search_dirs=[app.root_path+'/examples',])
    template = loader.load_name('fluid')
    renderer = Renderer()
    return renderer.render(template, {'person': 'Mom'})

def main():
    app.debug = True
    app.run()

FILE: MANIFEST.in

include README.rst
include NEWS.txt
recursive-include src/helloworld/examples *
recursive-include src/helloworld/static *

pystache is able to locate the templates stored in the source because I added the code ‘app.root_path’ to the template directory parameter in the pystache loader.

Flask is able to locate the static files because flask defaults ‘/static’ to the folder in the same directory as the current module. This did not require any special config. If you decided to move the file you would have to add some params to app.run()

Finally, since setuptools does not really recognize this project structure you have yo update the MANIFEST file yourself in order to tell setuptools to package the example/templates and static files.

One parting note. Jinga2 is installed with flask as part of the dependencies. I would have used Jinga2 but except for 2 reasons. 1) I’m experimenting with different languages and I’d rather use one template assembler. 2) There has been some recent criticism of template assemblers in general. The complaint is that they break the MVC model. It is currently impossible for Mustache to do that with the current syntax.

Serving any object like JS or PNG files need to be in the static directory or they need to be served by a web gateway in front of the flask instance. Like nginx, lighted or Apache.

I hope this article is better than the previous. I might clean that one up.

 
11 Comments

Posted by on 2012/01/18 in web

 

Tags: , , , , ,

Tweet… What? Huh?

I received a ‘being followed’ notice from twitter today. Since this does Not happen very often and it’s usually a spammer I check them all out. It turns out that this guy is a CEO for a social media company with 15k followers and he follows 15k people.

As my investigation continued I read his tweets for September 9. There must have been over 100 of them and they appeared to be legit. Which got me to thinking. How does he read tweets from 15k people; how does he keep that many conversations straight in his head; why; and what about his day job? If I were on the board of his company I’d be pissed!

And so that got me to thinking. What about the tweeter or blogger ithat tweets about pizza for dinner. Where is the marketing or social capital in that? It feels like smoke and mirrors.

[update 2011.09.11] and then there all the stupid bots that reply to everything. On topic or not.

 
 

Tags: , , ,

Logging in is hard to do

Services like Twitter and Facebook have created APIs so that 3rd party developers can write applications that can take… take advantage of their infrastructure, add features that are missing, and a host of other motives.

The one motive that we fail to remember when someone reports that Mark Zuckerberg get’s a Google+ account is that it’a all about marketing. I feel certain that long before it was announced about MZ his team had already performed a competitive analysis. The rest was just press from one side or the other.

Which brings me to my next observation… If you are a startup or a wanna-be startup. You might see yourself going to VCs for money. While on the surface that makes some sense, however, social networking is all the rage and organic growth is ok but VCs want to see explosive organic growth… *cough* cancerous growth. So your first stop should be an advertising or marketing company. Not VC.

And sliding back into APIs let’s talk security. When you are in your favorite app and they ask for some facebook credentials. Hold off. You should NEVER enter you username and definitely not your password. Sometimes your applications will launch a popup that looks like a login screen from whatever your remote system is (like facebook) but STOP!!! and cancel the current operation.

First you should log into your service (facebook or twitter etc). Then go back to the application and repeat the operations. This time the application will not prompt you for your credentials. It will slide to the part where it asks for permission. And then it’s going to display the types of permissions it wants.

The facebook permissions are very scary so read them carefully. One such permission allows the application to access your personal information any time they see fit. This does not seem like a problem today, however, some day you may have some important info that it truly secret. I hope MZ is listening and builds a data vault into the system.

 
Leave a comment

Posted by on 2011/07/01 in business

 

Tags: , , , ,

Is Social Networking Just a Fad?

I read the headline: Is Social Networking Just a Fad? And instead of reading the article I aggregated a number of other headlines that I read including One Simple Rule: Why Teens are Fleeing Facebook. There was also some grumbling about the upcoming IPO. Now that social network software is mainstream it’s just a matter of time for individual business to find a way to capitalize. If you’ve played and Cyberpunk RPG and you understand the backstory… it seems inevitable.

The rule of thumb in this fiction is always:

“The corporation” wants to spider away as much information as it can from any source that they can. Information from public sources is to be copied and then destroyed. The information from the competition is of utmost importance. And so on…

Sure there is going to be a FB but it will be different. It will be the public forum; it will be the anonymous platform; it will be the place of activism; games; and time wasting. Nothing is going to be real. It will be like most dating sites.

The corporation will exploit it for advertising a la Max Headroom. But have a very tight internal ghost network.

Yes! This post is from the FUD and Subjective folder.

 
Leave a comment

Posted by on 2011/06/17 in social networking

 

Tags: , , ,

 
One Page Docs

Creating a library one page at a time.

One Page Bugs

Reducing the friction of writing and fixing bugs or features.

Follow

Get every new post delivered to your Inbox.

Join 223 other followers