Hello! Im new to PythonAPI, still very much a novice. I'm trying to update some fields in an AGO feature layer from a script. Hopefully I will be able to set up a reoccurring task which will update the layer consistently. Every time the task will run I want my script to look at a field, and change another field based on what is there.
The change will occur based on a FromDate and a ToDate field. These fields will be the cause of the edit, which will change a field from Vacant to Occupied, depending if the current time (now()) falls within the FromDate / ToDate times. In other words, When the current time is After the FromDate and before the ToDate, the field will be occupied.
This is what I have so far:
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features <SPAN class="keyword token">import</SPAN> FeatureSet<SPAN class="punctuation token">,</SPAN> Feature
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN>url<SPAN class="operator token">=</SPAN><SPAN class="string token">'https://pythonapi.playground.esri.com/portal'</SPAN><SPAN class="punctuation token">,</SPAN> username<SPAN class="operator token">=</SPAN><SPAN class="string token">'xyz'</SPAN><SPAN class="punctuation token">,</SPAN> password<SPAN class="operator token">=</SPAN><SPAN class="string token">'xyz'</SPAN><SPAN class="punctuation token">)</SPAN>
itemId <SPAN class="operator token">=</SPAN> <SPAN class="string token">'xxxxxxxxxxxxxxxxxx'</SPAN>
fs<SPAN class="operator token">=</SPAN>gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>itemId<SPAN class="punctuation token">)</SPAN>
fl<SPAN class="operator token">=</SPAN>fs<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#this is where I get confused</SPAN>
features <SPAN class="operator token">=</SPAN> <SPAN class="operator token">not</SPAN> sure what to put here
<SPAN class="keyword token">for</SPAN> feature <SPAN class="keyword token">in</SPAN> features<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> FromDate <SPAN class="operator token"><=</SPAN> Now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> ToDate <SPAN class="operator token">>=</SPAN> Now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
newValue <SPAN class="operator token">=</SPAN> <SPAN class="string token">'occupied'</SPAN>
feature<SPAN class="punctuation token">.</SPAN>set_value<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'roomstatus'</SPAN><SPAN class="punctuation token">,</SPAN>NewValue<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
newValue2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">'vacant'</SPAN>
feature<SPAN class="punctuation token">.</SPAN>set_value<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'roomstatus'</SPAN><SPAN class="punctuation token">,</SPAN>NewValue<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># update the features in AGOL</SPAN>
results <SPAN class="operator token">=</SPAN> fl<SPAN class="punctuation token">.</SPAN>edit_features<SPAN class="punctuation token">(</SPAN>updates<SPAN class="operator token">=</SPAN>features<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Again, super new to this so any advice would be appreciated! Thanks.