Skip to content

Commit

Permalink
regexdict project
Browse files Browse the repository at this point in the history
regexdict project
  • Loading branch information
solos committed Mar 16, 2013
0 parents commit cd28746
Show file tree
Hide file tree
Showing 22 changed files with 142,689 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
#*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject
5 changes: 5 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# regexdict changelog

## 2013-03-16 0.1

* First public version.
1 change: 1 addition & 0 deletions LICENES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MIT
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include ChangeLog.txt LICENES.txt README.md requirements.txt
recursive-include test *.py *.sh
recursive-include docs *.md
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# regexdict

## 关于

regexdict 是一个使用正则表达式查询单词的网站,使用mongodb对正则表达式的支持实现,另外附带了一个不使用数据库的python实现。

demo: http://dict.re

## 目录介绍

1. ./ChangeLog.txt :变更历史
1. ./LICENES.txt :协议
1. ./MANIFEST.in :文件清单,distutils默认只打包指定模块下的.py文件,其它的要在这里指定
1. ./README.md :项目介绍
1. ./requirements.txt :项目需要依赖哪些模块
1. ./setup.py :安装文件
1. ./docs/ :文档目录
1. ./docs/analysis.model.md :概要设计文档
1. ./docs/design.model.md :详细设计文档
1. ./docs/maintain.md :维护文档
1. ./src/ :源码目录
1. ./src/regexdict : 项目代码
1. ./src/regexdict/stuff :杂项文件,在setup.py里用package_data参数指定
1. ./test/ :测试目录
1. ./test/run_all_test.sh :执行test目录下的所有单元测试
1. ./test/test_regexdict.py :测试示例

3 changes: 3 additions & 0 deletions docs/analysis.model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# regexdict 分析文档

此处存放项目的概要设计,简单分析,功能列表等初期文档
3 changes: 3 additions & 0 deletions docs/design.model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# regexdict 设计文档

此处存放项目的详细设计文档,主要算法描述等
3 changes: 3 additions & 0 deletions docs/maintain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# regexdict 维护文档

此处存放一些运维文档,比如运维需要做哪些监控,如何重启服务
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bottle
18 changes: 18 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding:utf-8 -*-
import sys
sys.path.append('./src')
from distutils.core import setup
from pyempty import __version__

setup(name='pyempty',
version=__version__,
description='empty python project template',
long_description=open("README.md").read(),
author='onlytiancai',
author_email='onlytiancai@gmail.com',
packages=['pyempty'],
package_dir={'pyempty': 'src/pyempty'},
package_data={'pyempty': ['stuff']},
license="Public domain",
platforms=["any"],
url='https://github.com/onlytiancai/pyempty')
3 changes: 3 additions & 0 deletions src/regexdict/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding:utf-8 -*-

__version__ = "0.1"
58 changes: 58 additions & 0 deletions src/regexdict/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/python
#coding=utf-8

import mako
import pymongo
import config
import json
import bottle
from bottle import response

conn = pymongo.Connection(config.MG_HOST, config.MG_PORT)
redict = conn.redict
redict.authenticate(config.MG_USER, config.MG_PASSWORD)

@bottle.route('/')
@bottle.mako_view("templates/index.html")
def index():
return dict()

@bottle.route('/re/:regex')
@bottle.mako_view("templates/redict.html")
def query(regex):

try:
regex = regex.replace('"', '').replace("'", '')
regex = '^%s$' % regex
collection = redict.words.find({"_id": {"$regex": regex}}).limit(config.LIMIT)
result = []
for item in collection:
result.append((item['_id'], item['definition']))
return dict(result=result)
except Exception, e:
print e
return {}

@bottle.route('/api/re/:regex')
def rapi(regex):

regex = regex.replace('"', '').replace("'", '')
regex = '^%s$' % regex
try:
collection = redict.words.find({"_id": {"$regex": regex}}).limit(config.LIMIT)
items = []
for item in collection:
items.append((item['_id'], item['definition']))
response.content_type = 'application/json'
result = {'code': 1, 'words': items}
except:
response.content_type = 'application/json'
result = {'code': 0, 'words': []}
return json.dumps(result)

@bottle.route('/static/<filepath:path>')
def static(filepath):
return bottle.static_file(filepath, root='./static/')

if __name__ == '__main__':
bottle.run(host=config.HOST, port=config.PORT, debug=config.DEBUG)
12 changes: 12 additions & 0 deletions src/regexdict/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/python
#coding=utf-8

HOST='localhost'
PORT=8000

MG_HOST='127.0.0.1'
MG_PORT=27017
MG_USER='user'
MG_PASSWORD='password'
LIMIT=50
DEBUG=False
Loading

0 comments on commit cd28746

Please sign in to comment.