Skip to content

Instantly share code, notes, and snippets.

@panchicore
Last active July 26, 2016 21:56
Show Gist options
  • Save panchicore/6a6f38939f1baa8a5a34935b4a7e8764 to your computer and use it in GitHub Desktop.
Save panchicore/6a6f38939f1baa8a5a34935b4a7e8764 to your computer and use it in GitHub Desktop.
elastic search client
import requests
# sample data to index. a layer.
d = {
'abstract': u'Public transportation in Sierra Leone is a rather unregulated business, with no comprehensive country-wide agenda. Most public transport appears to be provided by private entities. TaxiIn the larger towns, taxi service is rather reliable and occurs along predetermined routes. Most common is the use of Motorbike taxis, also known as Ocadas, which travel both within and across neighboring towns.BusMinibuses, known as Poda-Podas are the most common means of transport between towns. There are also Government Bus Routes and private Coach Buses, but these only connect the cities of Freetown, Bo and Kenema. Water transportIn Freetown, the use of water-based transportation is especially important for travel to and from the Lungi International Airport. The airport is located on the opposite side of the Sierra Leone River and at a distance of 3-4 hours if accessed by road, so options such as taxi-boat and ferries are the preferred modes of transport. Ferries are also used to connect Freetown to Pepel, Bonthe, and other smaller ports in the country.Air TransportHelicopter shuttles are available in Freetown, as another means \u2013 albeit more expensive \u2013 to connect to the Lungi International Airport, which is the only airport that meets international standards in the country. There are smaller airfields throughout some of the major towns.RailThere is currently no public rail transport in Sierra Leone. The previously existing Government Railways have been abandoned since the 1970\u2019s, and the one existing railway in the country is used privately for the purpose of cargo transport.Crime-wise, transport across the country is generally safe. However, due to the poor conditions of most of the road network, the difficult weather during the rainy season, and the lack of driving regulations, the accident rate is high, especially on rural roads. Similarly, water-transport can be unsafe as most ferries and taxi-boats have limited safety equipment and navigational lights, and the emergency response system is uncoordinated and inefficient.Attribute Table Field DescriptionsISO3-International Organization for Standardization 3-digit country codeADM0_NAME-Administration level zero identification / nameADM1_NAME-Administration level one identification / nameADM2_NAME-Administration level two identification / nameADM3_NAME-Administration level three identification / nameADM4_NAME-Administration level four identification / nameNAME-Name of transportation pointTYPE1-Primary classification in the geodatabase TYPE2-Secondary classification in the geodatabaseCITY-City location availableSPA_ACC-Spatial accuracy of site location (1 \u2013 high, 2 \u2013 medium, 3 \u2013 low)CONF_IMAGE-DG imagery confirmation (Confirmed, Assessed, Reported, Unconfirmed)COMMENTS-Comments or notes regarding public transportation SOURCE_DT-Source one creation dateSOURCE-Source oneSOURCE2_DT-Source two creation dateSOURCE2-Source twoImgDate-Date of imageSatName-Name of satellite that collected imagefeatureID-DG image catalog identification codeDigitalGlobe Satellite NamesGE01 \u2013 GeoEye 01 QB02 \u2013 QuickBird WV01 \u2013 WorldView 01 WV02 \u2013 WorldView 02 WV03 \u2013 WorldView 03 CollectionThe feature class was generated utilizing data from OpenStreetMap, GeoNames, and Wikimapia. OpenStreetMap and Wikimapia are free worldwide maps, created by crowd-sourcing. GeoNames is a geographical places database maintained and edited by the online community. Consistent naming conventions for geographic locations were attempted but name variants may exist, which can include historical or less widespread interpretations.The data included herein have not been derived from a registered survey and should be considered approximate unless otherwise defined. While rigorous steps have been taken to ensure the quality of each dataset, DigitalGlobe is not responsible for the accuracy and completeness of data compiled from outside sources.Sources (HGIS)DigitalGlobe, "DigitalGlobe Imagery Archive." Accessed November 2014.GeoNames, "Sierra Leone." November 2014. Accessed November 21, 2014. http://www.geonames.org.OpenStreetMap, "Sierra Leone." November 2014. Accessed November 21, 2014. http://www.openstreetmap.org.Wikimapia, "Sierra Leone." November 2014. Accessed November 21, 2014. http://wikimapia.org.Sources (Metadata)Government of the United Kingdom, \u201cForeign Travel Advice: Sierra Leone.\u201d 2013. Accessed December 12, 2014. https://www.gov.uk.Pushak, Nataliya and Vivien Foster, \u201cSierra Leone\u2019s Infrastructure: A Continental Perspective.\u201d World Bank. June 2011. Accessed December 11, 2014. http://www-wds.worldbank.org.Visit Sierra Leone, \u201cAirport Transfer from Lungi to Freetown.\u201d 2014. Accessed December 12, 2014. https://www.visitsierraleone.org.World Travel Guide, \u201cSierra Leone: Getting Around.\u201d 2014. Accessed December 12, 2014. http://www.worldtravelguide.net.',
'area': 0.2852770017299995,
'availability': 'Online',
'bbox': 'ENVELOPE(-13.294678,-12.926880,9.111328,8.335693)',
'domain_name': 'ngamaps.geointapps.org',
'id': '952',
'is_public': True,
'last_status': True,
'layer_category': None,
'layer_date': '1970-01-01T00:00:00Z',
'layer_datetype': 'Detected',
'layer_geoshape': {'coordinates': [[-13.294678, 9.111328],
[-12.92688, 8.335693]],
'type': 'envelope'},
'layer_id': '952',
'layer_originator': u'ngamaps.geointapps.org',
'layer_username': None,
'location': '{"layerInfoPage": "http://localhost:8000/registry/local/layer/952/"}',
'max_x': -12.92688,
'max_y': 9.111328,
'min_x': -13.294678,
'min_y': 8.335693,
'name': u'4',
'recent_reliability': 100.0,
'reliability': 100.0,
'service_id': '1221',
'service_type': 'OGC:WMS',
'srs': ['EPSG:4326'],
'title': u'Public Transportation',
'type': 'Layer',
'url': u'https://ngamaps.geointapps.org/arcgis/services/Sierra_Leone/SLE_Transportation_Points/MapServer/WMSServer?'}
index = "stress5"
_type = "layer"
url = "http://localhost:9200/{0}".format(index)
url_with_type = "{0}/{1}".format(url, _type)
for i in range(1, 100):
#0. exists indice?
print "1"
res = requests.head(url)
if res.status_code == 404:
#1. create indice
print "2"
res = requests.put(url)
print res.content
mapping = {
"layer": {
"properties": {
"layer_geoshape": {
"type": "geo_shape",
"tree": "quadtree",
"precision": "50m"
}
}
}
}
#2. add mappings
url_with_type_and_mapping = "{0}/_mapping".format(url_with_type, _type)
print "3"
res = requests.put(url_with_type_and_mapping, json=mapping)
print res.content
#3. index data
print "4"
res = requests.post(url_with_type, json=d)
print "5"
print res.status_code, res.content, res.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment