Beispiel #1
0
def main():
    load_dotenv(dotenv_path='.env')

    elastic_search_host = os.getenv("ELASTIC_SEARCH_HOST")
    es = Elasticsearch([elastic_search_host], use_ssl=False)

    client = RecombeeClient(os.getenv("RECOMBEE_DATABASE_ID"),
                            os.getenv("RECOMBEE_PRIVATE_TOKEN"))
    num_recipes = es.count(index=os.getenv("ELASTIC_SEARCH_INDEX"),
                           body={"query": {
                               "match_all": {}
                           }})["count"]

    recipes = scan(client=es,
                   index=os.getenv("ELASTIC_SEARCH_INDEX"),
                   query={"query": {
                       "match_all": {}
                   }},
                   size=BATCH_SIZE,
                   scroll='1ms')
    requests = [
        SetItemValues(recipe['_id'], {
            'title': recipe['_source']['title'],
            'ingredients': recipe['_source']['ingredients'],
            'link': recipe['_source']['link'],
            'image': recipe['_source']['image'],
            'tags': recipe['_source']['tags'],
            'total_time': recipe['_source']['total_time'],
            'rating': recipe['_source']['rating'],
            'time_acquired': recipe['_source']['time_acquired'],
        },
                      cascade_create=True) for recipe in recipes
    ]
    client.send(Batch(requests))
Beispiel #2
0
def offer(request, offer_id):
    offer = Product.objects.all().filter(id=offer_id, is_offer=True)
    reviews = ProductsReview.objects.all().filter(product=offer_id)
    context = {
        'offer': offer,
        'reviews': reviews,
    }

    client = RecombeeClient(
        'e-market-dev',
        'S1HpoVU0JuxtjU9ewtvSnAUQh4qgKHTjr2DFbQ30LoADU2S27OsleTi1C23TNVEm')
    current_user = request.user

    r = AddDetailView(current_user.id, offer_id, cascade_create=True)
    client.send(r)

    recommended = client.send(
        RecommendItemsToItem(offer_id, current_user.id, 3))
    related = recommended['recomms']
    related_products_id = []
    for r in related:
        related_products_id.append(r['id'])
    related_products = []
    for id in related_products_id:
        prod = Product.objects.all().filter(id=id)
        related_products.append(prod)

    context['suggested_offers'] = related_products

    return render(request, 'listings/offer.html', context)
Beispiel #3
0
def listing(request, product_id):
    if (request.method == 'POST'):
        if (request.POST['star1'] == 'active'):
            stars = 1
        elif (request.POST['star2'] == 'active'):
            stars = 2
        elif (request.POST['star3'] == 'active'):
            stars = 3
        elif (request.POST['star4'] == 'active'):
            stars = 4
        elif (request.POST['star5'] == 'active'):
            stars = 5
        #if user didn't make any rating
        else:
            stars = 0
        review = request.POST['review']
        # product = Product.objects.all().filter(id=product_id)
        product_review = ProductsReview.objects.create(product_id=product_id,
                                                       user_id=request.user.id,
                                                       review=review,
                                                       rating=stars)
        submit_product_review(product_id)

    product = Product.objects.all().filter(id=product_id)
    reviews = ProductsReview.objects.all().filter(product=product_id)
    client = RecombeeClient(
        'e-market-dev',
        'S1HpoVU0JuxtjU9ewtvSnAUQh4qgKHTjr2DFbQ30LoADU2S27OsleTi1C23TNVEm')
    current_user = request.user
    if (current_user.is_authenticated):
        current_user_id = current_user.id
    else:
        current_user_id = 0
    r = AddDetailView(current_user_id, product_id, cascade_create=True)
    client.send(r)
    recommended = client.send(
        RecommendItemsToItem(product_id, current_user_id, 3))
    related = recommended['recomms']
    related_products_id = []
    for r in related:
        related_products_id.append(r['id'])
    related_products = []
    for id in related_products_id:
        prod = Product.objects.all().filter(id=id)
        related_products.append(prod)

    # for prod in recommended:
    #     print(f"prod {prod}")

    avg_rating = get_avg_rating(product_id)

    context = {
        'product': product,
        'reviews': reviews,
        'avg_rating': round(avg_rating, 1),
        'related_products': related_products,
    }

    return render(request, 'listings/listing.html', context)
Beispiel #4
0
def index(request):
    categories = Category.objects.all()
    product = Product.objects.all()
    current_user = request.user
    client = RecombeeClient(
        'e-market-dev',
        'S1HpoVU0JuxtjU9ewtvSnAUQh4qgKHTjr2DFbQ30LoADU2S27OsleTi1C23TNVEm')
    prods = Product.objects.order_by('-sold')[:6]
    best_sellers = sorted(prods, key=operator.attrgetter('sold'), reverse=True)
    print(f"best_sellers: {best_sellers}")

    context = {
        'categories': categories,
        'best_sellers': best_sellers,
    }

    # recomender
    # if (request.user.is_authenticated):
    # print("auth")
    if (not request.user.is_authenticated):
        current_user_id = 0
    else:
        current_user_id = current_user.id
    recommended = client.send(
        RecommendItemsToUser(current_user_id, 5, cascade_create=True))
    # print(recommended)
    client = RecombeeClient(
        'e-market-dev',
        'S1HpoVU0JuxtjU9ewtvSnAUQh4qgKHTjr2DFbQ30LoADU2S27OsleTi1C23TNVEm')
    current_user = request.user
    recommended = client.send(RecommendItemsToUser(current_user_id, 3))
    print(f"Related products: {recommended}")
    suggested = recommended['recomms']
    suggested_products_id = []
    for r in suggested:
        suggested_products_id.append(r['id'])
    suggested_products = []
    for id in suggested_products_id:
        prod = Product.objects.all().filter(id=id)
        suggested_products.append(prod)
    print(f"related: {suggested_products}")
    context['suggested_products'] = suggested_products

    return render(request, 'pages/index.html', context)
Beispiel #5
0
 def get(self, user_id):
     _ = get_token_info()
     client = RecombeeClient(
         'globalhack',
         'QluRxG1ZkI3kRKvukeXpscV4kRcTxIPAIYbxVjlD14FJlhS0rLdVYVxv25NNeBYC')
     try:
         # get the recommendation
         response = client.send(RecommendItemsToUser(user_id, 5))
         return make_response(jsonify(response))
     except Exception:
         abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
Beispiel #6
0
def init_crawler(num=0, init=0):
    es = connect_to_es()
    client = RecombeeClient(os.getenv("RECOMBEE_DATABASE_ID"), os.getenv("RECOMBEE_PRIVATE_TOKEN"))
    #Create a crawling process for all crawlers to make use of Scrapy's concurrency
    process = CrawlerProcess(settings=get_project_settings())
    for host, site in URLS.items():
        #Create an instance of each site's crawler
        obj = site(math.floor(num / len(URLS.items())), init)
        #Instruct the process to crawl each individual site, but only start the actual crawling process once they're all ready
        obj.crawl(es, client, process)
    process.start()
    process.stop()
Beispiel #7
0
    def __init__(self, *args, **kwargs):
        super(RecombeeTest, self).__init__(*args, **kwargs)

        db_id = os.environ.get('DB_ID')
        if db_id is None:
            raise MissingEnvironmentVariable('DB_ID env var must be specified')

        token = os.environ.get('PRIVATE_TOKEN')
        if token is None:
            raise MissingEnvironmentVariable(
                'PRIVATE_TOKEN env var must be specified')

        self.client = RecombeeClient(db_id, token, region=Region.EU_WEST)
Beispiel #8
0
 def post(self, user_id, service_id):
     _ = get_token_info()
     client = RecombeeClient(
         'globalhack',
         'QluRxG1ZkI3kRKvukeXpscV4kRcTxIPAIYbxVjlD14FJlhS0rLdVYVxv25NNeBYC')
     request = AddPurchase(user_id, service_id, cascade_create=True)
     purchase_requests = [request]
     try:
         # Send the data to Recombee, use Batch for faster processing of larger data
         response = client.send(Batch(purchase_requests))
         return make_response(jsonify(response))
     except Exception:
         abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
Beispiel #9
0
def update_item(request):

    #data mining setup
    client = RecombeeClient(
        'e-market-dev',
        'S1HpoVU0JuxtjU9ewtvSnAUQh4qgKHTjr2DFbQ30LoADU2S27OsleTi1C23TNVEm')

    data = json.loads(request.body)
    productId = data['productId']
    action = data['action']

    current_user = request.user
    product = Product.objects.get(id=productId)
    product.sold = product.sold + 1
    product.save()
    order, created = Order.objects.get_or_create(user=current_user,
                                                 complete=False)
    orderItem, created = OrderItem.objects.get_or_create(order=order,
                                                         product=product)

    if (action == 'add'):
        print(f"usre ID: {current_user.id}, product ID: {product.id}")
        r = AddPurchase(current_user.id,
                        product.id,
                        timestamp=time.time(),
                        cascade_create=True)
        client.send(r)
        orderItem.quantity = (orderItem.quantity + 1)
        product.quantity = (product.quantity - 1)
        if (product.quantity <= 0):
            product.in_stock = False
            product.save()
        else:
            product.quantity = product.quantity - 1
            product.save()
    elif (action == 'remove'):
        orderItem.quantity = (orderItem.quantity - 1)
        product.quantity = (product.quantity + 1)
        product.save()

    orderItem.save()

    if (orderItem.quantity <= 0):
        orderItem.delete()

    print(f'Action: {action}, productId: {productId}')
    return JsonResponse('Item was added', safe=False)
Beispiel #10
0
def push_zion(database, token, prod_list, user, timestamp=False):
    items = get_global_dic(prod_list, user)
    print(items)
    client = RecombeeClient(database, token)
    if timestamp:
        requests = []
        for item in items:
            r = AddPurchase(item['user_id'],
                            item['item_id'],
                            timestamp=item['timestamp'],
                            cascade_create=True)
            client.send(r)
        requests = []
        for item in items:
            r = AddDetailView(item['user_id'],
                              item['item_id'],
                              timestamp=item['timestamp'],
                              cascade_create=True)
            requests.append(r)
        br = Batch(requests)
        client.send(br)
    else:
        requests = []
        for item in items:
            r = AddPurchase(item['user_id'],
                            item['item_id'],
                            cascade_create=True)
            client.send(r)

        requests = []
        for item in items:
            r = AddDetailView(item['user_id'],
                              item['item_id'],
                              cascade_create=True)
            requests.append(r)
            br = Batch(requests)
            client.send(br)
    print('Done')
import recombee_api_client
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.api_requests import *
from .find_charity import *
from .user_data import *
import json
import redis
from .. import firebase
import os

num_recs = 10
user = '******'
db_name = "team-2"
secret_token = "SFgtcueq51BZqYNKN8QMm9HuuWCN0lPOtUTZpwjg8uquAQ1ggzLtrEMaBceN9AD9"
client = RecombeeClient(db_name, secret_token)

global all_charity_data

# client.send(AddItemProperty('cause', 'string'))
# client.send(AddItemProperty('rating', 'int'))
# client.send(AddItemProperty('state', 'string'))


def output_dict():
    return

    all_charity_data = output_all()
    print('done getting charities')

    db = connect_to_db()
Beispiel #12
0
#run this file one time to seed DB at Recombee.com

from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.api_requests import *
import json
import os  # to access OS environment variables

client = RecombeeClient(os.environ['DB_NAME'], os.environ['SECRET_TOKEN'])

with open('static/dataset/movie_user_ratings.json') as fdata:
    interactions = json.loads(fdata.read())

requests = []
#interate through all interactions and create object for each interaction
for interaction in interactions:
    r = AddRating(interaction['userid'],
                  interaction['imdbid'],
                  interaction['rating'],
                  cascade_create=True)

    #making a list of interactions
    requests.append(r)

br = Batch(requests)
try:
    # Send the data to Recombee, use Batch for faster processing of larger data
    print('Send ratings')
    client.send(br)

except APIException as e:
    print(e)
import recombee_api_client
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.api_requests import *
from .find_charity import *
from .user_data import *
import json
from rounded.core import redis
from .. import firebase
import os
from flask import current_app as app

num_recs = 10
user = '******'

client = RecombeeClient(*app.config.get("RECOMBEE"))

global all_charity_data

# client.send(AddItemProperty('cause', 'string'))
# client.send(AddItemProperty('rating', 'int'))
# client.send(AddItemProperty('state', 'string'))

# def output_dict():
# 	return

# 	all_charity_data = output_all()
# 	print('done getting charities')

# 	# db = connect_to_db()

# 	db = redis.from_url(url)
Beispiel #14
0
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.api_requests import *
import csv

client = RecombeeClient(
    'wt-proj',
    'gVEMJ5zdYOleXwlX4MyCtExwaa8MgAFgejz0W7TPa8kB1Qebtp1t0OvESDDdwrmO')

purchases = []

with open('purchaseRecord.csv') as csvfile:
    csvreader = csv.reader(csvfile)
    for row in csvreader:
        user_id = row[0]
        item_id = row[1]
        r = AddPurchase(user_id, item_id, cascade_create=True)
        purchases.append(r)

br = Batch(purchases)
print(br)
client.send(br)

recommended = client.send(UserBasedRecommendation('0', 5))
print(recommended)
Beispiel #15
0
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.api_requests import *

