Esempio n. 1
0
void TweetQueryItem::setFavorited(bool favorited)
{
    if (m_data == nullptr) {
        return;
    }

    Tweet tweet {std::move(m_data->data())};
    tweet.setFavorited(favorited);
    m_data->update(tweet);
}
Esempio n. 2
0
void TweetQueryItem::setRetweeted()
{
    if (m_data == nullptr) {
        return;
    }

    Tweet tweet {std::move(m_data->data())};
    tweet.setRetweeted(true);
    m_data->update(tweet);
}
inline void getLists(TARGET &target_tweets,SIMILAR &similar_tweets,ifstream &inputID){
  string line,target_ID;
  getline(inputID,target_ID);
  getline(inputID,line);
  while(inputID && getline(inputID,line) && !line.empty()){
    target_tweets[target_ID].first.push_back(line);
    //    similar_tweets[line].ID = line;
    Tweet temp; temp.getID(line);
    similar_tweets.push_back(temp);
  }
  vector<string> &target_similars = target_tweets[target_ID].first;
  sort(target_similars.begin(),target_similars.end());
}
// Renders the tweet into a gl::Texture, using TextBox for type rendering
gl::Texture GoodNightMorningApp::renderTweet( const Tweet &tweet, float width, const Color &textColor, float backgroundAlpha )
{
	TextBox header = TextBox().font( mHeaderFont ).color( textColor ).text( "@" + tweet.getUser() );
	Surface headerSurface = header.render();
	TextBox phrase = TextBox().size( Vec2f( width - 48 - 4, TextBox::GROW ) ).font( mFont ).color( textColor ).text( tweet.getPhrase() );
	Surface textSurface = phrase.render();
	Surface result( textSurface.getWidth() + 56, std::max( headerSurface.getHeight() + textSurface.getHeight() + 10, 56 ), true );
	ip::fill( &result, ColorA( 1, 1, 1, backgroundAlpha ) );
	if( tweet.getIcon() )
		result.copyFrom( tweet.getIcon(), tweet.getIcon().getBounds(), Vec2i( 4, 4 ) );
	ip::blend( &result, headerSurface, headerSurface.getBounds(), Vec2i( result.getWidth() - 4 - headerSurface.getWidth(), textSurface.getHeight() + 6 ) );
	ip::blend( &result, textSurface, textSurface.getBounds(), Vec2i( 56, 4 ) );
	return result;
}
Esempio n. 5
0
//ユーザアイコンが読み込み終わった際に呼ばれる
void TweetList::onGetUserIcon(event::GetUserIconEvent& event) {
	long userId = event.getUserId();

	//画面内のリストを走査し、このユーザのアイコンを更新する
	int firstLine = GetVisibleBegin();
	int lastLine = GetVisibleEnd();

	for(int i=firstLine;i<=lastLine;i++){
		Tweet* tw = tweetList_->at(i);
		if(tw->getUser()->getId() == userId){
			RefreshLine(i);
		}
	}
}
Esempio n. 6
0
// gets called when we receive new data
void twitter_filter_cb(HTTPConnection* c, HTTPConnectionEvent event, 
                               const char* data, size_t len, void* user) 
{
  if(event == HTTP_ON_STATUS) {
    RX_VERBOSE("HTTP status: %d", c->parser.status_code);
  }
  else if(event == HTTP_ON_BODY) {
    // parse the tweet.
    std::string str(data, data+len);
    Tweet tweet;
    tweet.parseJSON(str);
    tweet.print();
  }
}
Esempio n. 7
0
//ツイートを読み込んだとき
void TweetList::onGetTweet(GetTweetEvent& event){
	vector<Tweet*>::iterator begin = tweetList_->begin();

	const vector<Tweet*>& loadedTweets = event.getTweetList();

	set<long> appearedUserIdSet;

	long lastTweetId = -1;

	for(int i= (loadedTweets.size() -1); i >= 0; i--){
		Tweet* tweet = loadedTweets.at(i);
		const User* user = tweet->getUser();
		cout << "(" << i << ")[" << *tweet->getText() << "]" << endl;

		if(appearedUserIdSet.find(user->getId()) == appearedUserIdSet.end()){
			appearedUserIdSet.insert(user->getId());

			wxString fileName = "images/user_icon/" + StringUtil::toStr(tweet->getUser()->getId()) + ".bmp";

			if(!util::FileUtil::exists(fileName)){
				//ユーザアイコンが読み込まれていなかったときは、別スレッドで読み込む
				DownloadUserIconTask* thread = new DownloadUserIconTask(this, user->getId(), user->getProfileImageUrl());
				if(thread->Create() != wxTHREAD_NO_ERROR){
					wxLogError(wxT("Can't create thread!"));
				}

				wxGetApp().add(thread);
				thread->Run();
			}
		}

		tweetList_->insert(tweetList_->begin(), tweet);
		lastTweetId = tweet->getId();
	}

	if(lastTweetId != -1){
		setLastReadTweetId(lastTweetId);
	}

	SetItemCount(tweetList_->size());
	RefreshAll();
}
/*
 * TweetListItemManager::updateItem(ListView* list,
                                      VisualNode* control, const QString& type,
                                      const QVariantList& indexPath,
                                      const QVariant& data)

   Implementation of ListItemManager::updateItem()
   Updates an item in the listview using the data provided
 */
