Skip to content

Instantly share code, notes, and snippets.

@okjodom
Last active November 16, 2016 19:14
Show Gist options
  • Select an option

  • Save okjodom/4c3df8082ff43924acb62659faad2f63 to your computer and use it in GitHub Desktop.

Select an option

Save okjodom/4c3df8082ff43924acb62659faad2f63 to your computer and use it in GitHub Desktop.
## some calls from the collector are refered here
#our data will be cached here
geo_data = {
"type": "FeatureCollection",
"features" : []
}
# a function to save the data
def saveGeoData(self, geo_data):
with open('geo_data.json', 'a') as gd:
gd.write(json.dumps(geo_data, indent = 4))
gd.close()
# a function to filter the data
def filterData(self, tweet):
self.tweet = tweet
geo_data = self.geo_data
# check if a tweet has coordinates and filter data from it
if self.tweet['coordinates'] != None:
print(self.tweet)
geo_data_feature = {
"type": "Feature",
"geometry": self.tweet['coordinates'],
"properties": {
"text": self.tweet["text"],
"created_at": self.tweet["created_at"]
}
}
geo_data["features"].append(geo_data_feature)
self.geo_data = geo_data # cache updated geodata
self.saveGeoData(geo_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment