0

Soooo I have been working on a script I took from ArcGIS Blueprints:

http://file.allitebooks.com/20151230/ArcGIS%20Blueprints.pdf

It should convert geolocated tweets into a geodatabase. I have the Twitter Streaming API already operational, and been playing with different ways to extract x/y, but keep coming back to this script, every so often, hoping I can get it running with no luck. I am stuck on a "List Index Out of Range" error. If anyone is gracious enough to offer some ideas on how I can get by this error I will be forever grateful. If nothing else this endeavor has exploited my shortcomings with Python and Arcpy, and hopefully it will round me out in the long run. For right now, I sure would like to get some mileage out of this script and the work Ive invested into it. Thank you!

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

import arcpy
import sys
import time

consumer_key = 'xxx'
consumer_secret = 'xxx'
token_key = 'xxx'
token_secret = 'xxx'



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

start_time = time.time()
arcpy.env.workspace = "c:\ArcGIS_Blueprint_Python\data\Twitter\TweetInformation.gdb"           "       



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=['car'])


    except Exception as e:
        print(e.message)

if __name__ == '__main__':
    main()  
  • Could you provide the complete error message? – Efferalgan Sep 14 '16 at 07:18
  • Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> list index out of range >>> So I took this right from the Shell. it hangs for awhile then right into the "list index out of range" Thank you for looking into it. – Miss_theBIG8 Sep 14 '16 at 14:30
  • Isn't there something else, like the line where the error happens? – Efferalgan Sep 14 '16 at 19:45
  • Nothin'. Same in the Command Prompt. Thanks for hanging in there. Ive had that error before and it seemed to come from writing a .csv usually; like a path was wrong or something similar and have seen line numbers pointed out and other information referenced to the error. This one is just as I posted it. – Miss_theBIG8 Sep 14 '16 at 20:43

0 Answers0