first commit

This commit is contained in:
Sanj 2011-07-16 11:41:20 +05:30
parent d5f3ef90e2
commit 96fa0509ab
15 changed files with 635 additions and 2 deletions

0
best/__init__.py Normal file
View File

14
best/clear_inbox.py Normal file
View File

@ -0,0 +1,14 @@
import pygsm
modem = pygsm.GsmModem("/dev/ttyS0", baudrate=115200, timeout=1)
modem.boot()
for i in range(25):
try:
temp = modem.command('AT+CMGR=' + str(i+1)+',1')
if "REC READ" in temp[0]:
modem.query('AT+CMGD=' + str(i+1))
except:
pass

18
best/manage.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
#import sys, os
from django.core.management import execute_manager
import settings
if __name__ == "__main__":
# project_root = os.path.abspath(
# os.path.dirname(__file__))
# path = os.path.join(project_root, "apps")
# sys.path.insert(0, path)
# sys.path.insert(0, project_root)
execute_manager(settings)

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 KiB

View File

View File

View File

@ -0,0 +1,33 @@
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
from rapidsms.contrib.handlers.handlers.keyword import KeywordHandler
from new_best.models import *
import datetime
try:
import json
except:
import simplejson as json
class BestHandler(KeywordHandler):
keyword = "route"
def help(self):
self.respond("Send route <bus_no>")
def handle(self, text):
bus_no = text.strip()
now = datetime.datetime.now()
try:
a = Atlas.get_atlas(bus_no, now)
self.respond("route %s from %s to %s" % (a['route'],a['from'], a['to']))
except:
self.respond("Did not find bus number %s. Sorry." % bus_no)
def time_str(no):
whole = int(no)
decimal = (no - whole) * 10
mins = int(((decimal + .0) / 10) * 60)
return str(whole) + ":" + str(mins)

View File

@ -0,0 +1,37 @@
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
from rapidsms.contrib.handlers.handlers.keyword import KeywordHandler
from buses.models import *
class BestHandler(KeywordHandler):
keyword = "routeold"
def help(self):
self.respond("Send route <bus_no>")
def handle(self, text):
bus_no = text.strip()
a = Atlas.objects.filter(route__iexact=bus_no)
if len(a) < 1:
self.respond("Did not find that bus number. Sorry.")
else:
a = a[0]
src = a.src
first_src = time_str(a.first_src)
last_src = time_str(a.last_src)
dest = a.dest
first_dest = time_str(a.first_dest)
last_dest = time_str(a.last_dest)
schedule = a.schedule
ret = "%s(%s-%s) to %s(%s-%s) from %s" % (src, str(first_src), str(last_src), dest, str(first_dest), str(last_dest), schedule)
self.respond(ret)
def time_str(no):
whole = int(no)
decimal = (no - whole) * 10
mins = int(((decimal + .0) / 10) * 60)
return str(whole) + ":" + str(mins)

123
best/new_best/models.py Normal file
View File

@ -0,0 +1,123 @@
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
# into your database.
from django.db import models
class Acexpressroutes(models.Model):
routecode = models.CharField(max_length=512)
stopserial = models.IntegerField()
stageno = models.IntegerField()
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
stage = models.CharField(max_length=512)
km = models.FloatField()
stopname = models.CharField(max_length=512)
class Meta:
db_table = u'acexpressroutes'
class Atlas(models.Model):
routecode = models.CharField(max_length=512)
route = models.CharField(max_length=512)
busfrom = models.CharField(max_length=512)
firstfrom = models.CharField(max_length=512)
lastfrom = models.CharField(max_length=512)
busto = models.CharField(max_length=512)
firstto = models.CharField(max_length=512)
lastto = models.CharField(max_length=512)
routespan = models.CharField(max_length=512)
runtime7to11 = models.CharField(max_length=512)
runtime11to17 = models.CharField(max_length=512)
runtime17toend = models.CharField(max_length=512)
runtimenight = models.CharField(max_length=512)
headwaybefore7 = models.CharField(max_length=512)
headway7to11 = models.CharField(max_length=512)
headway11to17 = models.CharField(max_length=512)
headway17to20 = models.CharField(max_length=512)
headway20tolast = models.CharField(max_length=512)
reliefpoint = models.CharField(max_length=512)
traveltime = models.CharField(max_length=512)
scheduletype = models.CharField(max_length=512)
id = models.IntegerField(unique=True, primary_key=True)
class Meta:
db_table = u'atlas'
class Regularroutes(models.Model):
routecode = models.CharField(max_length=512)
stopserial = models.IntegerField()
stageno = models.IntegerField()
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
stage = models.CharField(max_length=512)
km = models.FloatField()
stopname = models.CharField(max_length=512)
class Meta:
db_table = u'regularroutes'
class Routetype(models.Model):
typenumber = models.IntegerField()
routetype = models.CharField(max_length=512)
class Meta:
db_table = u'routetype'
class Stopmaster(models.Model):
stopcode = models.IntegerField(unique=True)
stopname = models.CharField(max_length=512)
areacode = models.ForeignKey('Areamaster', db_column='areacode')
displayname = models.CharField(max_length=512)
smlength = models.IntegerField()
class Meta:
db_table = u'stopmaster'
class Areamaster(models.Model):
areacode = models.IntegerField(unique=True)
areaname = models.CharField(max_length=512)
class Meta:
db_table = u'areamaster'
class Asroutes(models.Model):
routecode = models.CharField(max_length=512)
stopserial = models.IntegerField()
stageno = models.IntegerField()
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
stage = models.CharField(max_length=512)
km = models.FloatField()
stopname = models.CharField(max_length=512)
class Meta:
db_table = u'asroutes'
class Expressroutes(models.Model):
routecode = models.CharField(max_length=512)
stopserial = models.IntegerField()
stageno = models.IntegerField()
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
stage = models.CharField(max_length=512)
km = models.FloatField()
stopname = models.CharField(max_length=512)
class Meta:
db_table = u'expressroutes'
class LocationsPoint(models.Model):
id = models.IntegerField(primary_key=True)
latitude = models.DecimalField(max_digits=13, decimal_places=10)
longitude = models.DecimalField(max_digits=13, decimal_places=10)
class Meta:
db_table = u'locations_point'
class LocationsLocationtype(models.Model):
name = models.CharField(max_length=100)
slug = models.CharField(max_length=50, primary_key=True)
class Meta:
db_table = u'locations_locationtype'
class LocationsLocation(models.Model):
id = models.IntegerField(primary_key=True)
point = models.ForeignKey(LocationsPoint)
type = models.ForeignKey(LocationsLocationtype)
# parent_type = models.ForeignKey(DjangoContentType)
parent_id = models.IntegerField()
class Meta:
db_table = u'locations_location'

156
best/new_best/modelsOld.py Normal file
View File

@ -0,0 +1,156 @@
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
# into your database.
from django.db import models
class Acexpressroutes(models.Model):
routecode = models.CharField(max_length=255)
stopserial = models.IntegerField()
stageno = models.IntegerField()
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
stage = models.CharField(max_length=255)
km = models.FloatField()
stopname = models.CharField(max_length=255)
class Meta:
db_table = u'acexpressroutes'
class Areamaster(models.Model):
areacode = models.IntegerField(unique=True)
areaname = models.CharField(max_length=255)
class Meta:
db_table = u'areamaster'
class Expressroutes(models.Model):
routecode = models.CharField(max_length=255)
stopserial = models.IntegerField()
stageno = models.IntegerField()
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
stage = models.CharField(max_length=255)
km = models.FloatField()
stopname = models.CharField(max_length=255)
class Meta:
db_table = u'expressroutes'
DAYS_MAP = {
"Monday": ['MF', 'FW', 'MS+HOL'],
"Tuesday": ['MF', 'FW', 'MS+HOL'],
"Wednesday": ['MF', 'FW', 'MS+HOL'],
"Thursday": ['MF', 'FW', 'MS+HOL'],
"Friday": ['MF', 'FW', 'MS+HOL'],
"Saturday": ['SAT','FW', 'MS+HOL'],
"Sunday": ['SH', 'FW'],
"Holiday": ['HOL', 'SH', 'MS+HOL'],
}
DAYS_OF_WEEK = {
1: 'Monday',
2: 'Tuesday',
3: 'Wednesday',
4: 'Thursday',
5: 'Friday',
6: 'Saturday',
7: 'Sunday'
}
class Atlas(models.Model):
routecode = models.CharField(max_length=255)
route = models.CharField(max_length=255)
busfrom = models.CharField(max_length=255)
firstfrom = models.CharField(max_length=255)
lastfrom = models.CharField(max_length=255)
busto = models.CharField(max_length=255)
firstto = models.CharField(max_length=255)
lastto = models.CharField(max_length=255)
routespan = models.CharField(max_length=255)
runtime7to11 = models.CharField(max_length=255)
runtime11to17 = models.CharField(max_length=255)
runtime17toend = models.CharField(max_length=255)
runtimenight = models.CharField(max_length=255)
headwaybefore7 = models.CharField(max_length=255)
headway7to11 = models.CharField(max_length=255)
headway11to17 = models.CharField(max_length=255)
headway17to20 = models.CharField(max_length=255)
headway20tolast = models.CharField(max_length=255)
reliefpoint = models.CharField(max_length=255)
traveltime = models.CharField(max_length=255)
scheduletype = models.CharField(max_length=255)
# id = models.IntegerField(unique=True)
class Meta:
db_table = u'atlas'
@staticmethod
def get_schedule(qset, schedules):
for s in schedules:
res = qset.filter(scheduletype__exact=s)
if res.count() > 0:
return res
return qset[0]
@classmethod
def get_atlas(kls, route, dateObj):
dayofweek = dateObj.isoweekday()
dayString = DAYS_OF_WEEK[dayofweek]
schedules = DAYS_MAP[dayString]
atlases = kls.objects.filter(route__iexact=route)
if atlases.count() < 1:
return False
a = kls.get_schedule(atlases, schedules)
if not a:
return False
return a.get_data(dateObj)
def get_data(self, dateObj):
d = {
'route': self.route,
'from': self.busfrom,
'to': self.busto,
# 'lastbusfrom': self.lastfrom,
# 'lastbusto': self.lastto,
}
return d
class Routetype(models.Model):
typenumber = models.IntegerField()
routetype = models.CharField(max_length=255)
class Meta:
db_table = u'routetype'
class Regularroutes(models.Model):
routecode = models.CharField(max_length=255)
stopserial = models.IntegerField()
stageno = models.IntegerField()
stopcode = models.ForeignKey('Stopmaster', db_column='stopcode')
stage = models.CharField(max_length=255)
km = models.FloatField()
stopname = models.CharField(max_length=255)
class Meta:
db_table = u'regularroutes'
class Stopmaster(models.Model):
stopcode = models.IntegerField(unique=True)
stopname = models.CharField(max_length=255)
areacode = models.ForeignKey(Areamaster, db_column='areacode')
displayname = models.CharField(max_length=255)
smlength = models.IntegerField()
class Meta:
db_table = u'stopmaster'
class Asroutes(models.Model):
routecode = models.CharField(max_length=255)
stopserial = models.IntegerField()
stageno = models.IntegerField()
stopcode = models.ForeignKey(Stopmaster, db_column='stopcode')
stage = models.CharField(max_length=255)
km = models.FloatField()
stopname = models.CharField(max_length=255)
class Meta:
db_table = u'asroutes'

