How to use AKBusGpsParser

step 01:

sudo easy_install AKBusGpsParser

step02: Let's see a sample

#!/usr/bin/python
#coding:UTF-8
#-----------------------------------------
#-- Name : AKBusGpsParser
#-- ORG : Landpack
#-- Author : Frank AK
#-- Addr : Design In IMUT
#-- Email : landpack@sina.com
#-----------------------------------------
import MySQLdb
from AKBusGpsParser import *
#------------------------------------------------
if __name__ == '__main__': url="http://192.168.0.202/zsgj/Service/Common/onBusRealChanged"
line_id_dict={'x1':'','x2':'','h1':'',
'h2':'','k1':'','K1':'',
'K2':'','k2':'','k4':'',
'K4':'','k5':'','K5':''}
sample_gps = """*|GPS|1729|K2|2006-01-04|13:15:08|6000.0000|2000.0000\
|40|140|4|5|1|2006-01-04|13:01:04|0|0|0|01000932|1|#*"""
sample_stn="*|STN|1728|K4|2006-01-04|13:15:23|2|0|1|#" sourcekeys_gps=['star','cmd','bus_no','line_no','gps_date','gps_time','latitude','longitude','speed',
'angle','next_station','people_num','start_end_flag','send_date','send_time',
'direction','run_status','leave_flag','driver_no','driver_flag']
sourcekeys_stn=['star','cmd','bus_no','line_no','stn_date','stn_time','station_no','flag','direction'] insertkeys_gps=['star','cmd','bus_no','line_no','gps_datetime','latitude','longitude','speed',
'angle','next_station','people_num','start_end_flag',
'send_datetime','direction','run_status','leave_flag',
'driver_no','driver_flag']
insertkeys_stn=['star','cmd','bus_no','line_no','direction','stn_dt','flag','station_no'] insertruler_gps=['s','s',1,'s','s',9,'s',1]
insertruler_stn=['s','s',4] updatekeys_gps=['start','cmd','bus_no','line_id','gps_datetime','longitude','latitude','next_station','direction']
updatekeys_stn=['start','cmd','bus_no','line_id','station_no','stn_dt','flag','direction'] updateruler_gps=['s',1,1,'s','s',1,1]
updateruler_stn=['s',5] myflag='|' db=MySQLdb.connect("localhost","your_name","your_passwd","database_name")
cur=db.cursor()
BGP=BusGpsParser(db,cur)
BGP.load(sample_gps,sourcekeys_gps,line_id_dict)
BGP.parser(myflag) BGP.recondition(insertkeys_gps)
insert_data=BGP.wrap(insertruler_gps)
myitem=BGP.items()
sqldup=BGP.equal_value() gps_tn=BGP.tableName('gps')
sql_insert="""INSERT INTO `%s` %s VALUES %s ON DUPLICATE KEY UPDATE %s;""" % (gps_tn,myitem,insert_data,sqldup)
BGP.save(sql_insert) BGP.recondition(updatekeys_gps)
update_data=BGP.wrap(updateruler_gps)
myitem=BGP.items()
sqldup=BGP.equal_value()
sql_update="""INSERT INTO bus_gps %s VALUES %s ON DUPLICATE KEY UPDATE %s;""" % (myitem,update_data,sqldup)
BGP.update(sql_update) BGP.load(sample_stn,sourcekeys_stn,line_id_dict)
BGP.parser(myflag) BGP.recondition(insertkeys_stn)
insert_data=BGP.wrap(insertruler_stn)
myitem=BGP.items()
sqldup=BGP.equal_value()
stn_tn=BGP.tableName('stn')
sql_insert="""INSERT INTO `%s` %s VALUES %s ON DUPLICATE KEY UPDATE %s;""" % (stn_tn,myitem,insert_data,sqldup)
BGP.save(sql_insert) BGP.recondition(updatekeys_stn)
update_data=BGP.wrap(updateruler_stn)
myitem=BGP.items()
sqldup=BGP.equal_value()
sql_update="""INSERT INTO bus_stn %s VALUES %s ON DUPLICATE KEY UPDATE %s;""" % (myitem,update_data,sqldup)
BGP.update(sql_update)
BGP.post(url)
上一篇:CJOJ 1976 二叉苹果树 / URAL 1018 Binary Apple Tree(树型动态规划)


下一篇:C语言-字符操作函数