def __init__(self): self.twitter_handle = '' self.name = '' self.emotion = '' self.essay = False self.essay_path = '' self.songs = None self.books = None self.movies = None self.images = None self.quotes = None self.choice = None self.screen = 0 self.rec = Recommendations()
def clear(self): """ Clears user data """ self.twitter_handle = '' self.name = '' self.emotion = '' self.essay = False self.songs = None self.books = None self.movies = None self.images = None self.quotes = None self.choice = None self.rec = Recommendations()
def index(): name = None form = InputForm() country_name = form.country.data city = form.city.data if form.data["submit_country"] and country_name is not None: form.city.choices = city_choises(country_name) if form.data["submit_city"] and city != "None": weather = get_weather(city) rec = Recommendations(weather) return render_weather(weather, rec) return render_template('index.html', form=form, name=name)
def logout(): if "username" in session: session.pop("username", None) recommender.backup() return redirect(url_for("login")) @app.route("/delete") def delete(): if "username" in session: recommender.delete(session["username"]) return redirect(url_for("logout")) else: abort(403) if __name__ == "__main__": recommender = None if len(argv) > 0: try: cap = int(argv[1]) recommender = Recommendations(cap) except: print( "Argument not recognised, please provide an int to cap the ratings to or nothing at all.") exit() else: recommender = Recommendations(None) app.run(port=8080, debug=True)
class Data: def __init__(self): self.twitter_handle = '' self.name = '' self.emotion = '' self.essay = False self.essay_path = '' self.songs = None self.books = None self.movies = None self.images = None self.quotes = None self.choice = None self.screen = 0 self.rec = Recommendations() def set_twitter_handle(self, twitter_handle): self.twitter_handle = twitter_handle def get_twitter_handle(self): return self.twitter_handle def set_name(self, name): self.name = name def get_name(self): return self.name def set_essay(self, essay): self.essay = essay def get_essay(self): return self.essay def set_essay_path(self, path): self.essay_path = path def get_essay_path(self): return self.essay_path def set_emotion(self, emotion): self.emotion = emotion def get_emotion(self): return self.emotion def set_songs(self, songs): self.songs = songs def get_songs(self): return self.songs def set_books(self, books): self.books = books def get_books(self): return self.books def set_movies(self, movies): self.movies = movies def get_movies(self): return self.movies def set_images(self, images): self.images = images def get_images(self): return self.images def set_quotes(self, quotes): self.quotes = quotes def get_quotes(self): return self.quotes def set_choice(self, choice): self.choice = choice def get_choice(self): return self.choice def find_emotion(self): """ Identifies and sets the user's name and mood(emotion) """ if self.essay == False: self.set_name(get_name(self.twitter_handle)) self.set_emotion(get_twitter_emotion(self.twitter_handle)) else: self.set_emotion(get_essay_emotion(self.essay_path)) print('Your name :', self.get_name()) print('Your mood :', self.get_emotion()) def initialise_recommendations(self): """ Classifies the datasets if necessary """ self.rec.initialise_recommendations() def get_recommendations(self): """ Gets recommendations for the user based on their mood """ self.rec.get_recommendations(self.get_emotion(), self.get_choice()) with open(const.recs_path, 'rb') as handle: recs = pickle.load(handle) self.songs = recs[const.song_key] self.movies = recs[const.movie_key] self.books = recs[const.book_key] self.images = recs[const.image_key] self.quotes = recs[const.quote_key] def clear(self): """ Clears user data """ self.twitter_handle = '' self.name = '' self.emotion = '' self.essay = False self.songs = None self.books = None self.movies = None self.images = None self.quotes = None self.choice = None self.rec = Recommendations()
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Main module for App Engine app.""" from flask import Flask, jsonify, request from recommendations import Recommendations app = Flask(__name__) rec_util = Recommendations() DEFAULT_RECS = 5 @app.route('/recommendation', methods=['GET']) def recommendation(): """Given a user id, return a list of recommended item ids.""" user_address = request.args.get('user_address') num_recs = request.args.get('num_recs') # validate args if user_address is None: return 'No User address provided.', 400 if num_recs is None: num_recs = DEFAULT_RECS
from data_fetcher import DataFetcher from recommendations import Recommendations if __name__ == '__main__': file = '/Users/aggrom/Desktop/MSDS/5_Data_mining/Assignment_1/friend-recommender/data/facebook_combined.txt' percentages = [] algo_list = ['common_neighbors', 'jaccard', 'adamic_adar', 'cosine'] fetcher = DataFetcher(file) graph = fetcher.network_dict recommender = Recommendations(graph) recommender.compute_the_number_users_with_the_same_first_and_different_10_recommendations( ) percentages.append( recommender.compute_similarity_percentage('common_neighbors', 'jaccard')) percentages.append( recommender.compute_similarity_percentage('common_neighbors', 'adamic_adar')) percentages.append( recommender.compute_similarity_percentage('jaccard', 'adamic_adar')) percentages.append( recommender.compute_similarity_percentage('cosine', 'common_neighbors')) percentages.append( recommender.compute_similarity_percentage('cosine', 'jaccard')) percentages.append(
sleep_timer_set = True sleep_timer = Timer(sleep_interval, sleep_callback, args=[recommendations]) sleep_timer.start() else: sleep_timer_set = False if __name__ == '__main__': with open('credentials') as f: client_id = f.readline().strip() client_secret = f.readline().strip() authorization = Authorization(client_id, client_secret) access_token = authorization.get_access_token() recommendations = Recommendations(access_token) instance = Instance() while True: k = getch() if k == ' ': play_pause(recommendations, instance) elif k == '.': stop(recommendations) elif k == 'm': set_sleep_timer(recommendations, instance) elif k == 'q': sleep_timer_set = False if sleep_timer is not None: sleep_timer.cancel() sys.exit(0)