Permalink
Browse files

v0.93, GeoIP or pygeoip auto detect, update translation

  • Loading branch information...
1 parent 61506e9 commit 08a45baaee123517008fd65d8e2b5320ca21f8a4 @nopri committed Oct 23, 2012
Showing with 37 additions and 14 deletions.
  1. +8 −3 README.txt
  2. +26 −8 app.py
  3. +3 −3 messages.py
View
@@ -35,7 +35,7 @@ Using:
- jQuery/jQueryUI (bundled, old version)
- PyYAML
- BeautifulSoup
-- GeoIP
+- GeoIP or pygeoip (auto detect)
- Python Imaging Library
- MySQL (and MySQLdb)
@@ -46,7 +46,8 @@ Default user/password: admin
Installation (with Python already installed):
- We will use Apache HTTP Server for WSGI.
-- Install: web.py, PyYAML, BeautifulSoup, Python GeoIP, PIL, MySQL Server, Python MySQLdb
+- Install: web.py, PyYAML, BeautifulSoup, Python GeoIP (or pygeoip, noted below),
+ PIL, MySQL Server, Python MySQLdb
Ubuntu-based distribution (put command in one line):
$ sudo apt-get install python-webpy python-yaml python-beautifulsoup python-geoip python-imaging mysql-server python-mysqldb
@@ -86,5 +87,9 @@ Installation (with Python already installed):
$ sudo service apache2 reload
-
+- If you are using pygeoip:
+ - Download http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
+ - Extract and put GeoIP.dat into application directory
+
+
Thank you :)
View
34 app.py
@@ -35,7 +35,20 @@
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageFilter
-import GeoIP
+#
+fgeo = None
+try:
+ import GeoIP
+ ogeo = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
+ fgeo = ogeo.country_name_by_addr
+except ImportError:
+ try:
+ import pygeoip
+ ogeo = pygeoip.GeoIP(CURDIR + PS + 'GeoIP.dat', pygeoip.MEMORY_CACHE)
+ fgeo = ogeo.country_name_by_addr
+ except:
+ fgeo = None
+#
import web
import yaml
from BeautifulSoup import BeautifulSoup
@@ -219,7 +232,7 @@ def pget(option, default='', strip=True, callback=None):
############################### CONSTANT ###############################
-VERSION = '0.92'
+VERSION = '0.93'
NAME = 'onlinestore-multi'
PRECISION = 2
TEMPLATE_DIR = CURDIR + PS + 'template'
@@ -1943,9 +1956,11 @@ def proc_set_log(handle):
met = web.ctx.method
dt = now()
#
- gi = GeoIP.new(GeoIP.GEOIP_STANDARD)
- country = gi.country_name_by_addr(ip)
- del gi
+ country = None
+ if callable(fgeo):
+ country = fgeo(ip)
+ if not country: country = None
+ #
insert_id = db.insert('tr_log',
date_log=dt, date_log_last=dt, activity=1, ip=ip,
country=country, referer=ref, url=url,
@@ -1971,9 +1986,12 @@ def proc_set_lang(handle):
else:
#auto
ip = web.ctx.ip
- gi = GeoIP.new(GeoIP.GEOIP_STANDARD)
- country = gi.country_name_by_addr(ip)
- del gi
+ #
+ country = None
+ if callable(fgeo):
+ country = fgeo(ip)
+ if not country: country = None
+ #
#
if m.COUNTRY.has_key(country):
lang = m.COUNTRY[country][0]
View
@@ -428,8 +428,8 @@
'desc_sys_template' : '',
'desc_sys_logo_file' : '',
'desc_sys_news_max' : 'empty for all news',
- 'desc_sys_payments': 'comma separated/ended: 1=cash, 2=cod, 3=bank/wire transfer',
- 'desc_sys_domain': 'tanpa protokol http/https',
+ 'desc_sys_payments': 'comma separated/ended: 1=cash, 2=COD, 3=bank/wire transfer',
+ 'desc_sys_domain': 'without http/https protocol',
'desc_product_category_priority': 'descending sort',
'desc_product_category_name_info': 'please fill in at least one field',
'desc_product_group_name_info': 'please fill in at least one field',
@@ -872,7 +872,7 @@
'desc_sys_template' : '',
'desc_sys_logo_file' : '',
'desc_sys_news_max' : 'kosongkan untuk tampil semua',
- 'desc_sys_payments': 'dipisahkan/diakhiri koma: 1=cash, 2=cod, 3=transfer bank',
+ 'desc_sys_payments': 'dipisahkan/diakhiri koma: 1=cash, 2=COD, 3=transfer bank',
'desc_sys_domain': 'tanpa protokol http/https',
'desc_product_category_priority': 'besar ke kecil',
'desc_product_category_name_info': 'harap isikan paling tidak satu field',

0 comments on commit 08a45ba

Please sign in to comment.