Пример #1
0
def get_tweets():
    access_token,access_secret,consumer_key,consumer_secret = read_config()
    auth = OAuthHandler(consumer_key,consumer_secret)
    auth.set_access_token(access_token,access_secret)
    global hashes
    count = 0
    api = tweepy.API(auth)
    hashes = hashes.replace("'","").split(",")
    for hashtag in hashes:
        tweets = api.search(hashtag)
        for tweet in tweets:
            #print tweet.text
            twitter_json = {}
            twitter_json["created_at"] = str(tweet.created_at)
            twitter_json["caption"] = tweet.text
            twitter_json["username"] = tweet.user.name
            twitter_json["thumbs"] = sentiment.check_sentiments(tweet.text)
            twitter_json["source"] = "twitter"
            twitter_json["link"] = "https://twitter.com/"+str(tweet.user.screen_name)+"/status/"+str(tweet.id)
            print twitter_json["link"]
            if 'media' in tweet.entities:
                twitter_json["url"] = tweet.entities['media'][0]['media_url']
            else:
                twitter_json["url"] = ""
            push_mongo(twitter_json)
Пример #2
0
def get_instagram_posts():
    api = InstagramAPI(access_token=read_config())
    global tags
    tags = tags.replace("'","").split(',')
    for tag in tags:
        print tag
        filtered_media, barr = api.tag_recent_media(count=100,max_id=1,tag_name=tag)
        #print filtered_media
        for media in filtered_media:
            insta_json = {}
            insta_json['url']=str(media.images['standard_resolution'].url)
            insta_json['created_at']=str(media.created_time)
            insta_json['username']=str(media.user.username)
            insta_json['link']=str(media.link)
            insta_json['caption']=str(media.caption)
            insta_json['thumbs']=str(sentiment.check_sentiments(insta_json['caption']))
            insta_json['source']="instagram"
            #print "json"+str(insta_json)
            mongo = mongo_doc.MongoOP()
            mongo.store_values(insta_json)