Exemple #1
0
 def setUp(self):
     self.score = GameScore(score=1337,
                            player_name='John Doe',
                            cheat_mode=False)
     self.sao_paulo = City(name='São Paulo',
                           location=GeoPoint(-23.5, -46.6167))
     self.collected_item = CollectedItem(type="Sword", isAwesome=True)
 def objectFromJSON(event):
   try:
     parse_event = Event()
     if isInvalidAttribute(event['event_name']):
       return
     parse_event.title = event['event_name']
     if isInvalidAttribute(event['web_description']):
       return
     parse_event.description = event['web_description']
     if isInvalidAttribute(str(event['event_id'])):
       return
     parse_event.eventId = str(event['event_id'])
     try:
       parse_event.location = GeoPoint(latitude=float(event['geocode_latitude']), longitude=float(event['geocode_longitude']))
     except:
       print "Invalid lat/long"
     if isInvalidAttribute(event['street_address']):
       return
     parse_event.address = event['street_address']
     if isInvalidAttribute(event['venue_name']):
       return
     parse_event.venueName = event['venue_name']
     if isInvalidAttribute(event['date_time_description']):
       return
     parse_event.startTime = event['date_time_description']
     parse_event.photoURL = DEFAULT_PHOTO
     if isInvalidAttribute(event['category']):
       return
     parse_event.category = event['category']
     if isInvalidAttribute(event['event_detail_url']):
       return
     parse_event.eventURL = event['event_detail_url']
     return parse_event
   except KeyError:
     print "We missed a key!"
Exemple #3
0
 def setUp(self):
     self.now = datetime.datetime.now()
     self.score = GameScore(score=1337,
                            player_name='John Doe',
                            cheat_mode=False,
                            date_of_birth=self.now)
     self.sao_paulo = City(name='São Paulo',
                           location=GeoPoint(-23.5, -46.6167))
Exemple #4
0
 def new(self, lat, lon, distance, duration):
     self.location = GeoPoint(latitude=lat, longitude=lon)
     self.time = datetime.datetime.now()
     global u
     self.user = u
     self.distance = distance
     self.duration = duration
     self.save()
Exemple #5
0
def fakeOneLocation(exampleLoc, lat, lon):
    '''
    use like this...
    fakeOneLocation(getRunnerQuerySet()[0], 42.0588, -122.3334)
    '''
    exampleLoc.location = GeoPoint(latitude=lat, longitude=lon)
    exampleLoc.time = datetime.datetime.now()
    exampleLoc.save()
Exemple #6
0
def fakeNewRunFromCSV(csvLines, updateFrequency, length, objID, username, pwd,
                      delay):
    '''
    use like this...
    fakeNewLocations(runnerLocations, 1, 40)
    runnerLocations is the query,
    1 is going to send the next location every 1 second,
     and will do this for 40 seconds
    '''
    sleep(delay)
    u = User.login(username, pwd)
    updateNum = 0
    for line in csvLines[1:]:
        lat, lon, time, username, user_objid, dist, runT, speed = line.strip(
        ).split(",")
        rl = RunnerLocations(location=GeoPoint(latitude=float(lat),
                                               longitude=float(lon)),
                             time=datetime.datetime.now(),
                             user=u,
                             distance=float(dist),
                             duration=runT,
                             speed=float(speed))
        rl.save()

        base_url = 'https://crowdcheerdb.herokuapp.com/parse/classes/CurrRunnerLocation/' + objID
        header = {
            'X-Parse-Application-Id':
            'QXRTROGsVaRn4a3kw4gaFnHGNOsZxXoZ8ULxwZmf',
            'Content-type': 'application/json'
        }
        data = {
            "speed": float(speed),
            "duration": runT,
            "distance": float(dist),
            "location": {
                "__type": "GeoPoint",
                "latitude": float(lat),
                "longitude": float(lon)
            },
            "time": {
                "__type": "Date",
                "iso": datetime.datetime.utcnow().isoformat()
            }
        }
        resp = requests.put(base_url, headers=header, data=json.dumps(data))
        print resp.json()
        print "updated %s times" % updateNum
        print "location : %s, lat : %s, lon : %s" % (rl.location, lat, lon)
        print "speed : %s , distance : %s , duration : %s" % (
            rl.speed, rl.distance, rl.duration)
        updateNum += 1
        if (updateNum > length):
            break
        sleep(updateFrequency)
