Skip to content

Instantly share code, notes, and snippets.

@showyou
Created February 21, 2010 11:00
Show Gist options
  • Select an option

  • Save showyou/310262 to your computer and use it in GitHub Desktop.

Select an option

Save showyou/310262 to your computer and use it in GitHub Desktop.
!/usr/bin/env python
# -*- coding:utf-8 -*-
import hashlib
def genMod(str, modNumber):
m = hashlib.md5()
m.update(str[::-1])
a = int(m.hexdigest()[5:10],16)
return a % modNumber
def ngCharacter(str):
"""
if string contains "<,: and other, return false
>>> ngCharacter("<script>")
True
>>> ngCharacter("a_a")
False
>>> ngCharacter("abcde")
False
>>> ngCharacter("12345")
False
>>> ngCharacter("ab1233442")
False
"""
for c in str:
if c.isalnum() or c == '_':
return False
return True
def print_form():
print_header()
print """
<form action="./scoutter.cgi">別のユーザ名で試す<input
type="text" width=12 name="user"><input type="submit" value="測定!"></form>
"""
print_footer()
def output(user, str):
# ホントはここでuserにタグとかないかチェックすべき
template = """
<p align=center>
%sさんの戦闘力は<br>
<br>
<font size=7 color=red>%d</font><br>
<br>
です。<br>
</p>
<a href="javascript: var
m='%sさんのつぶやき力は%dです。【スカウッター】http://showyou.ath.cx/~yuki/cgi-bin/scoutter.cgi?user=%s #scoutter',
f='http://twitter.com/home/?status='+en
codeURIComponent(m); if(!window.open(f,'surfing')) location.href=f; void(0);">
twitterに投稿する</a><form action="./scoutter.cgi">別のユーザ名で試す<input
type="text" width=12 name="user"><input type="submit" value="測定!"></form>
""" % (user, str, user, str, user)
print_header()
print template
print_footer()
def print_header():
print """
<html>
<html lang="ja"><head><meta name="keywords" content="twitter"><meta
http-equiv="Content-Type" content="text/html; charset=utf-8" >
<meta http-equiv="Content-Style-Type" content="text/css" >
<link rel="stylesheet" type="text/css" href="../style.css">
<title>スカウッター</title>
</head>
<body><h1>スカウッター</h1>
<hr>
"""
def print_footer():
print """
<hr>
<p>スカウッター/<a href="http://twitter.com/showyou">showyou</a></p>
</body></html>
"""
if __name__ == "__main__":
#import doctest
#doctest.testmod(verbose=True)
"""import sys
if len(sys.argv) > 1:
input = sys.argv[1]
else:
input = "test"
"""
import cgi
f = cgi.FieldStorage()
url = f.getfirst('user', '')
if url != '':
if ngCharacter(url):
url = "hoge"
answer = genMod(url , 600000)
output( url ,answer )
else:
print_form()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment