コード例 #1
0
def movement_reader(ifile, bsmap):
    """ An iterator to read personal daily data.
    """
    assert isinstance(bsmap, BaseStationMap)

    buf_ts = []
    buf_lc = []
    buf_cr = []
    last_uid = None
    last_day_start = None

    def check_time_alignment():
        if len(buf_ts) == 0:
            return False
        if buf_ts[-1] != buf_ts[0] + 86400:
            buf_ts.append(buf_ts[0] + 86400)
            buf_lc.append(buf_lc[0])
            buf_cr.append(buf_cr[0])
        return True

    for line in ifile:
        if isinstance(line, str):
            if line.startswith('#'):
                continue
            line = line.strip('\r\n ')
            uid, ts, loc = line.split(',')[0:3]
        elif isinstance(line, tuple):
            uid, ts, loc = line

        uid = int(uid)
        ts = int(float(ts))
        loc = int(loc)
        day_start, day_end = drange(ts)
        coord = bsmap.get_coordinates(loc)

        if not in_area(coord, HZ_LB, HZ_RT):
            continue

        if last_uid is None or uid == last_uid and day_start == last_day_start:
            buf_ts.append(ts)
            buf_lc.append(loc)
            buf_cr.append(coord)
        else:
            if check_time_alignment():
                yield PersonMoveDay(last_uid, last_day_start, buf_ts, buf_lc, buf_cr)

            buf_ts = [ts]
            buf_lc = [loc]
            buf_cr = [coord]

        last_uid = uid
        last_day_start = day_start

    if check_time_alignment():
        yield PersonMoveDay(last_uid, last_day_start, buf_ts, buf_lc, buf_cr)
コード例 #2
0
def movement_reader(fname, bsmap):
    """ An iterator to read personal daily data.
    """
    assert isinstance(bsmap, BaseStationMap)

    buf_ts = []
    buf_lc = []
    buf_cr = []
    last_uid = None
    last_day_start = None

    def check_time_alignment():
        if buf_ts[-1] != buf_ts[0] + 86400:
            buf_ts.append(buf_ts[0] + 86400)
            buf_lc.append(buf_lc[0])
            buf_cr.append(buf_cr[0])

    for line in open(fname, 'rb'):
        line = line.strip('\r\n ')

        if line.startswith('#'): continue

        uid, ts, loc = line.split(',')[0:3]
        uid = int(uid)
        ts = int(float(ts))
        loc = int(loc)
        day_start, day_end = drange(ts)
        coord = bsmap.get_coordinates(loc)

        if not in_area(coord, HZ_LB, HZ_RT):
            continue

        if last_uid is None or uid == last_uid and day_start == last_day_start:
            buf_ts.append(ts)
            buf_lc.append(loc)
            buf_cr.append(coord)
        else:
            check_time_alignment()
            yield PersonMoveDay(last_uid, last_day_start, buf_ts, buf_lc, buf_cr)

            buf_ts = [ts]
            buf_lc = [loc]
            buf_cr = [coord]

        last_uid = uid
        last_day_start = day_start

    check_time_alignment()
    yield PersonMoveDay(last_uid, last_day_start, buf_ts, buf_lc, buf_cr)
コード例 #3
0
def scrape_for_apartments():
    #get results from craiglist
    cl_h = CraigslistHousing(site=settings.CL_SITE, area=settings.CL_AREA, category=settings.CL_CATEGORY,
                             filters={'bundle_duplicates': True,
                                      'posted_today': settings.POSTED_TODAY,
                                      'min_bedrooms': settings.MIN_NUM_BEDROOMS,
                                      'max_bedrooms': settings.MAX_NUM_BEDROOMS,
                                      # 'cats_ok': settings.CATS_OK,
                                      'max_price': settings.MAX_PRICE,
                                      'min_price': settings.MIN_PRICE,
                                      'laundry': settings.LAUNDRY_OPTIONS#,
                                      #'parking': settings.PARKING_OPTIONS
                                      #'housing_type': settings.HOUSING_TYPE
                                      })
    #adding a counter to limit the amount of results that can be sent at one time
    counter = 0
    for result in cl_h.get_results(sort_by='newest', geotagged=True):
        if check_for_record(result):
            continue
        else:
            counter += 1
            geotag = result["geotag"]
            #set blank area
            area = ""
            for a, coords in settings.AREAS.items():
                print(result);
                if geotag is not None and in_area(geotag, coords):
                    area = a
            #couldn't find from Geotag, string search the listing
            if area == "":
                # print settings.NEIGHBORHOODS
                for hood in settings.NEIGHBORHOODS:
                    if result["where"] is not None and hood in result["where"].lower():
                        area = hood
            if area != '' and counter < 10:
                store_in_db(result)
                client = Client(settings.ACCOUNT_SID, settings.AUTH_TOKEN)
                text = "{} per month in {}.\n {}".format(result['price'], result['where'], result["url"])
                message = client.messages.create(
                                messaging_service_sid=settings.MS_SID,
                                body=text,
                                to=settings.TARGET_PHONE_NUMBER)