I am trying to retrieve geolocated data and putting it into an ArcGIS feature class to analyze but unfortunately I keep getting an error. Below is my code.
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import arcpy
import sys #new
import time #new
#global variables
consumer_key = 'x9jRE3KQm1LlEFcHsL6bP4TRa'
consumer_secret = '8VVzPzY0DJbbgbBk5bgWCrBADzLEqdnATNbw1z0LUWF5MWuu4g'
token_key = '2997753385-nCFmNPAo2LOt7LLF311Kw0JdsAhcNSq8yQThxtO'
token_secret = '0Dck37JE7HV56Rs5t5GUkbW3C61qepG4fi070RiP4SNdm'
start_time = time.time()
arcpy.env.workspace = r'c:\ArcGIS_Blueprint_Python\data\Twitter\TweetInformation.gdb'
class StdOutListener(StreamListener):
def __init__(self, start_time, featureClass, time_limit):
super(StdOutListener, self).__init__()
self.time = start_time
self.limit = time_limit
self.featureClass = featureClass
def on_status(self, status):
while (time.time() - self.time) < self.limit:
if status.geo is not None:
dictCoords = status.geo
listCoords = dictCoords['coordinates']
latitude = listCoords[0]
longitude = listCoords[1]
cursor = arcpy.da.InsertCursor(self.featureClass,("SHAPE@XY"))
cursor.insertRow([(longitude,latitude)])
print(str(listCoords[0]) + "," + str(listCoords[1]))
return True
else:
#print "No coordinates found"
return True
exit()
def on_error(self, status):
print('Error...')
print status
return True
def on_timeout(self):
print('Timeout...')
return True
#Main function
def main():
try: #new
featureClass = sys.argv[1]
monitorTime = sys.argv[2]
monitorTime = monitorTime * 3600
sr = arcpy.SpatialReference(4326)
arcpy.env.overwriteOutput = True
arcpy.CreateFeatureclass_management(arcpy.env.workspace, featureClass, "POINT", spatial_reference=sr)
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)
stream = Stream(auth, StdOutListener(start_time, featureClass, time_limit=monitorTime)) #172800
#stream.filter(track=['#wildfire', '#forestfire', '#northstarfire', '#tunkblockfire', '#roughfire','#happycampfire'])
stream.filter(track=['#SEC', '#SECFootball', '#RollTide', '#GigEm', '#Bama', '#UGABulldogs','#Dawgs', '#GeorgiaBulldogs', '##A&MFootball', '#KyleField', '#Aggies', '#gigem','#LSUFootball','#LSUFB', '#WarEagle','#AuburnFootball' ])
except Exception as e: #new
print(e.message) #new
if __name__ == '__main__':
main()
Traceback (most recent call last):
File "C:\Users\18164\Desktop\Chapter (9)\tweepy_stream.py", line 55, in main
featureClass = sys.argv[1] IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\18164\Desktop\Chapter (9)\tweepy_stream.py", line 73, in <module>
main()
File "C:\Users\18164\Desktop\Chapter (9)\tweepy_stream.py", line 70, in main
print(e.message) #new AttributeError: 'IndexError' object has no attribute 'message'