client = RecombeeClient(
    'hanoi-university-of-science-and-technology-dev',
    'Q1NZZQ9do57L9rFjJtN293YZzInHoVGWjFogWIYiAQR8cHAyKw32eB2zAYSPurnH')
# client.send(AddUserProperty('address', 'string'))

# client.send(SetUserValues('0',{'id_account':0},cascade_create=True))

# client.send(AddItemProperty('id_shoes', 'int'))
# client.send(AddItemProperty('shoes_name', 'string'))
# client.send(AddItemProperty('shoes_type', 'string'))
# client.send(AddItemProperty('gender_shoes', 'string'))
# client.send(AddItemProperty('feature', 'string'))
# client.send(AddItemProperty('price', 'double'))
# client.send(AddItemProperty('sale', 'int'))
# client.send(AddItemProperty('athleter', 'string'))
# client.send(AddItemProperty('catalogy', 'string'))
# client.send(AddItemProperty('describe', 'string'))
# client.send(AddItemProperty('surface', 'set'))
# client.send(AddItemProperty('color', 'set'))
# client.send(AddItemProperty('image', 'string'))

# client.send(DeleteItem('xyz'))
# client.send(DeleteItem('6'))
Beispiel #16
0
from flask import Flask
from flask import request
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.exceptions import APIException
from recombee_api_client.api_requests import AddPurchase, RecommendItemsToUser, Batch, ResetDatabase
from time import sleep
import random

client = RecombeeClient('--my-database-id--', '--db-private-token--')
app = Flask(__name__)


@app.route('/', methods=["POST"])
def hello():
    data = request.get_json()
    try:
        recommended = client.send(RecommendItemsToUser(data['user'], 5))
        return recommended
    except:
        return "Failed to Get Data"


@app.route("/reset", methods=['POST'])
def reset():
    purchase_requests = []
    data = request.get_json()
    client.send(ResetDatabase())

    sleep(5)

    for d in data:
Beispiel #17
0
private_key_of_account = inp['key']

