def render_POST(self, request): lat = request.args["lat"][0]; lon = request.args["lon"][0]; accuracy = request.args["accuracy"][0]; #uid = request.getSession().uid; uid = request.getCookie('uid') print "saving: %s: %s,%s (%s)" % (uid, lat, lon, accuracy) record = Record(LAYER, uid, lat, lon, accuracy=accuracy) client.add_record(record) return json.dumps(record.to_dict())
def create_record(json, mood): """ Create a SimpleGeo record from a mood and tweet """ # get the coordinates coors = json['geo']['coordinates'] # make a python timestamp timestamp = int( time.mktime( time.strptime(json['created_at'], "%a, %d %b %Y %H:%M:%S +0000"))) # new record record = Record( layer=SIMPLE_GEO_LAYER, # making it unique by tweetid_mood id="%s_%s" % (json['id'], mood), lat=coors[0], lon=coors[1], created=timestamp, # storing the mood for searching mood=mood) return record
def main(): tweet_ids = [] client = Client(MY_OAUTH_KEY, MY_OAUTH_SECRET) my_tweets = tweepy.api.user_timeline(MY_TWITTER_USERNAME) print "\n\n" for tweet in my_tweets: if (tweet.geo): lat = tweet.geo['coordinates'][0] lng = tweet.geo['coordinates'][1] else: lat = 0 lng = 0 if (tweet.place): place_name = tweet.place['full_name'] place_URL = tweet.place['url'] else: place_name = "None" place_URL = "None" tweet_URL = "http://twitter.com/" + tweet.user.screen_name + "/" + str(tweet.id) created_t = tweet.created_at - datetime.timedelta(seconds=7*60*60) created_t = int(time.mktime(created_t.timetuple())) if (tweet.geo): record = Record( layer=MY_LAYER, id=str(tweet.id), lat=lat, lon=lng, created=created_t, text=tweet.text, URL=tweet_URL, type="object" ) print "\nCreated record with ID: %s" % record.id records.append(record) for chunk in chunker(records, 90): client.add_records(MY_LAYER, chunk) print "\n%s records added" % len(chunk)
def test_record_from_dict(self): record_dict = {'created': 10, 'geometry' : { 'type' : 'Point', 'coordinates' : [10.0, 11.0] }, 'id' : 'my_id', 'type' : 'Feature', 'properties' : { 'layer' : 'my_layer', 'key' : 'value' , 'type' : 'object' } } record = Record.from_dict(record_dict) self.assertEquals(record.created, record_dict['created']) self.assertEquals(record.lat, 11.0) self.assertEquals(record.lon, 10.0) self.assertEquals(record.id, 'my_id') self.assertEquals(record.layer, 'my_layer') self.assertEquals(record.key, 'value') self.assertEquals(record.type, 'object')
def test_record_from_dict(self): record_dict = { 'created': 10, 'geometry': { 'type': 'Point', 'coordinates': [10.0, 11.0] }, 'id': 'my_id', 'type': 'Feature', 'properties': { 'layer': 'my_layer', 'key': 'value', 'type': 'object' } } record = Record.from_dict(record_dict) self.assertEquals(record.created, record_dict['created']) self.assertEquals(record.lat, 11.0) self.assertEquals(record.lon, 10.0) self.assertEquals(record.id, 'my_id') self.assertEquals(record.layer, 'my_layer') self.assertEquals(record.key, 'value') self.assertEquals(record.type, 'object')