def handle(self, *args, **options): first_row = True with open(args[0], 'rb') as csvfile: for row in csv.reader(csvfile, delimiter=','): if row[0] and not first_row: location = row[1]+","+row[0] needs = row[2:5] for need in needs: if need: data = dict() data['from_num'] = '1111' _type = sms._find_type(needs[0]) if _type: data['type'] = sms._find_type(needs[0]) data['_id'] = uid_gen() data['words'] = map(lambda w: w.lower().strip(), need.split(' ')) data['loc_input'] = location res = geocode(data['loc_input']) if res: place, loc, score = res data.update({'loc':loc, 'loc_place':place, 'loc_score':score}) data['created'] = 1333425600 db['needs'].save(data) first_row = False
def _confirm(request, data): location = request.REQUEST.get('Body', '') address = location res = geocode(address.strip().lower(), request.REQUEST.get('FromCountry', '').lower()) r = twiml.Response() if res: place, loc, score = res db['needs'].update({'_id':data['_id']}, {'$set': {'loc':loc, 'loc_place':place, 'loc_input':location, 'loc_score':score, 'session': None}}) if data.get('type', None): count = db['needs'].find({'loc_place':place, 'type':data['type']}).count() if count>1: r.sms('There are %s needs for %s in your area. Hopefully someone will take action.' % (count, data['type'].lower())) else: r.sms('You are the first person to report the need for %s in your area. Thank you!' % data['type'].lower()) else: r.sms('Thank you! Your need is registered') else: r.sms('We do not understand where %s is. Please try again.' % location) return HttpResponse(str(r))
def init_data(request): types = get_types() min_time_res = db["needs"].find({"created": {"$exists": True}}).sort("created", 1).limit(1) if min_time_res.count() > 0: min_time = min_time_res[0]["created"] - 7 * 24 * 3600 else: min_time = 1325376000 continents = copy.deepcopy(CONTINENTS) for continent in continents: for country in db["countries"].find({"continent": continent["abbrev"]}).sort("country", 1): if "latlng" not in country or country["latlng"] == None: res = geocode(country["country"]) if res: place, latlng, score = res country["latlng"] = latlng else: print "No geocode for: %s" % country["country"] country["latlng"] = None db["countries"].save(country) if "area" in country and country["area"] > 0: pop_log = int(math.log(abs(country["area"]), 12)) else: pop_log = 4 continent["countries"].append( {"country": country["country"], "latlng": country["latlng"], "zoom": 10 - pop_log} ) chart_data = copy.deepcopy(_chart_data()) chart_data.append([int(time.time() * 1000), 0]) params = dict(types=types, min_time=min_time, continents=continents, chart_data=chart_data) return HttpResponse(json.dumps(params), content_type="application/json")
def handle(self, *args, **options): for num in range(0, 1000): data = dict() data['from_num'] = num data['type'] = random.choice(get_types()) data['created'] = self.random_time() data['_id'] = uuid.uuid4().hex data['words'] = [data['type'].lower()] country = self.random_country() data['country'] = country.get('iso', None) data['loc_input'] = '%s, %s' % (country['capital'], country['country']) res = geocode(data['loc_input']) if res: place, loc, score = res data.update({'loc':loc, 'loc_place':place, 'loc_score':score}) db.needs.insert(data)
def handle(self, *args, **options): if len(args)==2: print geocode(args[0], args[1]) else: print geocode(args[0])