Skip to content

Instantly share code, notes, and snippets.

@khibma
khibma / Add_AGOL_AuthServer.py
Created May 13, 2020 13:27
Add a new authorized server to your AGOL org
from arcgis.gis import GIS
import requests
import json
import getpass
USER = "USERNAME"
PASS = getpass.getpass()
g = GIS("https://ORG.maps.arcgis.com", USER, PASS)
@khibma
khibma / delete_AGOL_FS_Features.py
Created May 4, 2020 13:36
Example that uses ArcGIS Python API to authenticate, but uses Requests to make calls to the backend REST service directly.
from arcgis.gis import GIS
import requests
import json
USER = "USER"
PASS = "PASSWORD"
g = GIS("https://www.arcgis.com", USER, PASS)
token = g._con.token
#-------------------------------------------------------------------------------
# Name: UploadPublishCSVMultipart
# Purpose: This script uploads and publishes a CSV that includes XY data, not
# addresses. This uses a multipart upload for the CSV and requires
# username, password, CSVfile, X and Y fields, and tags to be defined
# Author: Melanie Summers
import requests
import os
@khibma
khibma / sendReq.py
Created March 16, 2015 21:01
Py3 Request maker
import urllib.parse as parse
import urllib.request as request
import http.client as client
#Force connections to the previous HTTP 1.0 standard as this is faster with chunked responses, which is typically what you'll get
client.HTTPConnection._http_vsn= 10
client.HTTPConnection._http_vsn_str='HTTP/1.0'
def sendReq(url, qDict=None, headers=None):
@khibma
khibma / OverwriteFS.py
Last active March 28, 2017 08:17
Python code to create a service definition from a map document (.mxd), modify the .SD file and overwrite an existing Hosted Feature Service on ArcGIS.com This workflow requires 2 files, the OverwriteFS.py and the settings.ini file. Download them both to the same directory. You will also need the 3rd party module, 'requests'. It can be downloaded…
# Import system modules
import urllib, urllib2, json
import sys, os
import requests
import arcpy
import ConfigParser
from xml.etree import ElementTree as ET
def urlopen(url, data=None):
@khibma
khibma / sendEmail.py
Last active December 28, 2015 10:19
Send email
def sendEmail(content, images):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
FROM = 'FROMemail@email.com'
TO = 'TOemail@email.com'
@khibma
khibma / maketoken.py
Last active December 28, 2015 10:19
Make arcgis.com token
def gentoken(username, password, referer, expiration=60):
#Re-usable function to get a token required for Admin changes
referer = "http://www.arcgis.com/"
query_dict = {'username': username,
'password': password,
'expiration': str(expiration),
'client': 'referer',
'referer': referer,
'f': 'json'}