Skip to content
Snippets Groups Projects
Commit ba6e2b39 authored by Matthew O'Halloran's avatar Matthew O'Halloran
Browse files

Merge branch 'patch-2' into 'master'

Patch 2

See merge request !10
parents 9cd2ce6d 267adc6d
Branches
No related tags found
1 merge request!10Patch 2
function (doc) {
var editDate = new Date(doc.created_at.split(" ")[0]);
var month = editDate.getMonth()+1;
var year = editDate.getFullYear();
var date = editDate.getDate();
if(year==2020){
if(date<=10){
stage='F'
}
else if(date<=20){
stage='M'
}
else{
stage='L'
}
if(doc.sentiment[0]<0)
emit([doc.state,'negative',month,stage],1)
else if(doc.sentiment[0]>0)
emit([doc.state,'positive',month,stage],1)
else
emit([doc.state,'neutral',month,stage],1)
}}
\ No newline at end of file
_sum
\ No newline at end of file
import io
import json
from datetime import datetime
import re
from textblob import TextBlob
file1='tweetsWA.json'
output_file=io.open('extractedWA.json','w')
count=1
remove_ms = lambda x:re.sub("\+\d+\s","",x)
mk_dt = lambda x:datetime.strptime(remove_ms(x), "%a %b %d %H:%M:%S %Y")
my_date = lambda x:"{:%Y-%m-%d}".format(mk_dt(x))
my_time = lambda x:"{:%H:%M:%S}".format(mk_dt(x))
with io.open(file1,'r',encoding="utf-8") as f:
for line in f:
try:
my_dict={}
my_dict['id']=json.loads(line)['id']
create_time=json.loads(line)['created_at']
my_dict['date']=my_date(create_time)
my_dict['time']=my_time(create_time)
tweet = json.loads(line)['text']
my_dict['polarity']=TextBlob(tweet).sentiment.polarity
my_dict['lang'] = json.loads(line)['lang']
output_file.write(json.dumps(my_dict)+',\n')
except:
pass
output_file.close()
import couchdb
import json
couch = couchdb.Server('http://127.0.0.1:5984')
couch.resource.credentials = ("admin", "960115")
if 'tweets' not in couch:
db = couch.create('tweets')
db = couch['tweets']
with open('tweetsWA.json',encoding='utf-8') as jsonfile:
for row in jsonfile:
db_entry = json.loads(row)
db.save(db_entry)
\ No newline at end of file
import couchdb
import json
couch = couchdb.Server('http://172.26.133.58:5984')
couch.resource.credentials = ("admin", "admin")
if 'housing-sa4' not in couch:
db = couch.create('housing-sa4')
db = couch['housing-sa4']
json_data = json.load(open('vic1.json'))
for feature in json_data['features']:
db.save(feature)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment