#include "ofApp.h" #define timtoken "3281768761.3dfcaf5.14ca9410c2aa4c00b9b60f36cd09d01a" #define hangdaitoken "3939854844.b31608d.a61a4e49a4dc40a688c22f4e0e81da3a" std::string replaceStrChar(std::string str, const std::string& replace, char ch) { // set our locator equal to the first appearance of any character in replace size_t found = str.find_first_of(replace); while (found != std::string::npos) { // While our position in the sting is in range. str[found] = ch; // Change the character at position. found = str.find_first_of(replace, found+1); // Relocate again. } return str; // return our new string. } void ofApp::loadInstagramFeed(){ /* std::string test[5]; int testindex=0; for (int i=0;i<255;i++){ test[testindex]=" "+test[testindex]; test[testindex][0]=i; if (i==25||i==126||i==174||i==229) test[testindex]="\n"+test[testindex]; if (i==51||i==102||i==153||i==204) testindex++; } */ items.clear(); items.resize(IMAGE_SLOTS); instagram.getUserRecentMedia("self"); //instagram.getUserLikedMedia(12); ofLog(OF_LOG_NOTICE) << "instagram self feed -------------------> " << instagram.getImageURL().size() << " items "; //leave in verbose logging as ofxInstagram does anyway int slot=0; map newmenu; if (!instagram.getImageURL().empty()) { for ( int i = 0; i < instagram.getImageURL().size(); i++) { std::string str=replaceStrChar(instagram.getImageCaption()[i],"\n",' '); vector tokens = ofSplitString(str," ",true,true); //,ignoreEmpty=false,trim=false); std::string caption; std::string price; std::string tags; bool interesting=false; bool foundTags=false; bool foundPrice=false; for(auto it = tokens.begin(); it != tokens.end(); it++){ if((*it).at(0)=='#'){ if (!foundPrice){ price=""; foundPrice=true; } if (*it==menutag){ interesting=true; } tags+=*it; tags+=" "; foundTags=true; } else if(((uint8_t)(*it).at(0))==226){ price=*it; foundPrice=true; price[0]=36; //replace with dollar to use hacked truetype font ofLog(OF_LOG_NOTICE) << "price is "<isAllocated()) { int imgx=(colinitialoffset+(col*coloffset))*FACTOR; int imgy=(rowinitialoffset+(row*rowoffset))*FACTOR; items[i].image->draw(imgx,imgy,imgsize*FACTOR,imgsize*FACTOR); myText.setText(items[i].caption); myText.wrapTextX(imgsize*FACTOR); myText.setColor(255,255,255,255); myText.drawCenter(imgx+((imgsize*FACTOR)/2),imgy+((imgsize+textcolinset)*FACTOR),2); myText.setText(items[i].price); myText.wrapTextX(imgsize*FACTOR); myText.setColor(255,255,255,255); myText.drawCenter(imgx+((imgsize*FACTOR)/2),imgy+((imgsize+textcolinset+(FONTSPACING*2))*FACTOR),2); } col++; if (col==cols){ col=0; row++; } } } ofEnableAlphaBlending(); overlay.draw(0,0,1080*FACTOR,1920*FACTOR); //ofGetWidth(),ofGetHeight()); //don't work on a horiz screen?? ofDisableAlphaBlending(); if(ofGetElapsedTimef()-lastPoll>POLL_INTERVAL) { loadInstagramFeed(); } } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseEntered(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseExited(int x, int y){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } //-------------------------------------------------------------- void ofApp::exit() { getImages.stopThread(); }