Skip to content

Instantly share code, notes, and snippets.

View oevans's full-sized avatar

Owen Evans oevans

View GitHub Profile
@oevans
oevans / AGO_PullHostedFeatures.py
Last active April 16, 2024 18:37
Python script to pull hosted features with attachments into a local file geodatabase. See ReadMe below.
import os, urllib, urllib2, datetime, arcpy, json
## ============================================================================== ##
## function to update a field - basically converts longs to dates for date fields ##
## since json has dates as a long (milliseconds since unix epoch) and geodb wants ##
## a proper date, not a long.
## ============================================================================== ##
def updateValue(row,field_to_update,value):
outputfield=next((f for f in fields if f.name ==field_to_update),None) #find the output field
@oevans
oevans / HomePageFonts.css
Last active April 30, 2018 21:09
To change the link and hover font colors on the ArcGIS Online home page: 1) Go to My Organization > Edit Settings > Home Page tab, 2) In the Banner section, choose the "HTML" radio button and click the "View HTML Source" button (the last button on the Banner box's toolbar), 3) Paste the HTML code below into the text field after/below the existin…
/*Header*/
<style>#header .nav a, .esri #header-controls ul li a, #header_map_newMap.map_nav a.map_nav_link{color: #fff; text-decoration: none;}</style>
/*Header Hover*/
<style>#header .nav a:hover {color: #26393d; text-decoration: none;}</style>
/*Footer*/
<style>.esriItemLinks a, .esriItemLinks a:link, .esriItemLinks a:hover, .esriItemLinks a:active, .esriItemLinks a:visited{color: #26393d;}</style>
/*
@oevans
oevans / AGO_Scripting_Tutorial1.py
Last active November 19, 2020 15:34
Simple python scripting examples for internal Tech Update. Note these examples work with ArcGIS Online or an instance of Portal for ArcGIS; just replace 'www.arcgis.com' with your portal (e.g., myportal.mydomain.com).
#### PART 1 -- GET AND INSPECT TOKEN ####
import urllib
# Replace <USERNAME>, and <PASSWORD> with your ArcGIS Online subscription account credentials
# Using f=pjson for examples/debugging, should use f=json for scripts
username = '<<USERNAME>>'
password = '<<PASSWORD>>'
# parameters = urllib.urlencode({'username':username,'password':password,'client':'requestip','f':'pjson'})
parameters = urllib.urlencode({'username':username,'password':password,'client':'referer','referer':'http://www.arcgis.com','f':'pjson'})
@oevans
oevans / REST_API_calls.py
Last active July 22, 2024 19:35
Examples: making standard calls to the ArcGIS Online/Portal REST API via python
'''
NOTES:
- See the ArcGIS REST API documentation for supported operations, methods, and syntax:
http://resources.arcgis.com/en/help/arcgis-rest-api/
- A TOKEN must be passed as parameter in addition to any required inputs for the operation.
- "urllib.urlencode" handles spaces and other special characters in parameters so that valid URLs are constructed.
- "urllib.urlopen" sends the reqest and handles the response.
- Parameters are appended to URL for GET (see Example 1), but passed to "urlopen" for POST (see Example 2). API docs specifiy supported methods for each operation.
- "json.loads" converts string responses to parseable JSON objects.
@oevans
oevans / AGO_UNIXTimeConv.py
Last active December 20, 2015 07:29
Converting ArcGIS Online UNIX time to a standard readable date/time format
# Modify time formatting codes (e.g., "%Y", etc.) as needed using values from table in python docs here:
# http://docs.python.org/2/library/time.html#time.strftime
# Replace <AGO DATE/TIME> with your time value/variable
import time
time.strftime("%Y-%m-%d %I:%M:%S %p (%Z)",time.localtime(<AGO DATE/TIME>/1000))
# SAMPLE RESULT - '2013-07-31 11:59:33 PM (Eastern Daylight Time)'
## Also plan to add a function transferAllItemsBatch which will read in a CSV file of username pairs.
def transferAllItems(self, userFrom, userTo):
'''
REQUIRES ADMIN ACCESS
Transfer ownership of all items in userFrom's account to userTo's account, keeping same folder names.
Note, does not check for existing folders in userTo's account.
'''
# userFrom is the account where the content currently resides
# userTo is the account where the content will be transferred
@oevans
oevans / gist:5978035
Last active December 19, 2015 15:39
Draft utility functions for ago-tools
def findNewUsers(users,daysToCheck):
newUsers = []
for user in users:
if date.fromtimestamp(float(user['created'])/1000) > date.today()-timedelta(days=daysToCheck):
newUsers.append(user)
return newUsers
def addUsersToGroups(users,groups):
params = urllib.urlencode({'token' : self.user.token,
## Admin script for adding new users (those that recently accepted invitations) to a group or groups.
## This script uses Evan Caldwell's agolTools module available on GitHub here: https://github.com/Esri/ago-tools
import csv, time, urllib, json, datetime
from datetime import date, timedelta
from agolTools import admin
myAgol = admin.admin()
users = myAgol.getUsers()
@oevans
oevans / gist:5902645
Last active December 19, 2015 05:09
Configuring app templates for use with Portal for ArcGIS: Changes to init() function
function init() {
if (!_jqueryReady) return;
if (!_dojoReady) return;
esri.arcgis.utils.arcgisUrl = SHARINGURL; // ***ADD THIS LINE***
if (getParameterByName("webmap") != "") {
WEBMAP_ID = getParameterByName("webmap");
}
@oevans
oevans / gist:5902621
Last active December 19, 2015 05:09
Configuring app templates for use with Portal for ArcGIS: Changes to CONFIG section
/*In the config section, add the following line above the existing code */
var SHARINGURL = "http://<YOUR WEB SERVER NAME HERE>/sharing/content/items" ;