Beispiel #1
0
def filter_consumption_records(data, formulation_names):
    def filter_func(x):
        for f in formulation_names:
            if f in x[FORMULATION]:
                return True
        return False

    return pydash.select(data.get(C_RECORDS, []), filter_func)
Beispiel #2
0
def filter_consumption_records(data, formulation_names):
    def filter_func(x):
        for f in formulation_names:
            if f in x[FORMULATION]:
                return True
        return False

    return pydash.select(data.get(C_RECORDS, []), filter_func)
Beispiel #3
0
    def for_each_facility(self, data, combination, previous_cycle_data=None):
        result = NOT_REPORTING

        values = values_for_records(self.fields, data.get(C_RECORDS, []))
        number_of_consumption_record_blanks = len(
            pydash.select(values, lambda v: v is None))

        c_count_ = data.get(C_COUNT, 0)
        a_count_ = data.get(A_COUNT, 0)
        p_count_ = data.get(P_COUNT, 0)
        if c_count_ == 0 and a_count_ == 0 and p_count_ == 0:
            return result
        if c_count_ < 25 or a_count_ < 22 or p_count_ < 7:
            result = NO
        elif number_of_consumption_record_blanks > 2:
            result = NO
        else:
            result = YES
        return result
Beispiel #4
0
    def for_each_facility(self, data, combination, previous_cycle_data=None):
        result = NOT_REPORTING

        values = values_for_records(self.fields, data.get(C_RECORDS, []))
        number_of_consumption_record_blanks = len(pydash.select(
            values, lambda v: v is None))

        c_count_ = data.get(C_COUNT, 0)
        a_count_ = data.get(A_COUNT, 0)
        p_count_ = data.get(P_COUNT, 0)
        if c_count_ == 0 and a_count_ == 0 and p_count_ == 0:
            return result
        if c_count_ < 25 or a_count_ < 22 or p_count_ < 7:
            result = NO
        elif number_of_consumption_record_blanks > 2:
            result = NO
        else:
            result = YES
        return result
Beispiel #5
0
def get_combination(combinations, name):
    return pydash.select(combinations, lambda x: x[NAME] == name)[0]
Beispiel #6
0
EMAIL = '<cloudflare email address>'
DOMAIN = '<domain>'  # nathancahill.com
SUBDOMAIN = '<subdomain>'  # home
LOCAL = '<local ip address>'  # 192.168.0.3

data = dict(
        a='rec_load_all',
        tkn=KEY,
        email=EMAIL,
        z=DOMAIN
    )

res = requests.post('https://www.cloudflare.com/api_json.html', data=data)
records = res.json()['response']['recs']['objs']

home =  _.select(records, dict(name='%s.%s' % (SUBDOMAIN, DOMAIN)))[0]

if socket.gethostbyname(socket.gethostname()) != LOCAL:
    sys.exit()

ip = requests.get('http://httpbin.org/ip').json()['origin']

data = dict(
        a='rec_edit',
        tkn=KEY,
        email=EMAIL,
        z=DOMAIN,
        id=home['rec_id'],
        type='A',
        name=SUBDOMAIN,
        content=ip,
def get_combination(combinations, name):
    return pydash.select(combinations, lambda x: x[NAME] == name)[0]
Beispiel #8
0
def fetch(filters, queries, locations, numberOfPages, maxRate, numBedrooms=None, tries=5):
    # base url for the craigslist catogory
    base_url = 'http://losangeles.craigslist.org/search/apa?'

    api_key="6ry0OW6wJFglXoNKrDSaxOSbeni9i9hlvQ8AeTSwy3qmfzNd2w0LdzLWSBYt5RADq+OKUF840wRzj7/HWBLMJQ=="

    pageInc = 100

    apts = []
    for query in queries:
        for page in range(numberOfPages):

            params = list(filters)
            params.append(('query',query))
            params.append(('s',page*pageInc))

            plainUrl = base_url + urllib.urlencode(params,'')
            url = urllib.quote(plainUrl)

            # Setup your REST GET request URL here
            getUrl = 'https://api.import.io/store/data/ae9b3481-fd34-4f31-88dc-ab2c18edde46/_query?input/webpage/url='+url+'&_user=43864eeb-fab1-4163-94ab-29ce26a543e5&_apikey='+urllib.quote(api_key,'')

            print 'FETCHING:'
            print ''
            print 'search:', query
            print ''
            print 'paging:', str(page*pageInc) + "-" + str((page+1)*pageInc)
            print ''
            print 'craigslist url:', plainUrl
            print ''
            print 'import.io API url:', getUrl
            print ''

            noResponse = True
            t = 0
            response = ''
            data = {}
            while ('results' not in data) and (t < tries):
                response = urllib.urlopen(getUrl).read()
                data = json.loads(response)
                t = t+1

            if 'results' in data:
                results = data['results']
                print str(len(results)) + ' results'
                for result in results:
                    # Gather the information you want from your API request
                    if all(key in result for key in ['title/_text', 'title', 'price', 'bedrooms', 'location']):
                        title = result['title/_text']
                        url = result['title']
                        price = float(result['price'].replace(',','').replace('$',''))
                        bedrooms = float(result['bedrooms'].replace('br',''))
                        location = result['location'].lower()
                        apt = {'title':title, 'url':url, 'price':price, 'bedrooms':bedrooms, 'ratio':price/bedrooms, 'location':location}
                        apts.append(apt)
            else:
                print 'FAILURE'
                print data

            print ''
            print '-'*79
            print ''

    def validLoaction(string):
        found = map(lambda loc: string.find(loc) != -1, locations)
        if 1 in found:
            return True
        else:
            return False

    totalResults = len(apts)

    if numBedrooms:
        apts = pydash.select(apts, lambda x: x['bedrooms'] == 1.)

    # sort based on ratio
    sortedApts = pydash.sort_by(apts, lambda x: x['ratio'])

    # filter based on ratio
    filteredApts = pydash.select(sortedApts, lambda x: x['ratio'] <= maxRate and x['ratio'] > 1)

    # filter location strings
    locationApts = pydash.select(filteredApts, lambda x: validLoaction(x['location']))

    # only show the unique results!
    uniqApts = pydash.uniq(locationApts)

    return uniqApts