23
best/new_best/tests.py Normal file
View File

@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

1
best/new_best/views.py Normal file
View File

@ -0,0 +1 @@
# Create your views here.

191
best/settings.py Normal file
View File

@ -0,0 +1,191 @@
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
# encoding=utf-8
# -------------------------------------------------------------------- #
# MAIN CONFIGURATION #
# -------------------------------------------------------------------- #
# you should configure your database here before doing any real work.
# see: http://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "best",
"USER": "best",
"PASSWORD": 'SMSbest',
"HOST": "localhost",
"PORT": "5432"
}
}
# the rapidsms backend configuration is designed to resemble django's
# database configuration, as a nested dict of (name, configuration).
#
# the ENGINE option specifies the module of the backend; the most common
# backend types (for a GSM modem or an SMPP server) are bundled with
# rapidsms, but you may choose to write your own.
#
# all other options are passed to the Backend when it is instantiated,
# to configure it. see the documentation in those modules for a list of
# the valid options for each.
INSTALLED_BACKENDS = {
"att": {
"ENGINE": "rapidsms.backends.gsm",
"PORT": "/dev/ttyS0",
"baudrate": 115200,
"timeout": 5
},
#"verizon": {
# "ENGINE": "rapidsms.backends.gsm,
# "PORT": "/dev/ttyUSB1"
#},
"message_tester": {
"ENGINE": "rapidsms.backends.bucket"
}
}
# to help you get started quickly, many django/rapidsms apps are enabled
# by default. you may wish to remove some and/or add your own.
INSTALLED_APPS = [
# the essentials.
"django_nose",
"djtables",
"rapidsms",
"new_best",
"django_extensions",
# "buses",
# common dependencies (which don't clutter up the ui).
"rapidsms.contrib.handlers",
"rapidsms.contrib.ajax",
# enable the django admin using a little shim app (which includes
# the required urlpatterns), and a bunch of undocumented apps that
# the AdminSite seems to explode without.
"django.contrib.sites",
"django.contrib.auth",
"django.contrib.admin",
"django.contrib.sessions",
"django.contrib.contenttypes",
# the rapidsms contrib apps.
"rapidsms.contrib.default",
"rapidsms.contrib.export",
"rapidsms.contrib.httptester",
"rapidsms.contrib.locations",
"rapidsms.contrib.messagelog",
"rapidsms.contrib.messaging",
"rapidsms.contrib.registration",
"rapidsms.contrib.scheduler",
"rapidsms.contrib.echo",
]
# this rapidsms-specific setting defines which views are linked by the
# tabbed navigation. when adding an app to INSTALLED_APPS, you may wish
# to add it here, also, to expose it in the rapidsms ui.
RAPIDSMS_TABS = [
("rapidsms.contrib.messagelog.views.message_log", "Message Log"),
("rapidsms.contrib.registration.views.registration", "Registration"),
("rapidsms.contrib.messaging.views.messaging", "Messaging"),
("rapidsms.contrib.locations.views.locations", "Map"),
("rapidsms.contrib.scheduler.views.index", "Event Scheduler"),
("rapidsms.contrib.httptester.views.generate_identity", "Message Tester"),
]
# -------------------------------------------------------------------- #
# BORING CONFIGURATION #
# -------------------------------------------------------------------- #
# debug mode is turned on as default, since rapidsms is under heavy
# development at the moment, and full stack traces are very useful
# when reporting bugs. don't forget to turn this off in production.
DEBUG = TEMPLATE_DEBUG = True
# after login (which is handled by django.contrib.auth), redirect to the
# dashboard rather than 'accounts/profile' (the default).
LOGIN_REDIRECT_URL = "/"
# use django-nose to run tests. rapidsms contains lots of packages and
# modules which django does not find automatically, and importing them
# all manually is tiresome and error-prone.
TEST_RUNNER = "django_nose.NoseTestSuiteRunner"
# for some reason this setting is blank in django's global_settings.py,
# but it is needed for static assets to be linkable.
MEDIA_URL = "/static/"
# this is required for the django.contrib.sites tests to run, but also
# not included in global_settings.py, and is almost always ``1``.
# see: http://docs.djangoproject.com/en/dev/ref/contrib/sites/
SITE_ID = 1
# the default log settings are very noisy.
LOG_LEVEL = "DEBUG"
LOG_FILE = "logs/rapidsms.log"
LOG_FORMAT = "[%(name)s]: %(message)s"
LOG_SIZE = 8192 # 8192 bits = 8 kb
LOG_BACKUPS = 256 # number of logs to keep
# these weird dependencies should be handled by their respective apps,
# but they're not, so here they are. most of them are for django admin.
TEMPLATE_CONTEXT_PROCESSORS = [
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
]
# -------------------------------------------------------------------- #
# HERE BE DRAGONS! #
# these settings are pure hackery, and will go away soon #
# -------------------------------------------------------------------- #
# these apps should not be started by rapidsms in your tests, however,
# the models and bootstrap will still be available through django.
TEST_EXCLUDED_APPS = [
"django.contrib.sessions",
"django.contrib.contenttypes",
"django.contrib.auth",
"rapidsms",
"rapidsms.contrib.ajax",
"rapidsms.contrib.httptester",
]
# the project-level url patterns
ROOT_URLCONF = "urls"
try:
from local_settings import *
except:
pass
# since we might hit the database from any thread during testing, the
# in-memory sqlite database isn't sufficient. it spawns a separate
# virtual database for each thread, and syncdb is only called for the
# first. this leads to confusing "no such table" errors. We create
# a named temporary instance instead.
import os
import tempfile
import sys
if 'test' in sys.argv:
for db_name in DATABASES:
DATABASES[db_name]['TEST_NAME'] = os.path.join(
tempfile.gettempdir(),
"%s.rapidsms.test.sqlite3" % db_name)

