This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import pydie | |
>>> pydie.roll('3d1') | |
3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# Input | |
string = '3d6+2' | |
# Regex Pattern | |
pattern = re.compile(r'(?P<multiplier>\d+)d(?P<die>\d+)m?(?P<math>\D)?(?P<modifier>\d+)?') | |
match = pattern.match(string) | |
# Attributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geocoder | |
places = geocoder.places('Kabul, Afghanistan', keyword='Embassy') | |
for place in places: | |
print place.json | |
print place.latlng |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import coordinate | |
# MGRS to LatLng | |
c = coordinate.get('41R QQ 123 123') | |
print c.latlng | |
# LatLng to MGRS | |
c = coordinate.get('41.123, -78.123') | |
print c.mgrs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
with open(join('us-data', 'codes.txt')) as f: | |
rows = list(csv.DictReader(f, dialect='excel-tab')) | |
codes = dict([(row['Postal Code'].lower(), row['State']) for row in rows]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<osm-script output="json" timeout="25"> | |
<!-- gather results --> | |
<union> | |
<query type="way"> | |
<has-kv k="addr:housenumber"/> | |
<user name="DenisCarriere"/> | |
<has-kv k="source" v="survey"/> | |
</query> | |
</union> | |
<!-- print results --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To Install: | |
# $ pip install geocoder | |
>>> import geocoder | |
>>> g = geocoder.opencage("New York City", key="YOUR API KEY") | |
>>> g.latlng | |
[40.7305991, -73.9865812] | |
>>> g.json | |
{"status": "OK", "locality": "New York City", ...} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install geocoder | |
# param: short_name (Default is True) | |
# param: method (Default is 'Geocode') | |
> import geocoder | |
> g = geocoder.google('41.34168 -8.71202', method='reverse', short_name=False) | |
'<[OK] Google - Reverse [IC1, 4480, Portugal]>' | |
> g.latlng | |
[41.344931, -8.7123075] | |
> g.country | |
'Portugal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
url = 'http://maps.ottawa.ca/ArcGIS/rest/services/compositeLocator/GeocodeServer/findAddressCandidates' | |
params = { | |
'SingleLine': '190 Forward Avenue', | |
'f': 'json', | |
'outSR': 4326, | |
} | |
r = requests.get(url, params=params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
""" | |
filename.csv | |
============ | |
first,second | |
hello,world | |
""" | |
# Standard CSV Reading |
OlderNewer