Skip to content

Instantly share code, notes, and snippets.

@benelog
Created June 11, 2012 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benelog/2908629 to your computer and use it in GitHub Desktop.
Save benelog/2908629 to your computer and use it in GitHub Desktop.
Python examples
import sys
import datetime
import os
target_date = datetime.datetime.now() - datetime.timedelta(1)
if len(sys.argv) > 1:
target_date = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d")
log_file_name = "js_01.%s.log" % target_date.strftime("%Y_%m_%d")
os.system("wget -O raw-data/session1/%s http://benelog.net/%s" % (log_file_name, log_file_name))
# -*- coding: UTF-8 -*-
'''
Created on 2012. 3. 20.
@author: benelog
'''
from datetime import datetime
print """
<html>
<head>
<title>login,out report</title>
</head>
<body>
<p align="center">
<img src="count-graph.png"/>
<img src="ratio-graph.png"/>
</p>
<p align="center">
<table border="1">
<tr>
<th>Date</th>
<th>Login count</th>
<th>Logout count</th>
<th>Close count</th>
<th>Close/(Login + Logout) ratio</th>
</tr>
"""
week = ('월','화','수','목','금','토','일')
raw_file = open("aggr.out")
linecount = 0
while 1:
line = raw_file.readline()
linecount = linecount + 1
if linecount == 1:
continue
if not line:
break
print("<tr>")
cols = line.split(",")
date = datetime.strptime(cols[0], "%Y-%m-%d")
login = int(cols[1])
logout = int(cols[2])
close = int(cols[3])
ratio = float(close) / (float(login) + float(logout))
print "<td align='left'> %s </td>" % date.strftime("%Y-%m-%d (%a)")
print "<td align='right'> %d</td>" % login
print "<td align='right'> %d</td>" % logout
print "<td align='right'> %d</td>" % close
print "<td align='right'> %.3f</td>" % ratio
raw_file.close();
print """
</table>
</p>
</body>
</html>
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment