Skip to content

Instantly share code, notes, and snippets.

@dyln
Created December 22, 2016 21:54
Show Gist options
  • Select an option

  • Save dyln/075e01587d2e7372021f2bf84ccafcff to your computer and use it in GitHub Desktop.

Select an option

Save dyln/075e01587d2e7372021f2bf84ccafcff to your computer and use it in GitHub Desktop.
support for my project. takes the raw twitter json dump, gives geoloc., text, time and sentiment analysis of text.
import json
import geojson
import csv
from textblob import TextBlob
#full json dosyası olan tweet datasını geolocation text ve saate çeviren süper bi kod
with open('tweets.json', 'r') as f:
geo_data = {
"type": "FeatureCollection",
"features": []
}
for line in f:
tweet = json.loads(line)
if tweet['coordinates']:
analysis = TextBlob(tweet['text'])
geo_json_feature = {
#"type": "Feature",
"geometry": tweet['coordinates'], #geoJSON (longitude first, then latitude)
"text": tweet['text'],
"created_at": tweet['created_at'],
"sentiment": analysis.sentiment # (polarity, subjectivity)
}
geo_data['features'].append(geo_json_feature)
# Save geo data
with open('geo_data.json', 'w') as fout:
fout.write(json.dumps(geo_data, indent=4))
##################
## bu da json geolocationı csvye çeviren bişey
# rows = json.loads(geo_data)
# with open('test.csv', 'wb+') as f:
# dict_writer = csv.DictWriter(f, fieldnames=['longitude', 'latitude'])
# dict_writer.writeheader()
# dict_writer.writerows(rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment