Пример #1
0
 def __init__(self, text):
     self.headers = HEADERS
     self.error = COMMEN_ERROR
     self.now_time = datetime.now().strftime('%Y%m%d')
     self.model = ''
     self.people_date = ''
     self.fast_model = fast_model
     self.slow_model = slow_model
     self.all_model = all_model
     self.station = Station()
     self.url = self.__get_query_url(text)
     self.trains_info = []
Пример #2
0
 def load_stations(self):
     # Read excel file and create a list with station objects
     with open('StationsHolland.csv') as csv_file:
         csv_reader = csv.reader(csv_file, delimiter=',')
     
         stations = []
     
         for row in csv_reader:
             stations.append(Station(row[0], row[1], row[2], row[3]))
             plt.plot(float(row[2]), float(row[1]), "bo")
             plt.text(float(row[2]) -0.02, float(row[1])+0.02, row[0], fontsize=5)
         return stations
Пример #3
0
    def handling_requests(self, data):
        print "hereee"

        request = np.array(data.data)

        for i in range(0, len(request), 2):
            cart = Cart(request[i])
            station = request_mapping[Station(request[i + 1])]
            self.directions_info[station] = cart
            self.requests.append(station)

        self.path_finder.publish_path(self.next_goal, self.requests)
Пример #4
0
def read_file():
    list_stations = []
    with open('delhi-metro-stations') as csvfile:
        contents = csv.reader(csvfile)
        for i in contents:
            list_stations.append(''.join(i))
    temp = 0
    key = ' '
    list = []
    flag = True
    while flag:
        if '#' in list_stations[temp]:
            key = list_stations[temp]
        elif 'START' in list_stations[temp] or len(list_stations[temp]) == 0:
            flag = False
        else:
            list1 = []
            list1.append(key)
            if 'Conn' not in list_stations[temp]:
                station = list_stations[temp].split(':')
                for i in station:
                    list1.append(i)
                if len(list_stations[temp + 1]) == 0:
                    list1.append('End')
                elif '#' not in list_stations[temp + 1]:
                    list1.append(list_stations[temp + 1])
                else:
                    list1.append('End')
                list1.append('None')
            else:
                index = list_stations[temp].split(':Conn:')
                m_index = index[0].split(':')
                for i in m_index:
                    list1.append(i)
                if len(list_stations[temp + 1]) == 0:
                    list1.append('End')
                elif '#' not in list_stations[temp + 1]:
                    list1.append(list_stations[temp + 1])
                else:
                    list1.append('End')
                list1.append(index[1])
            list.append(list1)
        temp += 1
    all_stations = [Station(i) for i in list]
    for i in all_stations:
        print(i._Tranfer)
Пример #5
0
      "site_id": "ST4",
      'location':"Vattiyoorkavu",
      "stype":"phc"
    },
    {
      "site_name": "District Centre",
      "site_id": "ST5",
      'location':"Trivandrum",
      "stype":"sc"
    }
]

for s in stations:
    st = session.query(StationType).filter(StationType.code == s['stype']).first()
    l = session.query(Location).filter(Location.name == s['location']).first()
    s = Station(name=s['site_name'],code=s['site_id'],location_id=l.id,station_type_id=st.id)
    session.add(s)
    session.commit()

role_stations = [
{
    'center':'sc',
    'roles': ["sc_user"]
},{
    'center':'phc',
    'roles': ["phc_user"]
}]

for rs in role_stations:
    st = session.query(StationType).filter(StationType.code == rs['center']).first()
    for role in rs['roles']:
Пример #6
0
duration = Slider(title="Duration of the observation (hours)",
                  value=8.0,
                  start=1.0,
                  end=30.0,
                  step=0.25)
elevation_limit = Slider(title="Lowest elevation (degrees)",
                         value=10.0,
                         start=0.0,
                         end=50.0,
                         step=5.0)
# Add checkboxes: include Ar, include eMERLIN, include VLBA, include LBA.
outstations = CheckboxGroup(labels=["eMERLIN", "VLBA", "LBA", "KVN"],
                            active=[])

# Reading all stations
all_stations = Station.stations_from_file(
    path.dirname(__file__) + '/station_location.txt')

# Default parameters
source_coord = coord.SkyCoord('00h00m00s +00d00m00s')
times_obs = get_obs_times(get_time('01/01/2018 00:00'), duration.value)
selected_stations = copy.deepcopy(stations[type_array.value])
selected_all_stations = stations['EVN'] + stations['eMERLIN'] + stations['VLBA'] + stations['LBA']\
                + stations['KVN']


# Set up callbacks
def update_data(attrname, old, new):
    # get tge current slider values
    # print(outstations.active)
    # print(stations[type_array.value])
    selected_stations = copy.deepcopy(stations[type_array.value])
Пример #7
0
    rfcBand = 's'
elif args.band in ['c', 'm']:
    rfcBand = 'c'
elif args.band == 'x':
    rfcBand = 'x'
elif args.band == 'u':
    rfcBand = 'u'
elif args.band in ['k', 'q']:
    rfcBand = 'k'
else:
    #not a known band?
    print("Error band {} is unknown.".format(args.band))
    sys.exit(2)

#load station information for all stations.
stationList = Station.stations_from_file('./station_location.txt')
stations = [stationList[station.upper()] for station in args.stations]

obsTimes = get_obs_times(get_time(args.timeStart), args.duration)

sourceCat = load_rfc_cat("./rfc_2018c_cat.txt", rfcBand, args.min_flux)
sources = get_up_sources(stations,
                         sourceCat,
                         obsTimes,
                         minEl=args.min_el,
                         minFluxBand=rfcBand)

#ask which source to plot
while True:
    print()
    print_sources(sources)
Пример #8
0
elif args.band in ['c','m']:
    rfcBand = 'c'
elif args.band == 'x':
    rfcBand = 'x'
elif args.band == 'u':
    rfcBand = 'u'
elif args.band in ['k','q']:
    rfcBand = 'k'
else:
    #not a known band?
    print("Error band {} is unknown.".format(args.band))
    sys.exit(2)


#load station information for all stations.
stationList = Station.stations_from_file(directory+'/station_location.txt')
stations = [stationList[station.upper()] for station in args.stations]

obsTimes = get_obs_times(get_time(args.timeStart), args.duration)

sourceCat = load_rfc_cat(directory+"/rfc_2021c_cat.txt", rfcBand, args.min_flux)
sources = get_up_sources(stations, sourceCat, obsTimes, minEl=args.min_el, minFluxBand=rfcBand)

#ask which source to plot
while True:
    print()
    print_sources(sources)
    srcIndex = input("Please select the source to plot (0-9, q to quit): ")
    if srcIndex == 'q':
        break
    try: srcIndex = int(srcIndex)
