<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python script to overwrite hosted FC and table from Google Sheets in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-to-overwrite-hosted-fc-and-table/m-p/1568974#M10971</link>
    <description>&lt;P&gt;The overwrite function, in my experience, is fickle. Store the overwrite job in a variable and then print this statement for debugging. It should provide a status as a json dictionary.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2024 17:53:18 GMT</pubDate>
    <dc:creator>AustinAverill</dc:creator>
    <dc:date>2024-12-16T17:53:18Z</dc:date>
    <item>
      <title>Python script to overwrite hosted FC and table from Google Sheets</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-to-overwrite-hosted-fc-and-table/m-p/1568972#M10970</link>
      <description>&lt;P&gt;I have a hosted feature class and a hosted table in the Organization's Contents section initially created from two Google Sheets (through shared CSV URLs), that I need regularly updated whenever new data is added/updated in the original two Google Sheets. For this purpose, I've put together a basic python script that sits on a local machine, with the plan to run it through a Windows Task Scheduler (i.e., user need only update the data in the Google Sheets for changes to reflect across to AGOL). However, the script does not appear to be completing the data overwrite. What am I missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Import libraries
from arcgis.gis import GIS
import urllib.request, csv
from arcgis import features
import pandas as pd
import os


# Define 
AGOL_username = "username"
AGOL_password = "password"
Layer_ID = 'long alphanumeric ID'
Table_ID = 'long alphanumeric ID'
Google_layer_csv = "https://docs.google.com/spreadsheets/...1&amp;amp;single=true&amp;amp;output=csv" #used to populate the location feature class
Google_table_csv = "https://docs.google.com/spreadsheets/...2&amp;amp;single=true&amp;amp;output=csv" #used to populate the related table


# Connect to the GIS
gis = GIS("https://www.arcgis.com", AGOL_username, AGOL_password)
print("Logged in as " + str(gis.properties.user.username))


# ## Overwrite the feature layer
# Let us overwrite the feature layer using the new csv file we just created. To overwrite, we will use the `overwrite()` method.

#item id of the hosted feature layer in AGOL Organization
Engines_featureLayer_item = gis.content.get(Layer_ID)

#item id of the hosted table in AGOL Organization
Engines_table_item = gis.content.get(Table_ID)

#access the manager helper object to overwrite our currently existing hosted feature layer or table
from arcgis.features import FeatureLayerCollection
Engines_flayer_collection = FeatureLayerCollection.fromitem(Engines_featureLayer_item)
Engines_table_collection = FeatureLayerCollection.fromitem(Engines_table_item)

#call the overwrite() method which can be accessed using the manager property
Engines_flayer_collection.manager.overwrite(Google_layer_csv)
Engines_table_collection.manager.overwrite(Google_table_csv)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 17:40:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-to-overwrite-hosted-fc-and-table/m-p/1568972#M10970</guid>
      <dc:creator>MathieuCain</dc:creator>
      <dc:date>2024-12-16T17:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to overwrite hosted FC and table from Google Sheets</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-to-overwrite-hosted-fc-and-table/m-p/1568974#M10971</link>
      <description>&lt;P&gt;The overwrite function, in my experience, is fickle. Store the overwrite job in a variable and then print this statement for debugging. It should provide a status as a json dictionary.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 17:53:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-to-overwrite-hosted-fc-and-table/m-p/1568974#M10971</guid>
      <dc:creator>AustinAverill</dc:creator>
      <dc:date>2024-12-16T17:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to overwrite hosted FC and table from Google Sheets</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-to-overwrite-hosted-fc-and-table/m-p/1570741#M10986</link>
      <description>&lt;P&gt;Instead of overwrite, can you access the individual feature layer and do a truncate, convert the csv to a data frame, then add data frame to the feature layer?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
#Wipe out all features in layer
yourfeaturelayer.manager.truncate()
#import your csv data into the data frame
df = pd.read_csv("your_csv_file.csv")
feature_set = FeatureSet.from_dataframe(df)
#Add in features from data frame into feature layer
result = yourfeaturelayer.edit_features(adds=feature_set)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 20:45:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-to-overwrite-hosted-fc-and-table/m-p/1570741#M10986</guid>
      <dc:creator>usace_sam_rd3</dc:creator>
      <dc:date>2024-12-20T20:45:03Z</dc:date>
    </item>
  </channel>
</rss>

