<commit_before>
from __future__ import unicode_literals
from __future__ import print_function


import sys
sys.path.insert(0, "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.4-py2.7.egg")

sys.path.insert(0, "/usr/local/lib/python2.7/dist-packages/lxml-3.6.4-py2.7-linux-i686.egg")


import datetime
from types import MethodType
import string

import frappe
from frappe import msgprint,_
from frappe.utils import cstr

#from ebay_requests import get_orders
from ebaysdk.exception import ConnectionError
#from ebaysdk.finding import Connection as Finding
from ebaysdk.trading import Connection as Trading

import MySQLdb

#import os




@frappe.whitelist()
def show_list():
	
	create_ebay_table()
	
	page = 1
	listings_dict = find_listings(page)
	pages = int(listings_dict['PaginationResult']['TotalNumberOfPages'])
	totalEntries = int(listings_dict['PaginationResult']['TotalNumberOfEntries'])
	i = 0

	while pages >= page:

		for item in listings_dict['ItemArray']['Item']:
			ebay_id = item['ItemID']
			qty = item['Quantity']
			try:
				sku = item['SKU']
			except:
				sku = ''
			price = item['BuyItNowPrice']
			description = item['Description']
			#hit_count = item['HitCount']
			site = item['Site']
			title = item['Title']
			#conv_title = title.encode('ascii', 'ignore').decode('ascii')
			#insert_ebay_table(ebay_id, qty, price, MySQLdb.escape_string(conv_title))

			i += 1

		page += 1
		listings_dict = find_listings(page)

	#print(totalEntries, i, duplicate_count)



	
def find_listings(page):
	
	# python -c "import certifi; print certifi.old_where()"
	#os.environ['REQUESTS_CA_BUNDLE'] = '/usr/local/lib/python2.7/dist-packages/certifi/cacert.pem'	
	
	try:
		api_trading = Trading(config_file='/home/frappe/ebay.yaml', warnings=True, timeout=20)
		
		api_request = {
			'EndTimeFrom': "2018-01-30T00:00:00",
			'EndTimeTo': "2018-05-01T00:00:00",
			"Pagination": {
				"EntriesPerPage": 100,
				"PageNumber": page
			},
		'DetailLevel': 'ReturnAll'
		}

		api_trading.execute('GetSellerList', api_request)
		#products = products.dict()
		products = api_trading.response.dict()
	

	except ConnectionError as e:
		print(e)
		print(e.response.dict())
		raise e
		
	return products





def create_ebay_table():
	
	sql = """
		create table if not exists `zEbayListings` (
		`sku` varchar(20),
		`ebay_id` integer,
		`qty` integer,
		`price` float
		)
	"""

	frappe.db.sql(sql, auto_commit = True)
	
	sql = """truncate table `zEbayListings` """
	
	frappe.db.sql(sql, auto_commit = True)
	

def insert_ebay_table(sku, ebay_id, qty, price):
	
	sql = """
	insert into `zEbayListings`
	values('{sku}', {ebay_id}, {qty}, {price})
	""".format(sku=sku, ebay_id=ebay_id, qty=qty, price=price)
	
	
	frappe.db.sql(sql, auto_commit = True)
	
	


<commit_msg>Active Listings fix<commit_after>
from __future__ import unicode_literals
from __future__ import print_function


import sys
sys.path.insert(0, "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.4-py2.7.egg")

sys.path.insert(0, "/usr/local/lib/python2.7/dist-packages/lxml-3.6.4-py2.7-linux-i686.egg")


import datetime
from types import MethodType
import string

import frappe
from frappe import msgprint,_
from frappe.utils import cstr

#from ebay_requests import get_orders
from ebaysdk.exception import ConnectionError
#from ebaysdk.finding import Connection as Finding
from ebaysdk.trading import Connection as Trading

import MySQLdb

#import os




@frappe.whitelist()
def show_list():
	
	create_ebay_listings_table()
	
	page = 1
	listings_dict = find_listings(page)
	pages = int(listings_dict['PaginationResult']['TotalNumberOfPages'])
	#totalEntries = int(listings_dict['PaginationResult']['TotalNumberOfEntries'])
	#i = 0

	frappe.msgprint(pages)

	while pages >= page:

		for item in listings_dict['ItemArray']['Item']:
			ebay_id = item['ItemID']
			qty = item['Quantity']
			try:
				sku = item['SKU']
			except:
				sku = ''
			price = item['BuyItNowPrice']
			description = item['Description']
			#hit_count = item['HitCount']
			site = item['Site']
			title = item['Title']
			#conv_title = title.encode('ascii', 'ignore').decode('ascii')  then  MySQLdb.escape_string(conv_title)
			insert_ebay_listing(sku, ebay_id, qty, price)

			#i += 1

		page += 1
		listings_dict = find_listings(page)

	#print(totalEntries, i, duplicate_count)



	
def find_listings(page):
	
	# python -c "import certifi; print certifi.old_where()"
	#os.environ['REQUESTS_CA_BUNDLE'] = '/usr/local/lib/python2.7/dist-packages/certifi/cacert.pem'	
	
	try:
		api_trading = Trading(config_file='/home/frappe/ebay.yaml', warnings=True, timeout=20)
		
		api_request = {
			'EndTimeFrom': "2018-01-30T00:00:00",
			'EndTimeTo': "2018-05-01T00:00:00",
			"Pagination": {
				"EntriesPerPage": 100,
				"PageNumber": page
			},
		'DetailLevel': 'ReturnAll'
		}
		
		
		# activelist = api.execute('GetMyeBaySelling', {'ActiveList': True,'DetailLevel': 'ReturnAll','PageNumber': page})


		api_trading.execute('GetSellerList', api_request)
		#products = products.dict()
		products = api_trading.response.dict()
	

	except ConnectionError as e:
		print(e)
		print(e.response.dict())
		raise e
		
	return products





def create_ebay_listings_table():
	
	sql = """
		create table if not exists `zEbayListings` (
		`sku` varchar(20),
		`ebay_id` integer,
		`qty` integer,
		`price` float
		)
	"""

	frappe.db.sql(sql, auto_commit = True)
	
	sql = """truncate table `zEbayListings` """
	
	frappe.db.sql(sql, auto_commit = True)
	

def insert_ebay_listing(sku, ebay_id, qty, price):
	
	sql = """
	insert into `zEbayListings`
	values('{sku}', {ebay_id}, {qty}, {price})
	""".format(sku=sku, ebay_id=ebay_id, qty=qty, price=price)
	
	
	frappe.db.sql(sql, auto_commit = True)
	
	



{'fraction_non_alphanumeric': 0.1411107230178135, 'fraction_numerical': 0.020957038071952497, 'mean_word_length': 4.407932011331445, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '507248', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2109, 'n_words': 417}