Пример #9
0
class SearchTickets(object):
    """docstring for Tickets"""
    def __init__(self, text):
        self.headers = HEADERS
        self.error = COMMEN_ERROR
        self.now_time = datetime.now().strftime('%Y%m%d')
        self.model = ''
        self.people_date = ''
        self.fast_model = fast_model
        self.slow_model = slow_model
        self.all_model = all_model
        self.station = Station()
        self.url = self.__get_query_url(text)
        self.trains_info = []

    def __parse_text(self, text):
        args = str(text).lstrip('查车票').strip().split(' ')
        if len(args) == 3:
            try:
                if len(args[2]) == 8:
                    if int(args[2]) < int(self.now_time):
                        self.error = DATE_ERROR
                    else:
                        self.from_station = self.station.get_telecode(args[0])
                        self.to_station = self.station.get_telecode(args[1])
                        self.train_date = args[2][:4] + '-' + args[2][
                            4:6] + '-' + args[2][-2:]
                else:
                    self.error = FORMAT_ERROR
            except:
                self.error = FORMAT_ERROR
        elif len(args) == 4:
            try:
                if args[0] in self.all_model:
                    if len(args[3]) == 8:
                        if int(args[3]) < int(self.now_time):
                            self.error = DATE_ERROR
                        else:
                            self.model = args[0]
                            self.from_station = self.station.get_telecode(
                                args[1])
                            self.to_station = self.station.get_telecode(
                                args[2])
                            self.train_date = args[3][:4] + '-' + args[3][
                                4:6] + '-' + args[3][-2:]
                    else:
                        self.error = FORMAT_ERROR
                elif int(args[3]) >= 0 and int(args[3]) <= 23:
                    if len(args[2]) == 8:
                        if int(args[2]) < int(self.now_time):
                            self.error = DATE_ERROR
                        else:
                            self.from_station = self.station.get_telecode(
                                args[0])
                            self.to_station = self.station.get_telecode(
                                args[1])
                            self.train_date = args[2][:4] + '-' + args[2][
                                4:6] + '-' + args[2][-2:]
                            self.people_date = args[3]
                    else:
                        self.error = FORMAT_ERROR
            except:
                self.error = FORMAT_ERROR

        elif len(args) == 5:
            try:
                if len(args[3]) == 8:
                    if int(args[3]) < int(self.now_time):
                        self.error = DATE_ERROR
                    else:
                        if args[0] in self.all_model:
                            if int(args[4]) >= 0 and int(args[4]) <= 23:
                                self.model = args[0]
                                self.from_station = self.station.get_telecode(
                                    args[1])
                                self.to_station = self.station.get_telecode(
                                    args[2])
                                self.train_date = args[3][:4] + '-' + args[3][
                                    4:6] + '-' + args[3][-2:]
                                self.people_date = args[4]
                            else:
                                self.error = TIME_ERROR
                        else:
                            self.error = MODEL_ERROR
                else:
                    self.error = FORMAT_ERROR
            except:
                self.error = FORMAT_ERROR

        else:
            self.error = FORMAT_ERROR

    def __fast_info(self, *args):
        info = ('车次:{}\n出发站:{},目的地:{}\n出发时间:{},到达时间:{}\n耗时:{}\n'
                '座位情况:\n一等座:{}\n二等座:{}\n无座:{}\n\n'.format(*args))
        self.trains_info.append(info)

    def __slow_info(self, *args):
        info = ('车次:{}\n出发站:{},目的地:{}\n出发时间:{},到达时间:{}\n耗时:{}\n'
                '座位情况:\n软卧:{}\n硬卧:{}\n硬座:{}\n无座:{}\n\n'.format(*args))
        self.trains_info.append(info)

    def __sort_info(self, train_number, from_station_name, to_station_name,
                    start_time, arrive_time, time_duration, first_class_seat,
                    second_class_seat, soft_sleep, hard_sleep, hard_seat,
                    no_seat):
        if train_number[:1] in self.fast_model:
            self.__fast_info(train_number, from_station_name, to_station_name,
                             start_time, arrive_time, time_duration,
                             first_class_seat, second_class_seat, no_seat)
        elif train_number[:1] in self.slow_model:
            self.__slow_info(train_number, from_station_name, to_station_name,
                             start_time, arrive_time, time_duration,
                             soft_sleep, hard_sleep, hard_seat, no_seat)

    def __get_query_url(self, text):
        '''
        解析传入的text并生成符合12306api的url连接
        :param text: 
        :return: 
        '''
        try:
            self.__parse_text(text)
            url = ('https://kyfw.12306.cn/otn/leftTicket/queryX?'
                   'leftTicketDTO.train_date={}&'
                   'leftTicketDTO.from_station={}&'
                   'leftTicketDTO.to_station={}&'
                   'purpose_codes=ADULT').format(self.train_date,
                                                 self.from_station,
                                                 self.to_station)
            print('url ok')
            return url
        except:
            self.error == URL_ERROR

    def __get_train_html(self):
        r = requests.get(self.url, headers=self.headers, verify=False)
        for x in range(5):
            try:
                return r.json()['data']['result']
            except:
                time.sleep(2)
                print('request ' + x + 'failure')
                continue
        self.error = FORMAT_ERROR
        # return r.json()

    def get_train_info(self):
        '''
        获取微信列车查询返回文本
        :return: 
        '''
        if self.url:
            raw_trains = self.__get_train_html()
            for raw_train in raw_trains:
                data_list = raw_train.split('|')
                train_number = data_list[3]
                from_station_name = self.station.get_name(data_list[6])
                to_station_name = self.station.get_name(data_list[7])
                start_time = data_list[8]
                arrive_time = data_list[9]
                time_duration = data_list[10]
                first_class_seat = data_list[31] or '--'
                second_class_seat = data_list[30] or '--'
                soft_sleep = data_list[23] or '--'
                hard_sleep = data_list[28] or '--'
                hard_seat = data_list[29] or '--'
                no_seat = data_list[33] or '--'
                if self.people_date == '':
                    if self.model == '':
                        self.__sort_info(train_number, from_station_name,
                                         to_station_name, start_time,
                                         arrive_time, time_duration,
                                         first_class_seat, second_class_seat,
                                         soft_sleep, hard_sleep, hard_seat,
                                         no_seat)
                    elif self.model in self.all_model:
                        if self.model == train_number[:1]:
                            self.__sort_info(train_number, from_station_name,
                                             to_station_name, start_time,
                                             arrive_time, time_duration,
                                             first_class_seat,
                                             second_class_seat, soft_sleep,
                                             hard_sleep, hard_seat, no_seat)
                else:
                    if self.model == '':
                        if int(start_time[:2]) >= int(
                                self.people_date) and int(
                                    start_time[:2]) != 24:
                            self.__sort_info(train_number, from_station_name,
                                             to_station_name, start_time,
                                             arrive_time, time_duration,
                                             first_class_seat,
                                             second_class_seat, soft_sleep,
                                             hard_sleep, hard_seat, no_seat)
                    elif self.model in self.all_model:
                        if self.model == train_number[:1]:
                            if int(start_time[:2]) >= int(
                                    self.people_date) and int(
                                        start_time[:2]) != 24:
                                self.__sort_info(
                                    train_number, from_station_name,
                                    to_station_name, start_time, arrive_time,
                                    time_duration, first_class_seat,
                                    second_class_seat, soft_sleep, hard_sleep,
                                    hard_seat, no_seat)

        if len(self.trains_info) == 0:
            return self.error
        else:
            train_info = '显示最新的5条列车信息\n\n' + ''.join(self.trains_info[:5])
            return train_info