Commits

timgluz  committed 6e419a5

second and updated version

  • Participants
  • Parent commits 66d845d

Comments (0)

Files changed (8)

         print "Serve as webpage with args: ", args
         return redirect(url_for("main"))
 
-    print args
     hours_count = twitter.do_request(args)
     if args["type"] == u"json":
         return jsonify(hours_count)

File app.pyc

Binary file modified.
     user = "ubuntu",
     key_filename = '/home/timgluz/workspace/interview_street/id_rsa',
     root = "/home/ubuntu/www",
-    requirements = ["flask", "simplejson", "datetime", "python-memcached"]
+    requirements = ["flask", "simplejson", "datetime","httplib2", "python-memcached"]
 ))
 
 def install_servers():
     print "Installing webservers."
     sudo("apt-get update")
     #Do you want to continue [Y/n]?
-    sudo("apt-get install nginx memcachedb")
-    pass
+    sudo("apt-get install nginx memcachedb uwsgi uwsgi-plugin-python uwsgi-plugin-greenlet-python")
 
 def load_configs():
     #sends server config files to production server
-    pass
+    put("../configs/nginx.sites.default", "/tmp/default")
+    sudo("mv /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/default.1")# do backup
+    sudo("mv /tmp/default /etc/nginx/sites-enabled/default")
 
 def install_venv():
     print "Installing and setting up virtualenv"
 
 def start_servers():
     print "starting web server"
+    sudo("/etc/init.d/nginx restart")
+    with cd("{0}/{1}".format(env.root, env.site)):
+        run("uwsgi --plugin python --socket :5000 --wsgi-file=app.py --venv=venv/ --daemonize ../log/uwsgi.log")
 
-    sudo("/etc/init.d/nginx start")
-    with cd("{0}/{1}".format(env.root, env.site)):
-        run("source venv/bin/activate")
-        run("python run.py")
 
 def make_dirs():
     print "Creating working dirs on production server"
     run("rm -rf {0}".format(env.root))
     run("mkdir {0}".format(env.root))
+    run("mkdir {0}/log".format(env.root))
     run("mkdir {0}/{1}".format(env.root, env.site))
 
 
     make_dirs()
     install_venv()
 
-def deploy(commit_msg = ""):
+def deploy(msg):
     #commit local files
-    local('hg add & hg commit -m"{0}"'.format(commit_msg))
+    local('hg add & hg commit -m "{0}"'.format(msg))
     local("hg archive --type=tgz ../{0}.tar.gz".format(env.site))
     #upload files
     put("../{0}.tar.gz".format(env.site),"{1}/{0}.tar.gz".format(env.site, env.root))
         run("tar -zxf {0}.tar.gz".format(env.site))
         run("rm {0}.tar.gz".format(env.site))
     #restart web server
+    start_servers()
     #clean local dir
     local("rm ../{0}.tar.gz".format(env.site))
 

File fabfile.pyc

Binary file modified.

File static/js/app.js

         form = get_form_data();
         //if form is empty, then show alert
         if(form.handle.length == 0){
-            $("#form-alert").empty().html("You need fill form!").addClass("alert alert-box alert-error");
+            $("#form-alert").empty().html('You need fill form!<a class = "close">&times;</a>').addClass("alert alert-box alert-error");
             return;
         }
         
         var callback = function(data){
-            $("#plot-container").empty().html(data);    
+            $("#plot-container").empty().text(data).html('<pre></pre>');    
         }
         
         get_data(form.handle, form.count, type, callback);
 
    
     // -- BIND some live actions --------------------------------------------
-    $("a.close").on("click", function(){
+    $(".close").on("click", function(){
         $(this).empty();
         $(this).removeClass();
     });
             '<dd>Tim Sulg alias TimGLuz</dd>',
             '<dd>interested in AI, ML and distributed computing</dd>',
             '<dt>Experienced in:</dt>',
-            '<dd><strong>Languages: </strong> C,Python,JS,Scala</dd>',
-            '<dd><strong>Skillset: </strong> 70% backend, 30% frontend</dd>',
+            '<dd>Languages: C,Python,JS,Scala</dd>',
+            '<dd>Skillset: 70% backend, 30% frontend</dd>',
             '<dt>Profiles</dt>',
             '<dd><a href = "">CV @StackCareer</a></dd>',
             '</dl>'
             '<dd>Flask</dd>',
             '<dd>OAuth v.2</dd>',
             '<dd>VirtualEnv & Fabric </dd>',
+            '<dd>nGinx, uWSGI, Memcachedb </dd>',
             '</dl>'
         ].join("\n");
 

File templates/base.html

-<!DOCTYPE html>
-
 <html lang="en">
     <head>
         <meta charset = "utf-8" />
                 <div class = "span7">
                     <div class = "form-menu well">
                         <form class = "form-inline" onSubmit = "return false;">
-                            <input name="handle" type = "text" class = "input-small" placeholder = "userhandler" />
-                            <input name="count" type = "text" class = "input-small" placeholder = "count" />
-                            <button type = "submit" class = "btn submit" >Go</button>
+                            <input name="handle" type = "text" class = "input" placeholder = "userhandler" />
+                            <input name="count" type = "text" class = "input" placeholder = "count" />
+                            <button type = "submit" class = "btn small btn-primary submit" >Go</button>
                         </form>
                         <div id  = "form-alert"></div>
                     </div>
 #!/usr/local/bin/python
 # -*- coding: utf-8 -*-
 '''
-
-
 '''
 import oauth2 as oauth
 import simplejson as json
 from datetime import datetime, tzinfo, timedelta
 import itertools
 import re
+import memcache
+
+CACHE_EXPIRES = 15 * 60 #content will hold in cache next 15 minutes
 
 API_KEY = "nMxlWGSl3OSWj8tfOPo6Q"
 SECRET_KEY = "LkOnQeGJpZFE0BJuIOR3d0RJMxpDfiPRKOcmRENRs"
     if query is None and not (query.has_key("handle")):
         query = default_query
 
+    mc = memcache.Client(["127.0.0.1:11211"])
+    key =  "{0}:{1}".format(query["handle"], query["count"])
+    cached_val =  mc.get(key)
+    if cached_val:
+        return cached_val
+
+    #if there wasnt cached value, then load data from service and cache it.
     match = re.match(r"\d+", query["handle"])
     if match and match.endpos > 5:
         query["user_id"] = query.pop("handle")
     client = init_oauth_client(ACCESS_TOKEN)
     tweets = get_user_timeline(client, query)
 
-    return  calc_hour_counts(tweets)
+    vals = calc_hour_counts(tweets)
+    mc.set(key, vals, CACHE_EXPIRES)
+    return vals
 
 
 if __name__ == "__main__":

File twitter.pyc

Binary file modified.