mirror of
https://github.com/OSURoboticsClub/Rover_2017_2018.git
synced 2025-11-08 18:21:15 +00:00
Add testing file with updated gitignore for jpgs
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -90,3 +90,6 @@ ENV/
|
||||
|
||||
# Google API Key
|
||||
ground_station/resources/core/key
|
||||
|
||||
# Map Images
|
||||
*.jpg
|
||||
|
||||
@@ -27,15 +27,12 @@ from io import StringIO, BytesIO
|
||||
import os
|
||||
import time
|
||||
import PIL.Image
|
||||
import signing
|
||||
|
||||
#####################################
|
||||
# Constants
|
||||
#####################################
|
||||
_KEYS = []
|
||||
file_pointer = open('key', 'w')
|
||||
for i in file_pointer:
|
||||
_KEYS.append(file_pointer.readline().rstrip())
|
||||
file_pointer.close()
|
||||
|
||||
# Number of pixels in half the earth's circumference at zoom = 21
|
||||
_EARTHPIX = 268435456
|
||||
@@ -48,6 +45,13 @@ _GRABRATE = 4
|
||||
# Pixel Radius of Earth for calculations
|
||||
_PIXRAD = _EARTHPIX / math.pi
|
||||
|
||||
file_pointer = open('key', 'r')
|
||||
for i in file_pointer:
|
||||
_KEYS.append(i.rstrip())
|
||||
file_pointer.close()
|
||||
|
||||
print _KEYS
|
||||
|
||||
|
||||
class GMapsStitcher(object):
|
||||
def __init__(self, width, height,
|
||||
@@ -79,11 +83,11 @@ class GMapsStitcher(object):
|
||||
# Make the url string for polling
|
||||
# GET request header gets appended to the string
|
||||
urlbase = 'https://maps.googleapis.com/maps/api/staticmap?'
|
||||
urlbase += 'center=%f%f&zoom=%d&maptype=%s&size=%dx%d&format=jpg&key=%s&signature=%s'
|
||||
urlbase += 'center=%f,%f&zoom=%d&maptype=%s&size=%dx%d&format=jpg&key=%s'
|
||||
|
||||
# Fill the formatting
|
||||
specs = latitude, longitude, self.zoom, self.maptype, _TILESIZE, _KEYS[0], _KEYS[1]
|
||||
filename = 'Resources/Maps/' + ('%f_%f_%d_%s_%d_%d_%s_%s' % specs) + '.jpg'
|
||||
specs = latitude, longitude, self.zoom, self.maptype, _TILESIZE, _TILESIZE, _KEYS[0]
|
||||
filename = 'Resources/Maps/' + ('%f_%f_%d_%s_%d_%d_%s' % specs) + '.jpg'
|
||||
|
||||
# Tile Image object
|
||||
tile_object = None
|
||||
@@ -95,8 +99,10 @@ class GMapsStitcher(object):
|
||||
else:
|
||||
# make the url
|
||||
url = urlbase % specs
|
||||
|
||||
result = urllib2.Request(url).read()
|
||||
print url
|
||||
url = signing.sign_url(url, _KEYS[1])
|
||||
print url
|
||||
result = urllib2.urlopen(urllib2.Request(url)).read()
|
||||
tile_object = PIL.Image.open(BytesIO(result))
|
||||
if not os.path.exists('Resources/Maps'):
|
||||
os.mkdir('Resources/Maps')
|
||||
@@ -117,14 +123,14 @@ class GMapsStitcher(object):
|
||||
temp = math.atan(math.exp(((lat_pixels + degree) - _EARTHPIX))/ _PIXRAD)
|
||||
return math.degrees(math.pi / 2 - 2 * temp)
|
||||
|
||||
def fetch_tiles(self,):
|
||||
def fetch_tiles(self):
|
||||
# cap floats to precision amount
|
||||
self.latitude = self._fast_round(self.latitude, _DEGREE_PRECISION)
|
||||
self.longitude = self._fast_round(self.longitude, _DEGREE_PRECISION)
|
||||
|
||||
# number of tiles required to go from center latitude to desired radius in meters
|
||||
if self.radius_meters is not None:
|
||||
self.num_tiles = int(round(2*self._pixels_to_meters / (_TILESIZE / 2. / self.radius_meters)))
|
||||
self.num_tiles = int(round(2*self._pixels_to_meters() / (_TILESIZE / 2. / self.radius_meters)))
|
||||
|
||||
lon_pixels = _EARTHPIX + self.longitude * math.radians(_PIXRAD)
|
||||
|
||||
|
||||
5
ground_station/resources/core/mappingtest.py
Normal file
5
ground_station/resources/core/mappingtest.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import mapping
|
||||
|
||||
obj = mapping.GMapsStitcher(10000, 10000, 44.57078, -123.275998, 21, 'terrain', 200)
|
||||
|
||||
obj.fetch_tiles()
|
||||
53
ground_station/resources/core/signing.py
Normal file
53
ground_station/resources/core/signing.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Signs a URL using a URL signing secret """
|
||||
|
||||
import hashlib
|
||||
import hmac
|
||||
import base64
|
||||
import urlparse
|
||||
|
||||
def sign_url(input_url=None, secret=None):
|
||||
""" Sign a request URL with a URL signing secret.
|
||||
|
||||
Usage:
|
||||
from urlsigner import sign_url
|
||||
|
||||
signed_url = sign_url(input_url=my_url, secret=SECRET)
|
||||
|
||||
Args:
|
||||
input_url - The URL to sign
|
||||
secret - Your URL signing secret
|
||||
|
||||
Returns:
|
||||
The signed request URL
|
||||
"""
|
||||
|
||||
if not input_url or not secret:
|
||||
raise Exception("Both input_url and secret are required")
|
||||
|
||||
url = urlparse.urlparse(input_url)
|
||||
|
||||
# We only need to sign the path+query part of the string
|
||||
url_to_sign = url.path + "?" + url.query
|
||||
|
||||
# Decode the private key into its binary format
|
||||
# We need to decode the URL-encoded private key
|
||||
decoded_key = base64.urlsafe_b64decode(secret)
|
||||
|
||||
# Create a signature using the private key and the URL-encoded
|
||||
# string using HMAC SHA1. This signature will be binary.
|
||||
signature = hmac.new(decoded_key, url_to_sign, hashlib.sha1)
|
||||
|
||||
# Encode the binary signature into base64 for use within a URL
|
||||
encoded_signature = base64.urlsafe_b64encode(signature.digest())
|
||||
|
||||
original_url = url.scheme + "://" + url.netloc + url.path + "?" + url.query
|
||||
|
||||
# Return signed URL
|
||||
return original_url + "&signature=" + encoded_signature
|
||||
|
||||
if __name__ == "__main__":
|
||||
input_url = raw_input("URL to Sign: ")
|
||||
secret = raw_input("URL signing secret: ")
|
||||
print "Signed URL: " + sign_url(input_url, secret)
|
||||
Reference in New Issue
Block a user