Example #1
0
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
Example #2
0
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)