Skip to content

Instantly share code, notes, and snippets.

View cesandoval's full-sized avatar

Carlos Sandoval Olascoaga cesandoval

View GitHub Profile
@cesandoval
cesandoval / web_query.py
Created July 24, 2012 20:11
Download web files. Takes a url and writes the file into the specified folder.
try:
import urllib2 #urllib is in python 2.7 and later standard libraries
except:
print('You need to install the URLLIB2')
#Download web files. Takes a url and writes the file into the specified folder.
url = 'http://www.blog.pythonlibrary.org/wp-content/uploads/2012/06/wxDbViewer.zip' #URL to download data from
def Json_Query(url):
@cesandoval
cesandoval / unzip.py
Created July 24, 2012 20:13
Extracts files on a zip file into a given directory, if no directory is given, it extracts the files into the zip file directory.
import zipfile
import os
#Extracts files on a zip file into a given directory, if no directory is given,
#it extracts the files into the zip file directory.
def unzip_file(zip_file, my_path=None):
zip_file = zipfile.ZipFile(zip_file) #open the zip file
if my_path != None: #if directory is given, and doesn't exist, create directory.
if not os.path.isdir(my_path):
@cesandoval
cesandoval / out_of_range_error.py
Created August 6, 2012 20:47
shp file review error
> I'm getting an error while trying to access the review page after uploading files. I get a list index out of range error. I'm guessing that this is happening because the script can't access any of the items I uploaded to the webpage, maybe the database is empty? How do you think I might be able to solve this? Here's the error:
> IndexError at /webfinches/review/
>
> list index out of range
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/webfinches/review/
> Django Version: 1.4
> Exception Type: IndexError
> Exception Value:
@cesandoval
cesandoval / review.py
Created August 7, 2012 00:44
forms - models
def review(request):
"""A view for uploading new data.
"""
user=User.objects.get(username='carlos')
if request.method == 'POST': # someone is giving us data
formset = LayerReviewFormSet(request.POST, request.FILES)
for form in formset:
print 'reviewing form'
else: # we are asking them to review data
# get the last upload of this user
@cesandoval
cesandoval / forms2.py
Created August 7, 2012 21:42
forms 2
#from forms.py
class LayerReviewForm(forms.ModelForm):
"""For editing and configuring the layer information for each layer."""
class Meta:
model = DataLayer
fields = ['name', 'notes', 'srs','geometry_type']
#from views.py
@login_required
def review(request):
@cesandoval
cesandoval / get geom type.py
Created August 8, 2012 00:59
get geom type
import shapefile
import zipfile
import os
shpTypeDict = {
"0":"Null Shape",
"1":"Point",
"3":"Polyline",
"5":"Polygon",
"8":"MultiPoint",
@cesandoval
cesandoval / gis geom type.py
Created August 8, 2012 18:50
get geom type gis
import shapefile
import zipfile
import os
def get_geometry_type(zip_file):
shpTypeDict = {
"0":"Null Shape",
"1":"Point",
"3":"Polyline",
"5":"Polygon",
@cesandoval
cesandoval / webfinches.py
Created August 8, 2012 19:10
web finches updates
#From models.py
shpTypeDict = {
"0":"Null Shape",
"1":"Point",
"3":"Polyline",
"5":"Polygon",
"8":"MultiPoint",
"11":"PointZ",
"13":"PolylineZ",
"15":"PolygonZ",
@cesandoval
cesandoval / hidden_id.py
Created August 8, 2012 22:57
hidden id
#from models.py
class DataLayer(Named, Authored, Dated, Noted):
geometry_type = models.CharField(max_length=50, null=True, blank=True)
srs = models.CharField(max_length=50, null=True, blank=True)
files = models.ManyToManyField('DataFile', null=True, blank=True )
layer_id = models.AutoField(primary_key=True)
def __unicode__(self):
return "DataLayer: %s" % self.name
#from forms.py
@cesandoval
cesandoval / hidden.html
Created August 9, 2012 00:24
hidden.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Local Code</title>
<link rel="stylesheet" href="/static/css/basics.css" type="text/css"/>