Exemple #7
0
def fakeNewCheerFromCSV(csvLines, updateFrequency, length, objID, username,
                        pwd):
    '''
    use like this...
    fakeNewLocations(runnerLocations, 1, 40)
    runnerLocations is the query,
    1 is going to send the next location every 1 second,
     and will do this for 40 seconds
    '''
    u = User.login(username, pwd)
    updateNum = 0
    for line in csvLines[1:]:
        lat, lon, time, username, user_objid, dist, runT = line.strip().split(
            ",")
        sl = SpectatorLocations(location=GeoPoint(latitude=float(lat),
                                                  longitude=float(lon)),
                                time=datetime.datetime.now(),
                                user=u,
                                distance=float(dist),
                                duration=runT)
        sl.save()

        base_url = 'https://crowdcheerdb.herokuapp.com/parse/classes/CurrSpectatorLocation/' + objID
        header = {
            'X-Parse-Application-Id':
            'QXRTROGsVaRn4a3kw4gaFnHGNOsZxXoZ8ULxwZmf'
        }
        data = {
            "duration": runT,
            "distance": float(dist),
            "location": {
                "__type": "GeoPoint",
                "latitude": float(lat),
                "longitude": float(lon)
            }
        }
        resp = requests.put(base_url, headers=header, data=json.dumps(data))
        print resp
        print "updated %s times" % updateNum
        print "distance : %s , duration : %s" % (sl.distance, sl.duration)
        updateNum += 1
        if (updateNum > length):
            break
        sleep(updateFrequency)
 def objectFromJSON(event, category):
     try:
         parse_event = Event()
         if isInvalidAttribute(event['title']):
             return
         parse_event.title = event['title']
         if isInvalidAttribute(event['description']):
             return
         parse_event.description = event['description']
         if isInvalidAttribute(event['id']):
             return
         parse_event.eventId = event['id']
         try:
             parse_event.location = GeoPoint(
                 latitude=float(event['latitude']),
                 longitude=float(event['longitude']))
         except:
             print "Invalid lat/long"
         if isInvalidAttribute(event['venue_address']):
             return
         parse_event.address = event['venue_address']
         if isInvalidAttribute(event['venue_name']):
             return
         parse_event.venueName = event['venue_name']
         if isInvalidAttribute(event['start_time']):
             return
         parse_event.startTime = event['start_time']
         if not getPhotoURL(event):
             return
         parse_event.photoURL = getPhotoURL(event)
         if isInvalidAttribute(event['url']):
             print "We f****d this up."
             return
         parse_event.eventURL = event['url']
         parse_event.category = category
         return parse_event
     except KeyError:
         print "We missed a key!"
Exemple #9
0
 def setUp(self):
     self.score = GameScore(score=1337,
                            player_name='John Doe',
                            cheat_mode=False)
     self.sao_paulo = City(name='São Paulo',
                           location=GeoPoint(-23.5, -46.6167))
Exemple #10
0
    u'信義區': '8cbb344b-83d2-4176-9abd-d84508e7dc73',
    u'南港區': '7b955414-f460-4472-b1a8-44819f74dc86',
    u'萬華區': '5697d81f-7c9d-43fc-a202-ae8804bbd34b'
}

register(APPLICATION_ID, REST_API_KEY)


class TrashCanSTG(Object):
    pass


for key, value in dict.iteritems():

    url = root + value

    response = urllib2.urlopen(url).read().decode('utf8')

    data = json.loads(response)

    items = data["result"]["results"]

    for item in items:
        trashcanItem = TrashCanSTG(address=item[u'段、號及其他註明'],
                                   region=key,
                                   road=item[u'路名'],
                                   memo=item[u'備註'])
        trashcanItem.location = GeoPoint(latitude=float(item[u'緯度']),
                                         longitude=float(item[u'經度']))
        trashcanItem.save()
Exemple #11
0
# Test file for python parse object creation
# Author: Jacob Cole

execfile("../../pythonParseConnect.py"
         )  # alternative to import for file in different directory
from parse_rest.datatypes import Object, GeoPoint
from parse_rest.core import ParseError


# intialization
class Restaurant(Object):
    pass


restaurant = Restaurant(name="Los Pollos Hermanos")
# coordinates as floats.
restaurant.location = GeoPoint(latitude=12.0, longitude=-34.45)

try:
    restaurant.save()
    restaurants = restaurant.Query.all()
    for res in restaurants:
        print res.objectId
except ParseError:
    print 'Failed to create new object, with error message: '
Exemple #12
0
from parse_rest.connection import register
from parse_rest.datatypes import Object,GeoPoint

APP_ID  = "APP_ID"   # YOUR_APP_ID
REST_ID = "REST_KEY"   # YOUR_REST_KEY

register(APP_ID,REST_ID)                              # Register App

ser = serial.Serial('/dev/ttyACM0',9600,timeout=0) # This is for Linux 

class TempScore(Object):                           # Demo Object 
	pass


interval =10   # time interval 

while 1 :
 try:
  temperature = ser.readline()    # reading temperature valure from PORT
  latitude  = 20.0  	          # example Latitude and Longitude for GeoPoint
  longitude = 77.0 
  print 'Temperature'+temperature+" "    
  gameScore = TempScore(temperatures=temperature)  # saving temperature to temperatures column
  gameScore.location= GeoPoint(latitude,longitude) 
  gameScore.save()                                 # final value commit to Parse
  time.sleep(interval)                             # sleep interval
 except IOError:
  print("Something Went Wrong")                    #if there anything IO error occur


Exemple #13
0
 def find_nearest(self, weighted_tweet):
     res = Venue.Query.filter(location__nearSphere=GeoPoint(
         *weighted_tweet.geotag)).limit(1)
     print "Got venues: {}".format(res)
     return res[0]