void TweetListItemManager::updateItem(ListView* list,
                                      VisualNode* control, const QString& type,
                                      const QVariantList& indexPath,
                                      const QVariant& data)
{
    Q_UNUSED(list);
    Q_UNUSED(type);
    Q_UNUSED(indexPath);

    QObject* obj = qvariant_cast<QObject*>(data);
    Tweet* tweet = qobject_cast<Tweet*>(obj);
    if (tweet)
    {
        TweetItem* titem = static_cast<TweetItem*>(control);
        if (titem)
        {
            titem->updateItem(tweet->getText(), tweet->getDate());
        }
    }
}
Esempio n. 9
0
//右クリックされた際の処理
void TweetList::onListBoxRightClick(wxMouseEvent& event) {
	int x,y;
	event.GetPosition(&x,&y);
	int firstLine = GetVisibleBegin();
	int lastLine = GetVisibleEnd();

	Tweet* firstTweet = tweetList_->at(firstLine);
	Tweet* lastTweet = tweetList_->at(lastLine);

	cout << "First:" << *firstTweet->getText()<< endl;
	cout << "Last:" << *lastTweet->getText()<< endl;

	for(int i=firstLine;i<=lastLine;i++){
		wxRect rect = GetItemRect(i);
		if(rect.y <= y && y < (rect.y + rect.height)){
			cout << "ここが右クリックされた:" << *tweetList_->at(i)->getText() << endl;
			break;
		}
	}
}
Esempio n. 10
0
//--------------------------------------------------------------
void storeApp::update() {
	double timestamp = ofGetElapsedTimeMillis();
	while(receiver.hasWaitingMessages() )
	{
		// get the next message
		ofxOscMessage m;
		receiver.getNextMessage( &m );
		
		if ( m.getAddress() == "/test" )
		{
			
		}
		else if ( m.getAddress() == "/tweet" )
		{
			if (m.getNumArgs() >= 2)
			{
				string user = "";
				if (m.getArgType(0) == OFXOSC_TYPE_STRING)
				{
					user = m.getArgAsString(0);
				}
				string text = "";
				if (m.getArgType(1) == OFXOSC_TYPE_STRING)
				{
					text = m.getArgAsString(1);
				}
				
				if (user != "" && text!= "") {
					//ofDrawBitmapString( user + ": " + text, 80, 200 );
					//tweet = user + ": " + text;
					if (tweets->tweets->size() < 100)
					{
						tweets->push(new Tweet(user, text));
					}					
				}
			}
		}
		
	}
	
	if (ofGetElapsedTimeMillis() - timestamp > 10)
		cout << "msg parsed in " << ofGetElapsedTimeMillis() - timestamp << endl;
	
	if (ofGetElapsedTimeMillis() - lastTweetTime > 200)
	{
		if (tweets->tweets->size() > 0)
		{
			float margin = 20;
			Tweet *t = tweets->pop();
			string text = t->getUser() + ": " + t->getText();
			
			
			timestamp = ofGetElapsedTimeMillis();
			Tweet *newTweet = new Tweet(t->getUser(), t->getText());
			newTweet->textBlock.init(&defaultFont, &doubleSizedFont, &superSizedFont);
			newTweet->textBlock.setText(text);
			newTweet->textBlock.wrapTextInWidthHM(ofGetWidth()/6 - margin*2);
			newTweet->textBlock.setColor(255, 255, 255, 255);
			newTweet->bound = ofRectangle(
										  activeColumn * ofGetWidth()/6 + margin,
										  margin,
										  ofGetWidth()/6 - margin * 2,
										  ofGetHeight() - margin * 2
										  );
			newTweet->lastShownTime = ofGetElapsedTimeMillis();
			newTweet->live = true;
			
			tweetsOnShow->push(newTweet);
			//cout << "tweets on show: " << tweetsOnShow->tweets->size() << endl;
			
			tweets->tweets->pop_front();
			activeColumn = (activeColumn+1) % 6;
			
			if (tweetsOnShow->tweets->size() > 6)
			{
				tweetsOnShow->tweets->pop_front();
			}
			
			lastTweetTime = ofGetElapsedTimeMillis();
			
			cout << "new tweet init'd in " << ofGetElapsedTimeMillis() - timestamp << endl;
			
			//cout << tweets->tweets->size();
			//cout << " tweet in queue\n";
		}
		
	}
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
set<string> bobHash;
    string following;
    int num_users;
    map<string, User*> allUsers;
    // map<string, Tweet*> allTimeTrends;
    map<string, vector<Tweet*> > allTimeTrends;
    User* userObject;
    User* followingObject;
    User* userTweetingObject;
    Tweet* tweetObject;
    DateTime dateTimeObject;

    ifstream infile(argv[1]);

    if (infile.is_open())
    {
        string users;
        string username;

        if (infile.good())
        {
            // finds number of users
            getline(infile, users);
            stringstream ss(users);
            ss >> num_users;

            // for loop through num_users to get all users 
            for (int i = 0; i < num_users; i++)
            {
                string line;
                getline(infile, line);
                stringstream ss1(line);
                ss1 >> username;

                //if (!allUsers->contains(username))
                //if (!allUsers->find(username))
                //check if userObject has already been created before 
                map<string, User*>::iterator it;
                it = allUsers.find(username); // SLIDE 15 OF L13_STL
                if (it != allUsers.end())                
                {
                    // userObject = allUsers->find(username); // get User* object from allUsers map
                  userObject = it->second; //get User* object that's already in the allUsers map
                } else
                { 
                    userObject = new User(username); //new userObject created for new username
                    allUsers.insert(pair<string,User*>(username, userObject)); //allUsers map inserts userObject to the username key 
                }

                //gets the following from file
                string dummy; 
                dummy = line.substr(0, line.find_first_of(' '));
                line = line.substr(line.find_first_of(' ') +1);
                stringstream ss2(line);

                while (ss2 >> following)
                {
                    // check if followingObject has already been created before
                    map<string, User*>::iterator it1;
                    it1 = allUsers.find(following);
                    if (it1 != allUsers.end()) 
                    { 
                      followingObject = it1->second;
                      //   followingObject = new User(following);
                        // allUsers->insert(following, followingObject);
                    } else 
                    {
                      followingObject = new User(following);
                      allUsers.insert(pair<string,User*>(following, followingObject));
                        // followingObject = allUsers->get(following);
                    }

                    userObject->addFollowing(followingObject); //adds following to main user objects
                   //  cout << "test: " << userObject->following().size() << endl;
                   // cout << "user added following: " << userObject->name() << endl;
                   // cout << "following being added: " << followingObject->name() << endl;
                    
                    followingObject->addFollower(userObject); //adds main users to following object
                }  
            }
            // map<string, User*>::iterator it3;
            // cout << allUsers->size() << endl;
            // cout << allUsers->find("Mark")->first << endl;
       
          // User* jillUserObject = allUsers->find("Mark")->second;
          // cout << "user: "******"following size: " << jillFollowing.size() << endl;
          // cout << "followers size: " << jillUserObject->followers().size() << endl;

            // User* cur = *(jillFollowing.first());
            // while (cur != NULL)
            // {
            //  cout << cur->name() << endl;
            //  cur = *(jillFollowing.next());
            // }

          int hour, min, sec, year, month, day;
          char symbols;
          string text;
          string userTweeting;
          string tweet;
          
          while(getline(infile, text))
          {
            stringstream ss3(text);
            ss3 >> year >> symbols >> month >> symbols >> day >> hour >> symbols >> min >> symbols >> sec; //symbol stores unwanted symbols for date/time
            //cout << year << " " << month << " " << day << " " << hour << " " << min << " " << sec << endl;
            dateTimeObject = DateTime(hour, min, sec, year, month, day);

             string dummy1, dummy2; 
            // dummy1 = text.substr(0, text.find_first_of(' ')); //skip over date
            // userTweeting = text.substr(text.find(' ')+10); //skip over time

            // get user of tweet
            stringstream ss4(text);
            ss4 >> dummy1 >> dummy2 >> userTweeting;
            ss4.ignore(256,' '); //ignore whitespace after user of tweets and before tweets
            getline(ss4, tweet);

            map<string, User*>::iterator it2;
            it2 = allUsers.find(userTweeting);
            if (it2 != allUsers.end())
            {
              userTweetingObject = it2->second;
            }
            else
            {
              userTweetingObject = new User(userTweeting);
              allUsers.insert(pair<string,User*>(userTweeting, userTweetingObject));
            }

            tweetObject = new Tweet(userTweetingObject, dateTimeObject, tweet);
            userTweetingObject->addTweet(tweetObject);

            ///////////////////////////////////////@ mentions //////////////////////////////////////
            if (tweet[0] == '@')
            {
              tweet.erase(0,1);
              int pos = tweet.find(' ');
              string firstMention = tweet.substr(0,pos);
              //add to feed? displaying first user?? 
              //cout << firstMention << endl;
            }

            stringstream ss5(tweet);
            string userMention;
            while (ss5 >> userMention)
            {
              if (userMention[0] == '@')
              {
                userMention.erase(0,1);
                //cout << userMention << endl;
              }
            }
          
            ///////////////////////////////////////@ mentions ////////////////////////////////////// 

            /////////////////////////////////////// hashtags ////////////////////////////////////// 
            stringstream ss6(tweet);
            string hashtag;
            while (ss6 >> hashtag)
            {
              if (hashtag[0] == '#')
              {
                hashtag.erase(0,1);
        // map<string, User*>::iterator it2;
        // it2 = allUsers.find(username);
        // if(it2 != allUsers.end())
        // {
        //     userObject = it2->second;
        // }
                vector<Tweet*>curTweets;
                if (allTimeTrends.find(hashtag) != allTimeTrends.end())
                {
                 
                vector<Tweet *> curTweets = allTimeTrends.at(hashtag);
              }
                curTweets.push_back(tweetObject);
                allTimeTrends.insert(pair<string,vector<Tweet*> >(hashtag, curTweets));

                // allTimeTrends.insert(pair<string,Tweet*>(hashtag, tweetObject));
              }
            }
            tweetObject->addHashTags(hashtag);
            /////////////////////////////////////// hashtags ////////////////////////////////////// 
          }
          // Tweet* jillTweetObject = allTimeTrends.find("tbt")->second;
          // cout << "time: " << jillTweetObject->time() << endl;
          // string hash = allTimeTrends.find("tbt")->first;
          // cout << "hashtag: " << hash << endl;
          // set<string> jillHash = jillTweetObject->getHashTags();
          // cout << "size: " << jillHash.size() << endl;
          // for (set<string>::iterator it5 = jillHash.begin(); it5 != jillHash.end(); ++ it5)
          // {
          //   cout << *it5 << endl;
          // }
           // cout << "size of allTimeTrends: " << allTimeTrends.size() << endl;


          //Tweet* jillTweetObject = allUsers.find("Tommy")->second;

          //TESTING TWEETS
          // User* jillUserObject = allUsers.find("Sam")->second;
          // cout << "User: "******"Begin debugging getFeed" << endl;
          // vector<Tweet*> jillTweets = jillUserObject->getFeed();
          // //cout << "size: " << jillTweets.size() << endl;
          // set <string> jillHash;
          // for (unsigned int i = 0; i < jillTweets.size(); i++)
          // {
          //   jillHash = jillTweets[i]->getHashTags();
          //   // cout << jillTweets[i]->time() << " "
          //   // << jillTweets[i]->user()->name() << " "
          //   // << jillTweets[i]->text() << endl;
          //   //cout << jillTweets[i]->getHashTags() << endl;
          // }
          // cout << "size: " << jillHash.size() << endl;
          // for (set<string>::iterator it5 = jillHash.begin(); it5 != jillHash.end(); ++it5)
          // {
          //   cout << "hashtag; " << *it5 << endl;
          // }
        }
Esempio n. 12
0
void Twitter::onDataReceived()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    QString response;
    bool success = false;
    if (reply)
    {
        if (reply->error() == QNetworkReply::NoError)
        {
            int available = reply->bytesAvailable();
            if (available > 0)
            {
                int bufSize = sizeof(char) * available + sizeof(char);
                QByteArray buffer(bufSize, 0);
                reply->read(buffer.data(), available);
                response = QString(buffer);
                success = true;
            }
        }
        else
        {
            response =  QString("Error: ") + reply->errorString() + QString(" status:") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
            emit tweetParseComplete(false, "We can't connect to the internet");
        }
        reply->deleteLater();
    }
    if (success )
    {
    	if (response != "[]") {
    		bb::data::JsonDataAccess jda;
    		QVariant jsonva = jda.loadFromBuffer(response);
    		QVariantMap map = jsonva.toMap();
    		QVariantList results = map.value("results").toList();
    		//okay let's get the news items

    		int numTweets = 0;
    		foreach (QVariant v, results) {
    			QVariantMap map = v.toMap();

    			Tweet *tweet = new Tweet();
    			tweet->parse(v);

    			QVariant q = QVariant::fromValue(tweet);

        		_tweetList.append(q); //to go from a QVariant back to a Tweet* item: Tweet *Tweet = q.value<Tweet*>();

    			QVariantList path;
				path.append(_tweetList.indexOf(q));

				emit  itemAdded (path);
				numTweets++;
    		}

        	if (numTweets > 0) {
        		emit tweetParseComplete(true, "Parsed successfully");
        	} else {
        		if (_tweetList.count() == 0) {
        			emit tweetParseComplete(false, "No Tweets yet");
        		}
        	}
    	}
Esempio n. 13
0
 void serialize(Archive& ar) {
     tweet.api_serialize(ar);
 }
Esempio n. 14
0
void TweetQueryItem::setFavorited(bool favorited)
{
    Tweet tweet {item()->data()};
    tweet.setFavorited(favorited);
    setItem(std::move(tweet));
}
Esempio n. 15
0
void TweetQueryItem::setRetweeted(bool retweeted)
{
    Tweet tweet {item()->data()};
    tweet.setRetweeted(retweeted);
    setItem(std::move(tweet));
}
Esempio n. 16
0
int main(int argc, char * argv[]) {

    queue<Tweet *> tweetQueue;

    auto start = std::chrono::system_clock::now();

    // For testing purposes, add command line arguments
    if( argc == 2 && *argv[1] == '1')
        readTweets("../tweet_input/test_tweets.txt", tweetQueue);
    else if ( argc == 2 && *argv[1] == '2' )
        readTweets("../tweet_input/tweets_new.txt", tweetQueue);
    else
        readTweets("../tweet_input/tweets.txt", tweetQueue);

    int unicodeCount = 0;
    int count = tweetQueue.size();

    // Open both output files
    ofstream ft1("../tweet_output/ft1.txt");
    ofstream ft2("../tweet_output/ft2.txt");

    // Iterate over all tweets in order from time of arrival
    while(!tweetQueue.empty()) {

        Tweet * t = tweetQueue.front();
        tweetQueue.pop();

        //Write the information to file1
        ft1 << t->getTweetForFile();

        if( t->hadUnicode)
            unicodeCount++;

        //Generate all the connections for the graph
        generateConnections(t);

        //Get the average degree and write to the file
        double average = getAverageDegree();
        ft2 << average << '\n';

        //Clean up datastructures
        delete t->timestamp;
        delete t;
    }

    ft1 << '\n' << unicodeCount << " tweets contained unicode.";

    ft1.close();
    ft2.close();

    auto end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start);

    double secondsElapsed = elapsed.count() * 0.000001;

    cout << "Tweets Processed per Second: " << count / secondsElapsed << endl;

    // Remove nodes before exit
    std::map<string, Node *>::iterator it;
    for (it=globalMapOfNodes.begin(); it!=globalMapOfNodes.end(); ++it) {
        delete it->second;
    }

    return 0;
}