diff --git a/db/loadAppsReviews.py b/db/loadAppsReviews.py deleted file mode 100644 index 3ea7e38..0000000 --- a/db/loadAppsReviews.py +++ /dev/null @@ -1,109 +0,0 @@ -from sqlalchemy import * -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker, relationship -import json -from itertools import islice, count -from pprint import pprint -from models.review import Review -from models.app import App - -engine = create_engine('postgresql://postgres:i219kkls@munners.dlinkddns.com:28432/obidroid') -Base = declarative_base() -Session = sessionmaker(bind=engine) -session = Session() - - -def parse_review_json(fname='../exports/rawdata_reviews.json'): - json_data = open(fname).read() - return json.loads(json_data) - -def parse_all_json(fname='../exports/game_brain_all.json'): - json_data = open(fname).read() - return json.loads(json_data) - -def calculateSingularRating(ratings): - total = 0; count = 0 - for rating in ratings: - total = total + (int(rating[0].strip()) * int(rating[1])) - count = count + int(rating[1]) - return total/float(count) - -def parse_reviews(): - # list container - review_list = list() - - # loop through the json file, first by app and then by reviews - for idx, app in enumerate(islice(parse_review_json(), None)): - for review in app['reviews']: - r = Review(app['appId'], review[0], review[1]) - review_list.append(r) - - # only commit all the review for every 10 apps - if idx % 25 == 0: - session.add_all(review_list) - session.commit() - review_list = list() - - # commit the rest of the review from the rest of the apps - session.add_all(review_list) - session.commit() - session.close() - -def parse_apps(): - # app container - app_list = list() - - # loop through the json file, first by app and then by reviews - for idx, app in enumerate(islice(parse_all_json(), 1)): - a = App(app['id'], app['category'], app['company'], app['contentRating'], - app['description'], app['install'], app['name'], calculateSingularRating(app['rating']), - app['screenCount'], app['size'], app['totalReviewers'], app['version']) - app_list.append(a) - - # only commit all the review for every 10 apps - if idx % 25 == 0: - session.add_all(app_list) - session.commit() - app_list = list() - - # commit the rest of the review from the rest of the apps - session.add_all(app_list) - session.commit() - session.close() - -def parse_all(): - # app and review list container - app_list = list() - review_list = list() - - # loop through the json file, first by app and then by reviews - for idx, app in enumerate(islice(parse_all_json(), None)): - - a = App(app['id'], app['category'], app['company'], app['contentRating'], - app['description'], app.get('devmail'), app.get('devprivacyurl'), app.get('devurl'), - app['install'], app['name'], calculateSingularRating(app['rating']), - app['screenCount'], app['size'], app['totalReviewers'], app['version']) - app_list.append(a) - for review in app['reviews']: - r = Review(app['id'], review[0], review[1]) - review_list.append(r) - - # only commit all the review for every 10 apps - if idx % 25 == 0: - session.add_all(app_list) - session.commit() - app_list = list() - session.add_all(review_list) - session.commit() - review_list = list() - - # commit the rest of the review from the rest of the apps - session.add_all(app_list) - session.commit() - session.add_all(review_list) - session.commit() - session.close() - -if __name__ == '__main__': - #main - parse_all() diff --git a/nginx_ws/conf/nginx.conf b/nginx_ws/conf/nginx.conf new file mode 100644 index 0000000..22df1ef --- /dev/null +++ b/nginx_ws/conf/nginx.conf @@ -0,0 +1,46 @@ +worker_processes 4; + +events {} + +http { + upstream database { + postgres_server 127.0.0.1 dbname=obidroid user=postgres password=i219kkls; + } + + server { + listen 8080; + server_name localhost; + + location /appsByCategory { + postgres_pass database; + rds_json on; + postgres_escape $category $arg_category; + postgres_query "SELECT * FROM app WHERE category=$category"; + postgres_rewrite HEAD GET no_rows 410; + } + + location /reviewByAppId { + postgres_pass database; + rds_json on; + postgres_escape $appid $arg_appid; + postgres_query HEAD GET "SELECT * FROM review WHERE playappid=$appid"; + postgres_rewrite HEAD GET no_rows 410; + } + + location /appByAppId { + postgres_pass database; + rds_json on; + postgres_escape $appid $arg_appid; + postgres_query HEAD GET "SELECT * FROM app WHERE appid=$appid"; + postgres_rewrite HEAD GET no_rows 410; + } + + location /reviewsByCategory { + postgres_pass database; + rds_json on; + postgres_escape $category $arg_category; + postgres_query HEAD GET "SELECT app.appid, review.title, review.review FROM app, review WHERE app.category=$category AND app.appid=review.playappid"; + postgres_rewrite HEAD GET no_rows 410; + } + } +}