<?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: Can't figure out syntax error for append Call list in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1476839#M70637</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/249770"&gt;@JustinNettleton1&lt;/a&gt;&amp;nbsp;do you have ArcGIS Pro?&amp;nbsp; You may be able to simplify this with a truncate/append.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-documents/overwrite-arcgis-online-feature-service-using/ta-p/904457" target="_blank"&gt;https://community.esri.com/t5/arcgis-online-documents/overwrite-arcgis-online-feature-service-using/ta-p/904457&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2024 11:09:50 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-05-22T11:09:50Z</dc:date>
    <item>
      <title>Can't figure out syntax error for append Call list</title>
      <link>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1474237#M70601</link>
      <description>&lt;P&gt;I am working on python script that takes data straight from SQL server and update AGO feature service (Hosted table).&amp;nbsp; &amp;nbsp;I keep getting the below syntax error on line 50 but don't understand why. I have made sure all the fields have the correct spelling and case.&amp;nbsp; Anyone have any ideas?&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;SyntaxError&lt;/SPAN&gt;                               Traceback (most recent call last)
File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\ast.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;parse&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;50&lt;/SPAN&gt;:    &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;compile&lt;/SPAN&gt;(source, filename, mode, flags,

&lt;SPAN class=""&gt;SyntaxError&lt;/SPAN&gt;: invalid syntax (&amp;lt;string&amp;gt;, line 72)
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pyodbc
import os
from arcgis.gis import GIS

#lists for calls used during the update process
agol_calls = []
current_calls = []
call_numbers = []

# SQL Query being passed through the ODBC connection
SQL_QUERY = """
select id,Unit,Status,Type,Juridiction,Division,LastUpdate
from Reports_Database.dbo.Avail_Units_T
order by Unit
"""
print ('Query Successful')

def ODBC_connect():
    ##SERVER = 'CADGIS.heartlandcad.net\CADGIS\SQLEXPRESS' # Server FQDN
    SERVER = 'CADGIS\SQLEXPRESS' # Server FQDN
    DATABASE = 'Reports_Database' # Database Name
    ## Connection string to pass in pyodbc connection request. Using Trusted_Connect=yes to have SQL Server Native Client ODBC driver use Windows Authentication of the account running the script
    ## Using the Windows Authentication of the account running the script allows for the use of a Managed Service Account to run the scheduled python script
    connectionString = f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={SERVER};DATABASE={DATABASE};Trusted_Connection=yes'
    conn = pyodbc.connect(connectionString)
    cursor = conn.cursor()
    cursor.execute(SQL_QUERY)
    records = cursor.fetchall()
    for r in records:
        record = [r.id,r.Unit,r.Status,r.Type,r.Juridiction,r.Division,r.LastUpdate]
        current_calls.append(record)
        call_numbers.append(r.id)
        
print ('SQL Connection Successful')

def Portal_push():
    user = os.getenv('justin.nettleton') # System Environmental Variable Name for Username
    password = os.getenv('******') # System Environmental Variable Name for Password
    portal = os.getenv('https://www.arcgis.com') # System Environmental Variable Name for Portal URL
    gis = GIS(portal,user,password,use_gen_token=True)
    agol_item = gis.content.get('38aabc243aaf4f4ab5c8b9d5600ed173') # ArcGIS Online Item ID
    cadLayer = agol_item.layers[0]
    cadFSet = cadLayer.query(where = '1=1')
    cad_list = cadFSet.features



    # Retrieving the call numbers that are existing in the ArcGIS Online Feature Service
    for exsting_call in cad_list:
        agol_calls.append(exsting_call.attributes['id'])

    for call in agol_calls:
        if call not in call_numbers:
            call_feature = [f for f in cad_list if f.attributes['id'] == call][0]
            call_objid = call_feature.get_value('OBJECTID')
            cadLayer.edit_features(deletes=str(call_objid))

    # Adding Calls
    for call in current_calls:
        if call[0] not in agol_calls:     
            call_dict = {"attributes":
                        {"id":call[0],
                        "Unit":call[1],
                        "Status":call[2],
                        "Type":call[3],
                        "Juridiction":call[4].upper(),
                        "Division":call[5],
                        "LastUpdate":call[6],
                        
            cadLayer.edit_features(adds=[call_dict])

if __name__ == '__main__':
    ODBC_connect()
    Portal_push()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 23:46:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1474237#M70601</guid>
      <dc:creator>JustinNettleton1</dc:creator>
      <dc:date>2024-05-16T23:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can't figure out syntax error for append Call list</title>
      <link>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1474253#M70603</link>
      <description>&lt;P&gt;Are you missing some lines?&amp;nbsp; Your call_dict looks like it's missing its last line (or multiple lines), it doesn't have a closing bracket.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 00:55:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1474253#M70603</guid>
      <dc:creator>MobiusSnake</dc:creator>
      <dc:date>2024-05-17T00:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can't figure out syntax error for append Call list</title>
      <link>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1474285#M70605</link>
      <description>&lt;P&gt;Yep, that was that issue. Used someone elses code and accidently removed those lines when editing.&amp;nbsp; Fixed that and now getting cursor error:&amp;nbsp; Possibly not connected to the database correctly?&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;ProgrammingError&lt;/SPAN&gt;                          Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[7]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;72&lt;/SPAN&gt;:    ODBC_connect()

In  &lt;SPAN class=""&gt;[7]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;28&lt;/SPAN&gt;:    records = cursor.fetchall()

&lt;SPAN class=""&gt;ProgrammingError&lt;/SPAN&gt;: No results.  Previous SQL was not a query.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/249770"&gt;@JustinNettleton1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I am working on python script that takes data straight from SQL server and update AGO feature service (Hosted table).&amp;nbsp; &amp;nbsp;I keep getting the below syntax error on line 50 but don't understand why. I have made sure all the fields have the correct spelling and case.&amp;nbsp; Anyone have any ideas?&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;SyntaxError&lt;/SPAN&gt;                               Traceback (most recent call last)
File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\ast.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;parse&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;50&lt;/SPAN&gt;:    &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;compile&lt;/SPAN&gt;(source, filename, mode, flags,

&lt;SPAN class=""&gt;SyntaxError&lt;/SPAN&gt;: invalid syntax (&amp;lt;string&amp;gt;, line 72)
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pyodbc
import os
from arcgis.gis import GIS

#lists for calls used during the update process
agol_calls = []
current_calls = []
call_numbers = []

# SQL Query being passed through the ODBC connection
SQL_QUERY = """
select id,Unit,Status,Type,Juridiction,Division,LastUpdate
from Reports_Database.dbo.Avail_Units_T
order by Unit
"""
print ('Query Successful')

def ODBC_connect():
    ##SERVER = 'CADGIS.heartlandcad.net\CADGIS\SQLEXPRESS' # Server FQDN
    SERVER = 'CADGIS\SQLEXPRESS' # Server FQDN
    DATABASE = 'Reports_Database' # Database Name
    ## Connection string to pass in pyodbc connection request. Using Trusted_Connect=yes to have SQL Server Native Client ODBC driver use Windows Authentication of the account running the script
    ## Using the Windows Authentication of the account running the script allows for the use of a Managed Service Account to run the scheduled python script
    connectionString = f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={SERVER};DATABASE={DATABASE};Trusted_Connection=yes'
    conn = pyodbc.connect(connectionString)
    cursor = conn.cursor()
    cursor.execute(SQL_QUERY)
    records = cursor.fetchall()
    for r in records:
        record = [r.id,r.Unit,r.Status,r.Type,r.Juridiction,r.Division,r.LastUpdate]
        current_calls.append(record)
        call_numbers.append(r.id)
        
print ('SQL Connection Successful')

def Portal_push():
    user = os.getenv('justin.nettleton') # System Environmental Variable Name for Username
    password = os.getenv('******') # System Environmental Variable Name for Password
    portal = os.getenv('https://www.arcgis.com') # System Environmental Variable Name for Portal URL
    gis = GIS(portal,user,password,use_gen_token=True)
    agol_item = gis.content.get('38aabc243aaf4f4ab5c8b9d5600ed173') # ArcGIS Online Item ID
    cadLayer = agol_item.layers[0]
    cadFSet = cadLayer.query(where = '1=1')
    cad_list = cadFSet.features



    # Retrieving the call numbers that are existing in the ArcGIS Online Feature Service
    for exsting_call in cad_list:
        agol_calls.append(exsting_call.attributes['id'])

    for call in agol_calls:
        if call not in call_numbers:
            call_feature = [f for f in cad_list if f.attributes['id'] == call][0]
            call_objid = call_feature.get_value('OBJECTID')
            cadLayer.edit_features(deletes=str(call_objid))

    # Adding Calls
    for call in current_calls:
        if call[0] not in agol_calls:     
            call_dict = {"attributes":
                        {"id":call[0],
                        "Unit":call[1],
                        "Status":call[2],
                        "Type":call[3],
                        "Juridiction":call[4].upper(),
                        "Division":call[5],
                        "LastUpdate":call[6],
                        
            cadLayer.edit_features(adds=[call_dict])

if __name__ == '__main__':
    ODBC_connect()
    Portal_push()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&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 pyodbc
import os
from arcgis.gis import GIS

#lists for calls used during the update process
agol_calls = []
current_calls = []
call_numbers = []

##select id,Unit,Status,Type,Juridiction,Division,LastUpdate
# SQL Query being passed through the ODBC connection
SQL_QUERY = """
select id,Unit,Status,Type,Juridiction,Division,LastUpdate
from Reports_Database.dbo.Avail_Units_T
order by id
"""
print ('Query Successful')

def ODBC_connect():
    ##SERVER = 'CADGIS.heartlandcad.net\CADGIS\SQLEXPRESS' # Server FQDN
    SERVER = 'CADGIS\SQLEXPRESS' # Server FQDN
    DATABASE = 'Reports_Database' # Database Name
    ## Connection string to pass in pyodbc connection request. Using Trusted_Connect=yes to have SQL Server Native Client ODBC driver use Windows Authentication of the account running the script
    ## Using the Windows Authentication of the account running the script allows for the use of a Managed Service Account to run the scheduled python script
    connectionString = f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={SERVER};DATABASE={DATABASE};Trusted_Connection=yes'
    conn = pyodbc.connect(connectionString)
    cursor = conn.cursor()
    records = cursor.fetchall()
    for r in records:
        record = [r.id,r.Unit,r.Status,r.Type,r.Juridiction,r.Division,r.LastUpdate]
        current_calls.append(record)
        call_numbers.append(r.id)
        
print ('SQL Connection Successful')

def Portal_push():
    user = os.getenv('justin.nettleton') # System Environmental Variable Name for Username
    password = os.getenv('******') # System Environmental Variable Name for Password
    portal = os.getenv('https://www.arcgis.com') # System Environmental Variable Name for Portal URL
    gis = GIS(portal,user,password,use_gen_token=True)
    agol_item = gis.content.get('38aabc243aaf4f4ab5c8b9d5600ed173') # ArcGIS Online Item ID
    cadLayer = agol_item.layers[0]
    cadFSet = cadLayer.query(where = '1=1')
    cad_list = cadFSet.features



    # Retrieving the call numbers that are existing in the ArcGIS Online Feature Service
    for exsting_call in cad_list:
        agol_calls.append(exsting_call.attributes['id'])

    for call in agol_calls:
        if call not in call_numbers:
            call_feature = [f for f in cad_list if f.attributes['id'] == call][0]
            call_objid = call_feature.get_value('OBJECTID')
            cadLayer.edit_features(deletes=str(call_objid))

    # Adding Calls
    for call in current_calls:
        if call[0] not in agol_calls:     
            call_dict = {"attributes":
                        {"id":call[0],
                        "Unit":call[1],
                        "Status":call[2],
                        "Type":call[3],
                        "Juridiction":call[4].upper(),
                        "Division":call[5],
                        "LastUpdate":call[6]}}
            cadLayer.edit_features(adds=[call_dict])

if __name__ == '__main__':
    ODBC_connect()
    Portal_push()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 01:57:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1474285#M70605</guid>
      <dc:creator>JustinNettleton1</dc:creator>
      <dc:date>2024-05-17T01:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can't figure out syntax error for append Call list</title>
      <link>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1476839#M70637</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/249770"&gt;@JustinNettleton1&lt;/a&gt;&amp;nbsp;do you have ArcGIS Pro?&amp;nbsp; You may be able to simplify this with a truncate/append.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-documents/overwrite-arcgis-online-feature-service-using/ta-p/904457" target="_blank"&gt;https://community.esri.com/t5/arcgis-online-documents/overwrite-arcgis-online-feature-service-using/ta-p/904457&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 11:09:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1476839#M70637</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-05-22T11:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can't figure out syntax error for append Call list</title>
      <link>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1476908#M70639</link>
      <description>&lt;P&gt;Thanks, I will give this a try.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 13:48:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-t-figure-out-syntax-error-for-append-call-list/m-p/1476908#M70639</guid>
      <dc:creator>JustinNettleton1</dc:creator>
      <dc:date>2024-05-22T13:48:27Z</dc:date>
    </item>
  </channel>
</rss>