#private local Ethereum blockchain
w3 = Web3(Web3.HTTPProvider("http://*****:*****@app.route('/Process', methods=['POST'])
def Process():
    """ Processes requests from GeniSys AI E-Commerce Magic Leap Application. """

    if frequest.headers["Content-Type"] == "application/json":
        query = frequest.json

        #send action to smart contract
        nonce = w3.eth.getTransactionCount(msg_sender_address)
        transaction = myContract.functions.addDataCollected(
Beispiel #18
0
sid = SentimentIntensityAnalyzer()

from pytrends.request import TrendReq
pytrends = TrendReq(hl='en-US', tz=360)
# Create your views here.

ckey = "7h38tcEM8IO8id2htVXO9NDoW"
csecret = "A9zfCDyM8mx7P2LBaC9rkCIgoOV3P71ZCajKbn2l0tt4EnkObk"
atoken = "2611228746-JSr7EbtntCKlcAjZl5PkvVFxq8sYyzhamjvYYXg"
asecret = "45c3EKZBxdI86ssyoR3gypx0ffIZGFyjlgcsznft2SToD"

API_KEY = '63XAFJTFC5HF4OE9'
fenil_key = "FQFTFEI83XPWMSPQ"

client = RecombeeClient(
    'stockmanager',
    'Y9UsOCsqPBetEKgFtmatmcdBeifBwcFqgXTAYhVpu5hEPBh31DmQ18JC5w0hqqbb')


@login_required(login_url='/login/')
def stockform(request):
    if request.method == 'GET':
        return render(request, 'stock/stockform.html')
    elif request.method == 'POST':
        user = request.user
        name = request.POST.get('name', '')
        date = request.POST.get('date', '')
        type = request.POST['type_investment']
        quantity = request.POST.get('quantity', '')
        method = request.POST['type_transaction']
        price = request.POST.get('price', '')
Beispiel #19
0
 def __init__(self):
     print("recombee client was initiatlized")
     client = RecombeeClient(DB_NAME, API_KEY)
     self.recombee_client = client
Beispiel #20
0
	def load_recombee(self):
		self.recombee_client = RecombeeClient(self.app.config['RECOMBEE_DB'], self.app.config['RECOMBEE_KEY'])
import csv
import random
from .models import *
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.exceptions import APIException
from recombee_api_client.api_requests import *

client = RecombeeClient(
    'tvseries',
    'IG1t5vSWYgpJvClpbJZUn29oqnCu6QnIHoJdm9u5dRLom47i0WrpWrNKcZ9om21x')

requests = []
list_of_ratings = SeriesRating.objects.all()
print(list_of_ratings)
print(len(list_of_ratings))
for i in range(0, len(list_of_ratings)):
    name = list_of_ratings[i].user.id
    series = list_of_ratings[i].series.id
    rate = list_of_ratings[i].rating
    rate = (rate - 10) / 10
    print(str(name) + ' ' + str(series) + ' ' + str(rate))
    request = AddRating(name, series, rate, cascade_create=True)
    requests.append(request)

print(len(requests))
print(requests)
try:
    print('sending')
    client.send(Batch(requests))
    print('Send')
except APIException as e:
Beispiel #22
0
 def __init__(self, *args, **kwargs):
     super(RecombeeTest, self).__init__(*args, **kwargs)
     self.client = RecombeeClient(
         'client-test',
         'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L')
Beispiel #23
0
from .models import Item
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from users.models import Profile
from django.contrib import messages
from django.views.generic import TemplateView, ListView
from django.db.models import Q
from .forms import SearchForm
from django.core.paginator import Paginator
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.exceptions import APIException
from recombee_api_client.api_requests import *
# Create your views here.

client = RecombeeClient(
    'university-of-jordan-dev',
    'sMGOTwMPzOPM3l6Tmxs8jXZ2WeCskPR9dnzKrdBczJHy1vdRFQs9HldcLPC8W63N')


@login_required
def recommend(request):
    user_profile = request.user.profile
    if user_profile.gender is None or user_profile.user_style is None or user_profile.user_class is None or user_profile.user_brands is None:
        messages.info(
            request,
            'Please fill out some information for better cusotmized recommendations'
        )
        return redirect('update_profile_initial')

    user_id = str(
        User.objects.filter(username=request.user.username).first().id)
Beispiel #24
0
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.exceptions import APIException
from recombee_api_client.api_requests import *

client = RecombeeClient(
    'moodsic-dev',
    'Pb4MhOK6751HmdEGmvISdFJqXjLDWEtVkyb2AIY4Cn1EL3vQWy9V0B236OGEj8iy')

#For reseting the database before changing the model
client.send(ResetDatabase())

#########################################
# WARNING Recombee API creates some problems when you're trying to add an object
# when it already exists, therefore if you want to build the model of the database, you have to
# erase the whole database first, this is the best way yet
# adendum: requst should be done in certain order
#
# PrimaryKey means that we will transfer PrimaryKeys from our server database to the recombee database as id-s
##########################################

#DATA  MODELS FOR USERS AND MUSIC

client.send(AddUserProperty("username", "string"))
client.send(AddUserProperty("usualMood", "string"))
client.send(AddUserProperty("age", "int"))

#this can be good enough for our needs
client.send(AddItemProperty("mood", "string"))
client.send(AddItemProperty("length", "double"))
client.send(AddItemProperty("title", "string"))
client.send(AddItemProperty("viewCount", "int"))
import csv
# from bookdb.models import *
import random
# from django.db import transaction
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.exceptions import APIException
from recombee_api_client.api_requests import *

client = RecombeeClient(
    'wd-project',
    'DDf4VljyLxNsbdLtWT1jueFbVsanOWCwbEW59cTpp1W3LB3JlpeT3jqZQ1k7S7sN')

# @transaction.atomic
# def main():
# 	with open('BX-CSV-Dump/BX-Users.csv', encoding='utf-8') as f:
# 		reader = list(csv.reader(f, delimiter=';'))

# 		# Skipping the headers
# 		# next(reader)
# 		print("Result =", len(reader))
# 		count = 0
# 		# transaction.set_autocommit(False)
# 		with transaction.atomic():
# 			for row in reader[1:]:
# 				count += 1
# 				# if User.objects.filter(id=int(row[0])).count() == 0:
# 				user = User(id=int(row[0]))
# 				user.username = str(user.id)
# 				user.set_password('pass@123')
# 				user.is_superuser = True
# 				user.is_staff = True
Beispiel #26
0
from recombee_api_client.api_client import RecombeeClient
from recombee_api_client.api_requests import *
client = RecombeeClient(
    'sns', 'cqLZqZnboKlyVKS7EhhYYyM8BflGRDlizngZbljA3kp67tjd1FKfH3WaXLNSXl7F')
count = 1
users = []
for i in range(1, 102):
    request = DeleteUser(str(count))
    count = count + 1
    users.append(request)
try:
    print('sending')
    client.send(Batch(users))
    print('sent')

except APIException as e:
    print(e)
Beispiel #27
0
def pred_prod(database, token, USER, NUMBER):
    client = RecombeeClient(database, token)
    recommended = client.send(RecommendItemsToUser(USER, 5))
    print(recommended)