def getData(self): # Set up a client to talk to the Semantics3 API using your Semantics3 API Credentials sem3 = Products(api_key=self.apikey, api_secret=self.apisecret) sem3.products_field("site", self.site) sem3.products_field("sitedetails_display", ("include", [self.site])) sem3.products_field("offset", self.offset) sem3.products_field("limit", self.limit) results = sem3.get_products() ds = json.dumps(results) self.writeData(ds) return ds
def make_query(item_name): products = Products( api_key='SEM3A92F1C506BB40F217AA3716D7C9A8815', api_secret='ZGU0MWJiNjY1ZTY1OTgxZDVhODFiYWNkYzNkOTBjZjA') products.products_field('name', item_name) result_query = products.get_products() code = result_query['code'] result_list = result_query['results'] result_count = result_query['results_count'] return code, result_list, result_count
def user_profile(request): sem3 = Products( api_key = "SEM3CCB4BBBB383C73986C4B27B9BE4B3088", api_secret = "YmJjY2M1YzFlMGM0ZTg1OTdlNDFkYmY5MmRmZTg2ZDk" ) if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): form.save() searchInput = form.cleaned_data.get('input') sem3.products_field("search", searchInput) results = sem3.get_products() return render(request, 'user_profile.html', results) else: return render(request, 'user_profile.html')
def isUpcExist(code): product = Products(SEMANTIC_PUBLIC, SEMANTIC_SECRET) product.products_field("upc", str(code)) results = product.get_products() # a = ['CD','DVD', 'CD()'] # yes = results['results'][0]['format'] # count = 0 # for x in range(1,len(a)): # if(yes == a[x]): # print('{} == {}'.format(a[:],yes)) # count += 1 # else: # print('Error') if results['results_count'] == 1: return results, True else: print("not exist") return results, False
def import_shoes(apps, schema_editor): # We can't import the Person model directly as it may be a newer # version than this migration expects. We use the historical version. Shoe = apps.get_model("product", "Product") products = Products( api_key="SEM383288C8F0304F7BB107E2E110B0420D3", api_secret="MGYwZjgxZTVkOTVmZmY5OTEwYzlkMWI4MDAxMzk3YjA") products.products_field("name", "Shoes") products.products_field("limit", 100) results = products.get_products() resultarr = results['results'] count = 1 for i, var in enumerate(resultarr): s = Shoe(id=count, name=var['name'], price=Decimal(var['price']), stock=1, description=var['category']) s.save() count = count + 1
def post(self, request, *args, **kwargs): product_serializer = ProductSerializer(data=request.data) if product_serializer.is_valid(): product_serializer.save() upc = product_serializer.data['upc'] ean = product_serializer.data['ean'] sem3 = Products( api_key="SEM358802643C8595EA80A4BA5F74DB35FD9", api_secret="ZDhkMDJiNmEzMzdlMzVmZmQwNmNmZGVhODE4ZjQ4ZGQ") if ean or len(ean) > 5: print("EAN in") sem3.products_field("ean", ean) elif upc or len(upc) > 5: print("UPC in") sem3.products_field("upc", upc) sem3.products_field("fields", ["name", "gtins"]) p = "product not found" # Run the request try: results = sem3.get_products() print(results) p = results['results'][0]['name'] except: print('An error occured.') # View the results of the request print(p) return Response({ "upc": product_serializer.data, "result": p }, status=status.HTTP_201_CREATED) else: return Response(product_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get_recommendations(name, brand=None): k = keys.Keys() # categories = Categories( # api_key = k.get_semantics_api_key(), # api_secret = k.get_semantics_secret_key() # ) products = Products(api_key=k.get_semantics_api_key(), api_secret=k.get_semantics_secret_key()) products.products_field("search", name) if brand != None: products.products_field("brand", brand) products.products_field("variation_includeall", 0) products.products_field("limit", 10) results = products.get() output = [] for r in results["results"]: data = {} try: data['image'] = r["images"][0] except: pass data['url'] = r['sitedetails'][0]["url"] try: data['price'] = r['sitedetails'][0]["latestoffers"][0]["price"] except: pass try: data['brand'] = r['brand'] except: pass data['title'] = r['name'] data['status'] = True output.append(data) return {"results": output}
from semantics3 import Products sem3 = Products(api_key="SEM310D8563D0E07BA3AC280829F8076605D", api_secret="ZTliZjI1NTg5ZDQ2ZjdhNDMyNmRmMTc4Mjg3NjJmN2M") product_list = ['laptop', 'phone'] results = [] all_products = [] for product in product_list: sem3.products_field("search", product) results = sem3.get_products() if product == 'laptop': for i, p in enumerate(results['results']): title = results['results'][i]['name'] price = results['results'][i]['price'] if 'color' in results['results'][i].keys(): color = results['results'][i]['color'] else: color = None image = results['results'][i]['images'] url = results['results'][i]['sitedetails'][0]['url'] product_data = { 'product': 'Laptop', 'title': title, 'price': price, 'color': color, 'image': image, 'url': url, } if product == 'phone':
import food2fork as f2f import world_openfoodfacts as woff import ingredients_parser as ip import utils as u import json, sys import food_ndtv_parser as food_ndfv from semantics3 import Products import time sem3 = Products(api_key="SEM37B78A6306695816904F3BB8C677F71D8", api_secret="OTg4OWJiN2ZhZjc0Y2Q5ZjJhODIyNDE2MzhhZDM2ZmY") def f2f_api(): result = f2f.send_requests(11, 16) links = f2f.parse_api_response(result) recipes = [] for website in f2f.valid_websites.keys(): data = f2f.get_recipes_html(links[website]) recipes.extend(f2f.valid_websites[website](data)) d = dict() d["count"] = len(recipes) d["recipies"] = recipes # print(d) u.write(json.dumps(d), "food2fork") def ing_with_categ(): ingredients_with_category = food_ndfv.parse() u.write(json.dumps(ingredients_with_category), "ingredients_with_category", "")
from semantics3 import Products import unittest from os import environ sem3 = Products(api_key=environ["SEM3_API_KEY"], api_secret=environ["SEM3_API_SECRET"]) class TestProductAPI(unittest.TestCase): """Docstring for TestProductAPI. """ def test_get_products(self): """@todo: Docstring for test_get_products. :returns: @todo """ sem3.products_field("search", "iphone") results = sem3.get_products() self.assertEqual(results['code'], 'OK') sem3.clear_query() def test_upc_query(self): """@todo: Docstring for test_upc_query. :returns: @todo """ pass sem3.products_field("upc", "883974958450") sem3.products_field("field", ["name", "gtins"]) results = sem3.get_products() self.assertEqual(results['code'], 'OK') sem3.clear_query()
# Here I am importing the "decimal" module, which will help me find the average price of the search later. from decimal import Decimal # Here I am importing the "textblob" module which will help me to find the sentiment of the string by first "globbing" the string together. from textblob import TextBlob # Here I am importing all of the external functions from my "functions.py" file, which I will use later. from functions import input_sentiment, crosscheck_email, character_counter # Code Citation: Semantics 3 API Documentation # URL: https://docs.semantics3.com/reference#keyword-api-1 # Author: Semantics3 # Accessed on: 4/3/18 # Purpose of code: The API key and secret will be passed along with the request, allowing me to access a response. sem3 = Products(api_key="SEM3D4E92E7495711694BF8E16042CB789B7", api_secret="NjJmYWI3ZDQyZGZmMzk4ZjkwNjMzNWUxZjM0YjU0ODQ") # I defined all of the global variables below. user_list = [] email_list = [] password_list = [] price_list = [] username = "" return_user = "" return_item_num = ""
pip install semantics3 SEM3KEY y SEM3S son la API key y el API secret que se obtiene al darse de alta como usuario. La version demo permite hacer 500 queries diarias por usuario. :Authors: bejar :Version: :Created on: 25/02/2016 15:27 """ from semantics3 import Products from AgentUtil.APIKeys import SEM3KEY, SEM3SECRET import pprint __author__ = 'bejar' if __name__ == '__main__': sem3 = Products(api_key=SEM3KEY, api_secret=SEM3SECRET) sem3.products_field("search", "iphone") # Run the request results = sem3.get_products() # View the results of the request pprint.pprint(results['results'])
def __init__(self): self.api_key = 'SEM30A3983D93A26181838BA0FA228979B01' self.api_secret = 'OWFiNmE3YTU2NDljNDliNDU4ZDczZTk1ZmU3MTgzMDE' self.wrapper = Products(api_key=self.api_key, api_secret=self.api_secret)
from sqlalchemy.exc import DBAPIError from pyramid.response import Response from pyramid.view import view_config from pyramid.response import Response from pyramid.httpexceptions import HTTPFound, HTTPNotFound, HTTPBadRequest from pyramid.security import NO_PERMISSION_REQUIRED, remember, forget from ..sample_data import MOCK_DATA import requests import json from ..models import Account from semantics3 import Products sem3 = Products(api_key="SEM3B4C97C14B003A87822E95D682C8847F2", api_secret="ZWVmOGUxNDg1YjM1ZTNjZjMwNTI1Zjk4MjA5MThhNTg") @view_config(route_name='home', renderer='../templates/base.jinja2', request_method='GET', permission=NO_PERMISSION_REQUIRED) def index_view(request): """ Directs user to the home template """ return {} @view_config(route_name='about', renderer='../templates/about_us.jinja2', request_method='GET',
def __init__(self): self.products = Products(api_key="xx", api_secret="xx")
from semantics3 import Products import unittest sem3 = Products(api_key="", api_secret="") class TestProductAPI(unittest.TestCase): """Docstring for TestProductAPI. """ def test_get_products(self): """@todo: Docstring for test_get_products. :returns: @todo """ sem3.products_field("search", "iphone") results = sem3.get_products() self.assertEqual(results['code'], 'OK') sem3.clear_query() def test_upc_query(self): """@todo: Docstring for test_upc_query. :returns: @todo """ pass sem3.products_field("upc", "883974958450") sem3.products_field("field", ["name", "gtins"]) results = sem3.get_products() self.assertEqual(results['code'], 'OK') sem3.clear_query() def test_url_query(self):
import requests, json from flask import Flask, render_template, request, redirect, url_for from flask_sqlalchemy import SQLAlchemy from semantics3 import Products import MySQLdb app = Flask(__name__) #Set up a client to talk to the Semantics3 API using your Semantics3 API Credentials sem3 = Products(api_key="SEM322EF6FCE667BE9ED88826363DE85E0A2", api_secret="NmI4OTU5ZmVjZTVkZDNlODhmYmZmN2Q2ZTkyMmQ2OTY") #Configure the Database app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql://*****:*****@sql9.freemysqlhosting.net:3306/sql9240288' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) class WishList(db.Model): #__tablename__ = "wish_list" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) price = db.Column(db.String(10)) url = db.Column(db.String(1000)) """ Takes in a string input and return it as a dictionary. Used to add to a databse
from semantics3 import Products sem3 = Products( api_key = "SEM3188CBEA0C536322303E7C24718D47A3B", api_secret = "ZDI1NWU4NTQ3M2M4MjJiZDdlMWNlNDBmMTM0MTQ4OGU" ) userInputProduct = input("What product would you like to know about: ") sem3.products_field("search", userInputProduct) results = sem3.get_products() print(results)
from flask import Flask, render_template, request, session, url_for, redirect import json import datetime from copy import deepcopy from sqlite3 import connect from hashlib import sha1 from semantics3 import Products sem3 = Products(api_key="SEM3C4DC74D42480F5F4C1CD26C2108854E6", api_secret="YmVkZGQ1YWY1NTQxOThlZTE5Y2FlMDU1Nzc2MTlmMDQ") f = "data/database.db" def get_median(l): l = sorted(l) if len(l) % 2 == 1: return l[len(l) // 2] return (l[len(l) // 2] + l[len(l) // 2 - 1]) / 2 def insert_interval(l, interval): for i in range(len(l)): if interval[1] <= l[i][1]: l.insert(i, interval) return l l.append(interval) return l def to_datetime(d): return datetime.datetime.fromtimestamp(
import eventlet sys.modules['httplib2'] = eventlet.import_patched('httplib2') print "[Optional Import] Using eventlet" except Exception: print "[Optional Import] Not using eventlet" from semantics3 import Semantics3Request from semantics3 import Products from semantics3 import Categories from semantics3 import Offers import pprint api_key = "" api_secret = "" pp = pprint.PrettyPrinter() products = Products(api_key, api_secret) products.products_field("cat_id", 4992) products.products_field("brand", "Toshiba") products.products_field("weight", "gte", 1000000) products.products_field("weight", "lt", 1500000) products.products_field("sitedetails", "name", "newegg.com") products.products_field("sitedetails", "latestoffers", "currency", "USD") products.products_field("sitedetails", "latestoffers", "price", "gte", 100) products.cache(5) for i in products.iter(): pass # Build the query products.categories_field("cat_id", 4992)