#include "ofApp.h" #define timtoken "3281768761.3dfcaf5.14ca9410c2aa4c00b9b60f36cd09d01a" #define hangdaitoken "3939854844.b31608d.a61a4e49a4dc40a688c22f4e0e81da3a" void ofApp::loadInstagramFeed(){ 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++) { vector tokens = ofSplitString(instagram.getImageCaption()[i]," ",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((*it).at(0)=='€'){ price=*it; foundPrice=true; } else{ if (!foundTags){ caption+=*it; caption+=" "; } } } if (interesting){ items[slot]=menuItem(caption,price); std::string id=instagram.getImageID()[i]; if (imagepool.find(id)==imagepool.end()){ imagepool[id]=ofImage(); getImages.loadFromURL(imagepool[id], instagram.getImageURL()[i]); ofLog(OF_LOG_NOTICE) << menutag << " " << slot << " " << caption << price << " " << id; } else { ofLog(OF_LOG_NOTICE) << "REUSE " << menutag << " " << slot << " " << id; } items[slot].image=&imagepool[id]; slot++; if (slot==IMAGE_SLOTS) break; } else ofLog(OF_LOG_NOTICE) << "instagram " << i << " " << price << " " << tags; //this is where we would clean up unused images in the pool } } lastPoll=ofGetElapsedTimef(); } //-------------------------------------------------------------- void ofApp::setup(){ ofTrueTypeFont::setGlobalDpi(150); myText.init("American Typewriter Regular.ttf", FONTSIZE*FACTOR, 'i'); background.load("images/background1080.png"); overlay.load("images/overlay1080.png"); instagram.setup(hangdaitoken,"self"); instagram.setCertFileLocation(ofToDataPath("ca-bundle.crt",false)); menutag=MENUTAG; loadInstagramFeed(); /* instagram.getUserRecentMedia("self"); //instagram.searchForTags("hangdai"); //ofLog(OF_LOG_NOTICE) << instagram["data"][0]["caption"]["text"].asString(); const Json::Value selfdata = instagram.getJSON()["data"]; for ( int index = 0; index < selfdata.size(); ++index ) // Iterates over the sequence elements. ofLog(OF_LOG_NOTICE) << selfdata[index]["caption"]["text"].asString(); */ //load ofSetFrameRate(5); } //-------------------------------------------------------------- void ofApp::update(){ ofBackground(255); } //-------------------------------------------------------------- void ofApp::draw(){ ofSetColor(255,255,255); ofPushMatrix(); //Store the coordinate system nexessary for some reason background.draw(0,0,1080*FACTOR,1920*FACTOR); //ofGetWidth(),ofGetHeight()); ofPopMatrix(); //Restore the coordinate system int colinitialoffset=40; int rowinitialoffset=60; int coloffset=520; int imgsize=480; int rowoffset=615; int col=0; int row=0; int cols=2; int textcolinset=10; int textrowinset=50; //some kind of rendering bug with textsuite means it has to go last or everything is dim if (!items.empty()) { for (int i = 0; i < items.size(); i++) { if (items[i].image->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(); }