-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconvertJSON.py
More file actions
66 lines (45 loc) · 1.36 KB
/
convertJSON.py
File metadata and controls
66 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pip install tweepy
#cashtag
#change count to change the number of tweets returned
import datetime
import pymongo
import tweepy
import json
from pymongo import MongoClient
consumer_key = "43b4urzsW8nMY3oGzB5tIIM8B"
consumer_secret = "fbGLMhkFyipYbTAz0s0S6yrN6cDGGWnEMmNaciceYjr4sgEdP2"
access_token = "2990432317-eYMpYm2Ck2G1YBPvWEq7Mf9wdgzBlOydabaxmzN"
access_token_secret = "lQYcmiMlFdic9KSdmd6PClGQ3Swq8y9BgvVPOmqwhHjV2"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
tweets_data_path = '/home/user/Dropbox/bigData/appleTest.txt'
tweets_data = []
tweets_file = open(tweets_data_path, "r")
#for line in tweets_file:
#try:
#tweet = json.loads(line)
##print(tweet)
#tweets_data.append(tweet)
#except:
#continue
#print(tweets_data)
#print (tweets_data[1]['text'])
#print (len(tweets_data))
with open('/home/user/Dropbox/bigData/appleTest.txt', 'r') as f:
first_line = f.readline()
oneDocument = json.loads(first_line)
#print(oneDocument['text'])
client = MongoClient()
db = client['mydb']
collection = db.testData
post = tweets_data
post = oneDocument
posts = db.posts
#post_id = posts.insert(post['text'])
print(post['text'])
data = {}
data['text'] = post['text']
json_data = json.dumps(data)
post_id = posts.insert(data)
#post_id