Skip to content

Instantly share code, notes, and snippets.

View oevans's full-sized avatar

Owen Evans oevans

View GitHub Profile
## 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: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,
## 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 / 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)'
@oevans
oevans / REST_API_calls.py
Last active November 19, 2020 15:34
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_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 / 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_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 / Enterprise Login Final Migration Instructions.md
Last active August 29, 2015 13:56
Instructions to complete migration to Esri Enterprise Login

Things to know before migration:

  • Any layers/maps you have shared from Excel will no longer be able to be updated. They will continue to exist in their current form, but if they need to be updated they must be republished (and then any related maps/apps must be updated).
  • Testing indicates that hosted layers shared from Desktop can be accessed and updated ("overwritten") from your new enterprise login account.
  • Still investigating...which Esri Apps (e.g., Community Analyst, Collector, Ops Dashboard, etc.) support enterprise logins?

Actions needed to complete migration:

  1. Spot check your items and groups and let the admin (Owen) know if things look good.
@oevans
oevans / ChangeMapSelectionColor
Last active August 29, 2015 14:06
Change map selection color in app templates
/* Side Accordion template
Add map2_graphics_layer, map3_graphics_layer, etc. as needded for additional maps*/
<style type="text/css">
#map0_graphics_layer path, #map1_graphics_layer path {
stroke: #b22222 !important;
}
</style>
/* Text and Legend template