37
best/urls.py Normal file
View File

@ -0,0 +1,37 @@
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^my-project/', include('my_project.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
# RapidSMS core URLs
(r'^account/', include('rapidsms.urls.login_logout')),
url(r'^$', 'rapidsms.views.dashboard', name='rapidsms-dashboard'),
# RapidSMS contrib app URLs
(r'^ajax/', include('rapidsms.contrib.ajax.urls')),
(r'^export/', include('rapidsms.contrib.export.urls')),
(r'^httptester/', include('rapidsms.contrib.httptester.urls')),
(r'^locations/', include('rapidsms.contrib.locations.urls')),
(r'^messagelog/', include('rapidsms.contrib.messagelog.urls')),
(r'^messaging/', include('rapidsms.contrib.messaging.urls')),
(r'^registration/', include('rapidsms.contrib.registration.urls')),
(r'^scheduler/', include('rapidsms.contrib.scheduler.urls')),
)
if settings.DEBUG:
urlpatterns += patterns('',
# helper URLs file that automatically serves the 'static' folder in
# INSTALLED_APPS via the Django static media server (NOT for use in
# production)
(r'^', include('rapidsms.urls.static_media')),
)

View File

@ -1,3 +1,3 @@
-e svn+http://code.djangoproject.com/svn/django/branches/releases/1.1.X/#egg=django
-e bzr+http://code.0xdb.org/python-oxdjango/#egg=python-oxdjango
# -e svn+http://code.djangoproject.com/svn/django/branches/releases/1.1.X/#egg=django
-e bzr+http://code.0xdb.org/python-ox/#egg=python-ox
South