示例#1
0
    def setUp(self):
        self.client = Client(config.MY_OAUTH_KEY, config.MY_OAUTH_SECRET, host=config.API_HOST, port=config.API_PORT)
        self.known_points = {
            'darrell_k_royal_stadium': {
                'lat': 30.283863,
                'lon': -97.732519,
                'expected_response': EXPECTED_RESPONSES['darrell_k_royal_stadium']
            },
            'att_park': {
                'lat': 37.778434,
                'lon': -122.389146,
                'expected_response': EXPECTED_RESPONSES['att_park']
            },
            'invesco_field': {
                'lat': 39.744026,
                'lon': -105.019893,
                'expected_response': EXPECTED_RESPONSES['invesco_field']
            }
        }

        # Request known points.
        self.known_requests = []
        for (point_name, point) in self.known_points.iteritems():
            point['name'] = point_name
            response = self.client.context.get_context(point['lat'], point['lon'])
            self.known_points[point_name]['response'] = response
            self.known_requests.append((point, response))

        # Request random points.
        self.random_requests = []
        for i in range(10):
            (lat, lon) = random_lat_lon()
            point = {'lat': lat, 'lon': lon}
            response = self.client.context.get_context(lat, lon)
            self.random_requests.append((point, response))
示例#2
0
 def setUp(self):
     self.client = Client(MY_OAUTH_KEY,
                          MY_OAUTH_SECRET,
                          host=API_HOST,
                          port=API_PORT)
     self.query_lat = D('37.8016')
     self.query_lon = D('-122.4783')
示例#3
0
 def test_get_feature_useful_validation_error_message(self):
     c = Client('whatever', 'whatever')
     try:
         c.get_feature('wrong thing')
     except TypeError, e:
         self.failUnless(
             str(e).startswith('simplegeohandle is required to match '),
             str(e))
示例#4
0
 def calculate_timezone(self):
     from simplegeo import Client
     client = Client('oauth key', 'oauth secret SHH')
     response = client.context.get_context_by_address(self.location)
     for feature in response['features']:
         if feature['classifiers'][0]['category'] == 'Time Zone':
             timezone = feature['name']
     self.timezone = timezone
     self.put()
示例#5
0
def im_moody(mood_words):
    """
        Main mood searching def. This will ping the twitter search api
        every [SLEEP_TIME] seconds and find tweets that display a mood, and
        have a location
    """

    # Found it easier to store the parameters as a list
    # so I can update the since_id
    params_list = ["q=query", "rpp=100", "since_id=1"]

    # Get the SimpleGeo Client
    client = Client(SIMPLE_GEO_TOKEN, SIMPLE_GEO_SECRET)

    # update the query to the mood words
    params_list[0] = "q=%s" % '+OR+'.join(mood_words)

    while True:

        # Init an empty list of records
        records = []

        # Search twitter
        json = get_twitter_search_json('&'.join(params_list))

        # if we got something back
        if json:

            # store the results
            results = json["results"]

            # set the since_id so we don't search more than we need
            params_list[2] = "since_id=%s" % json['max_id']

            # if we got at least 1 result
            if len(results) > 0:

                # get the SimpleGeo records from the api
                records = get_records(results)
        else:

            print "API Error: No data returned"

        # Save 90 records at a time
        for chunk in chunker(records, 90):

            # add records to the SimpleGeo Layer
            client.add_records(SIMPLE_GEO_LAYER, chunk)

            # how many records added
            print "%s %s records added" % (len(chunk), mood_words[0])

        # Wait x seconds before continuing
        time.sleep(SLEEP_TIME)
示例#6
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)
示例#7
0
import cherrypy
import pymongo
import urllib2
from simplegeo import Client
from pymongo import Connection
from Cheetah.Template import Template


connection = Connection()
db = connection['meetme']
client = Client('p2R3QHMxH3xZV6SAgeTdb6sqrxG6Qk8f','XbF4sZxLyhNDMzjykHmVysbzYtnbEtCn')


class Index(object):
    def group(self,name="",error=""):

        group_collection = db.Groups
        group = group_collection.find_one({"name":name})

        grouppage_t = open('grouppage.tmpl', 'r')
        self.grouppage_template = grouppage_t.read()

        g_exist = self.group_exist(name)
        if g_exist > 0:
            max_num = group["max"]
            cur_num = group["joined"]
            namespace = {"cur_num":cur_num,"max_num":max_num}
            namespace["error"] = error
            namespace["name"] = name

            if g_exist == 1:
示例#8
0
 def setUp(self):
     self.client = Client(MY_OAUTH_KEY,
                          MY_OAUTH_SECRET,
                          host=API_HOST,
                          port=API_PORT)
     self.handle = 'SG_4H2GqJDZrc0ZAjKGR8qM4D'
示例#9
0
 def setUp(self):
     self.client = Client(MY_OAUTH_KEY,
                          MY_OAUTH_SECRET,
                          host=API_HOST,
                          port=API_PORT)