Esempio n. 1
0
def main():
        # 保存站到站
        temp_trains = ['C6903','C6905','C6907','C6909','C6911','C6913','C6915','C6917','C6919','C6921','C6923','C6925','C6953','C6955','C6957','C6959','C6961','C6963','C6965','C6967','C6969','C6971','C6973','C6975','C6902','C6904','C6906','C6908','C6910','C6912','C6918','C6920','C6922','C6924','C6926','C6952','C6954','C6956','C6958','C6960','C6962','C6966','C6968','C6970','C6972','C6974','C6976','C6929','C6914','C6928','C6930','C6978','C6964','C6980','C6977','C6979','C6981']
        for code in temp_trains:
            names = DataBaseUtil.select("select name from train_line_stop where train_code = '%s' order by sequence" % code)
            if len(names) >  0:
                key = 0
                name_list = {}
                for n in names:
                    name_list[key] = n[0]
                    key = key+1
                kvs = name_list.items()
                i = -1
                for ki,vi in kvs:
                    i += 1
                    j = -1
                    for kj,vj in  kvs:
                        j += 1
                        if i == j:
                            continue
                        start_station = vi
                        end_station = vj
                        try:
                            start_py = DataService.get_alia_by_station(start_station)
                            if start_py == '':
                                start_py =  py_util.hanzi2pinyin_split(string=start_station, split="", firstcode=False)
                            end_py = DataService.get_alia_by_station(end_station)
                            if end_py == '':
                                end_py =  py_util.hanzi2pinyin_split(string=end_station, split="", firstcode=False)
                            DataService.save_s2s(start_station,start_py,end_station,end_py)
                        except:
                            t, v, tb = sys.exc_info()
Esempio n. 2
0
 def parse_content(self,content,link_job):
     json_obj = json.loads(content)
     data = json_obj['data']['data']
     typeName = data[0]['train_class_name']
     start_time = data[0]['start_time']
     pre_time = start_time
     duration = 0
     name_list = {}
     days = 0
     train_no = link_job.task.train_no
     # 保存站点数据
     for i,d in enumerate(data):
         arrive_time = d['arrive_time']
         depart_time = d['start_time']
         if i==0 :
             arrive_time = 'null'
         if i != 0:
             if compareSS(pre_time,arrive_time)<0:
                 days +=1
             duration = duration + getDaysSS(start_time,d['arrive_time'],days)
             pre_time = arrive_time
             if int(d['station_no'])==1:
                 raise  Exception
         stayTime = 0
         if i!=0 and i!= len(data)-1 :
             stayTime = d['stopover_time']
             try:
                 stayTime = stayTime[0:str(stayTime).index('分')]
             except Exception as e:
                 stayTime=0
                 # raise e
         if i == len(data)-1:
             depart_time = 'null'
         try:
             train_stop = TrainStop(link_job.task.train_code,d['station_name'],int(d['station_no']),arrive_time,stayTime,days,duration,depart_time,typeName,train_no)
             DataService.save_train_stop(train_stop)
             log.info((link_job.task.train_code,d['station_name'],int(d['station_no']),arrive_time,stayTime,days,duration,depart_time,typeName,train_no))
             name_list.update({d['station_no']:d['station_name']})
         except:
             t, v, tb = sys.exc_info()
             log.error("%s,%s,%s" % (t, v, traceback.format_tb(tb)))
     # 保存站到站
     kvs = name_list.items()
     i = -1
     for ki,vi in kvs:
         i += 1
         j = -1
         for kj,vj in  kvs:
             j += 1
             if i == j:
                 continue
             start_station = vi
             end_station = vj
             try:
                 start_py = DataService.get_alia_by_station(start_station)
                 if start_py == '':
                     start_py =  py_util.hanzi2pinyin_split(string=start_station, split="", firstcode=False)
                 end_py = DataService.get_alia_by_station(end_station)
                 if end_py == '':
                     end_py =  py_util.hanzi2pinyin_split(string=end_station, split="", firstcode=False)
                 DataService.save_s2s(start_station,start_py,end_station,end_py)
             except:
                 t, v, tb = sys.exc_info()
                 log.error("%s,%s,%s" % (t, v, traceback.format_tb(tb)))