Skip to content

Commit

Permalink
Added logic to store statistical information about each image loaded
Browse files Browse the repository at this point in the history
into a database
  • Loading branch information
Kyle Hayes committed Dec 29, 2012
1 parent af40915 commit 4a85fd6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# virtualenv
venv

# foreman
.env

# OS X
*.DS_Store

Expand Down
30 changes: 23 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from PIL import Image, ImageDraw, ImageFont
from StringIO import StringIO
import os
import _mysql
import datetime

app = Flask(__name__)

Expand Down Expand Up @@ -157,20 +159,34 @@ def show_image_width_height(width, height):
width = min([width, 5000])
height = min([height, 5000])
caption = request.args.get('text', '')
bg_color = hex_to_rgb(request.args.get('bg_color', '#C7C7C7'))
text_color = hex_to_rgb(request.args.get('text_color', '#8F8F8F'))

return generate(width, height, caption, bg_color, text_color)
bg_color_hex = request.args.get('bg_color', '#C7C7C7')
text_color_hex = request.args.get('text_color', '#8F8F8F')
#track(width, height, caption, bg_color_hex, text_color_hex, request.remote_addr)
return generate(width, height, caption, hex_to_rgb(bg_color_hex), hex_to_rgb(text_color_hex))


@app.route('/<int:width>x<int:height>/<caption>')
def show_image_width_height_caption(width, height, caption):
width = min([width, 5000])
height = min([height, 5000])
bg_color = hex_to_rgb(request.args.get('bg_color', '#C7C7C7'))
bg_color_hex = request.args.get('bg_color', '#C7C7C7')
text_color = hex_to_rgb(request.args.get('text_color', '#8F8F8F'))

return generate(width, height, caption, bg_color, text_color)
text_color_hex = request.args.get('text_color', '#8F8F8F')
#track(width, height, caption, bg_color_hex, text_color_hex, request.remote_addr)
return generate(width, height, caption, hex_to_rgb(bg_color_hex), hex_to_rgb(text_color_hex))


def track(width, height, caption, bg_color, text_color, ip_address):
db_host = os.environ.get('DB_HOST', '')
db_user = os.environ.get('DB_USER', '')
db_passwd = os.environ.get('DB_PASSWD', '')
db_name = os.environ.get('DB_NAME', '')
#Define our connection string
db=_mysql.connect(host=db_host, user=db_user, passwd=db_passwd, db=db_name)
db.query("""
INSERT INTO stats(created_date, width, height, caption, bg_color, text_color, ip_address)
VALUES ('%s', %i, %i, '%s', '%s', '%s', '%s')
""" % (datetime.datetime.now(), width, height, caption, bg_color, text_color, ip_address))


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Flask==0.9
Jinja2==2.6
MySQL-python==1.2.4c1
PIL==1.1.7
Werkzeug==0.8.3
distribute==0.6.27
distribute==0.6.32
wsgiref==0.1.2

0 comments on commit 4a85fd6

Please sign in to comment.