Serving Flask helloworld using uwsgi

uwsgi is a high performance, low-resource usage web server for deploying python application.

In this post, i am going to show how to serve a simple HelloWorld application in flask using uwsgi

 

Prerequisites

pip install flask 

pip install uwsgi

Now lets create our app.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()


So we have created a simple flask application. Now lets create a run file for running the application

run.py

from app import app as application
if __name__ == "__main__":
    application.run()


Now we need to create a .ini (uwsgi.ini) file to save the settings for serving the uwsgi

[uwsgi]
http = 127.0.0.1:3031
chdir = /home/name/flaskuwsgi
wsgi-file = run.py
processes = 4
threads = 2
stats = 127.0.0.1:9191

now serve the application by running uwsgi uwsgi.ini. You can view your application at 127.0.0.1:3031

if you wish to serve it via nginx, configure reverse proxy to the ip and port after changing the first line in uwsgi.ini to

socket = 127.0.0.1:3031

Njoy smile

Solution for gpg: skipped: ” secret key not available” in windows

This occurs when GPG is not specified in the path. Excellent solution for this problem is given by Thomas Muntaner here http://www.thomasmuntaner.com/blog/gpg-with-git-on-windows-secret-key-not-available/

He gave me the solution, I am not going to copy paste it here.

Enjoy smile

Uninstalling torrent-time on Mac

Torrent-time is a browser plugin to stream torrents directly from your browser. During the past week, many popular torrent sites have incoporated it to their sites.
If you have installed them by mistake, and wants to remove them, you can follow the steps below

Open Terminal and type in the following commands

sudo rm /Library/LaunchDaemons/com.torrents-time.helper.plist
sudo rm /Library/PrivilegedHelperTools/com.torrents-time.helper
sudo rm -rf /Library/Preferences/com.torrents-time.plist /Library/Application Support/com.torrents-time

Restart & Njoy smile

Scraping comments of a facebook post

This is a basic example of scrapping comments of a facebook post using python and facebook sdk

I hope you have python and know how to install a package.

Lets install facebook using pip

pip install facebook-sdk

We are proceeding directly in python

Before that we need an access token to connect to facebook.

Get the access token from here: https://developers.facebook.com/tools/accesstoken/

Access token is the pretty long string inside the textbox on the side where it is written “Access Token”

Now lets get those comments

graph = facebook.GraphAPI(access_token=’your pretty long string which you have copied now’)

post = graph.get_object(id = ‘post id’)

You can get the post id, by opening an url of a post in facebook

If url to a post is https://www.facebook.com/TimesofIndia/posts/10153947250687139 then, “10153947250687139” is the post id

print post

This will print bunch of details about the post including first 10 likes and first 10 comments

If you just need to see the comments

print post[‘comments’]

This will show just the comments.

If you need the remaning comments/likes, you will need to iterate the “cursors”, which doesn’t cover in basics. So just stopping here.

If you need further clarifications, please comment. If you wish to have Part 2 of this post, comment.

Njoy smile

CMD + Q to close Finder window in OS X

Issue

One of the most annoying things that I have encountered while using mac was the inability of os x to close the finder window with the default quit button(cmd+q) . The default button to close finder in os x is cmd+w. But that, for me is a slow process when I want to quit all applications quickly.

Solution

There is a simple way to achieve this. As simple as entering two commands in terminal. That commands being

defaults write com.apple.finder QuitMenuItem -bool yes

killall Finder

That’s it. You are done. Now you can use cmd+q to quit the finder windows.

Njoy smile