def setItemConfig(model, item): #Get default config values first and then overwrite them with model specific values global APIcmds def f(cfgValues,item): tempDict = item cfgDict = {} for k,v in cfgValues.items(): if k == "ItemSpecifics": #Skip item specifics so it doesn't overwrite the generated ones continue cmd = "Item.{}".format(k) if cmd in APIcmds: cfgDict[k] = v if cfgOverride.has_key(k): cfgDict[k] = cfgOverride[k] mergeDictionary(tempDict["Item"],cfgDict) return tempDict defaultCfg = ebayTools.getConfig("default") modelCfg = ebayTools.getConfig(model) if defaultCfg is not None: item = f(defaultCfg,item) if modelCfg is not None: item = f(modelCfg,item) return item
def genInfo(fname): notes = ebayTools.getConfig(LogReader.getModel(fname),"SpecialNotes") info = LogReader.genInfo(fname).replace(",\n","<br>"); info += "<br>" if notes is not None: info += "<br>{}".format(notes) return info
def verifyPost(fname,postInfo,postTitle): model = LogReader.getModel(fname) pictures = getPictures(LogReader.getSerial(fname)) if len(pictures) <= 0: pictures = getPictures(LogReader.getModel(fname)) printLine() print("Picture #: {}".format(len(pictures))) print("TITLE:{}".format(postTitle)) print "Buy It Now Price: ${}".format(ebayTools.getConfig(model,"BuyItNowPrice")) print "Starting Price: ${}".format(ebayTools.getConfig(model,"StartPrice")) printLine() print("DESCRIPTION:\n{}".format(postInfo.replace("<br>","\n"))) while True: print("Is this ok? (y/n)") line = sys.stdin.readline().rstrip() if line.lower() == "y" or line.lower() == "yes": return elif line.lower() == "n" or line.lower() == "no": print("Skipping...") return -1 else: print("Invalid input")
def genItemSpecifics(fname): model = LogReader.getModel(fname) mConfig = ebayTools.getConfig(model,"ItemSpecifics") specList = [] specDict = {} if mConfig is not None: for k,v in mConfig.items(): addItemSpecific(k,v,specList) addItemSpecific("Memory (RAM) Capacity",LogReader.getTotalRam(fname)[0],specList) addItemSpecific("Model",model.split(" ")[-1],specList) addItemSpecific("Product Line",model.split(" ")[0],specList) addItemSpecific("MPN",model.split(" ")[-1],specList) addItemSpecific("CPU Cores",LogReader.getProcCores(fname),specList) addItemSpecific("Number of Processors",sum([v for k,v in LogReader.getProcInfo(fname).items()]),specList) addItemSpecific("Memory Type",LogReader.getTotalRam(fname)[1],specList) addItemSpecific("Processor Speed",LogReader.getProcSpeed(fname),specList) specDict["NameValueList"] = specList return specDict
def getPictures(name): realpath = os.path.dirname(os.path.realpath(sys.argv[0])) pictureCfg = ebayTools.getConfig("default","PictureInfo") picPath = pictureCfg["Path"]; fileTypes = pictureCfg["FileTypes"].split(",") pictureList = [] if picPath[:2] == "./": picPath = "{}{}/{}".format(realpath,pictureCfg["Path"][1:],name) else: picPath = "{}/{}".format(picPath,name) if os.path.isdir(picPath): files = os.listdir(picPath) for file in files: fname,ext = os.path.splitext(file) if ext.lower() in fileTypes: pictureList.append("{}/{}".format(picPath,file)) else: print("ERROR: picPath '%s' does not exist." % picPath) return pictureList
def postItem(fname): try: global cfgOverride model = LogReader.getModel(fname) postTitle = genTitle(fname) postInfo = genInfo(fname) if dynamicPrice: price = prices.getPrice(fname) if ebayTools.getConfig(model,"ListingType") == "FixedPriceItem": cfgOverride["StartPrice"] = int(price) else: cfgOverride["BuyItNowPrice"] = int(price) cfgOverride["StartPrice"] = int(price / 7) if VerifyFlag: if verifyPost(fname,postInfo,postTitle) is not None: return pictureURLs = uploadPicture(fname) template = file(os.path.join(dn,"template.html"),"r") htmlData = template.read().replace("{{ title }}", postTitle) htmlData += "<!---SERVICETAG={}-----!>".format(LogReader.getSerial(fname)) if pictureURLs is not None: pictureHTML = "" for url in pictureURLs: pictureHTML += '<img src="{}" style="display:none;">'.format(url) htmlData = htmlData.replace("{{ image src }}",'{}'.format(pictureHTML)) else: htmlData = htmlData.replace("{{ image src }}","") #htmlData = htmlData.replace("{{ image src }}","<img src='http://i.ebayimg.sandbox.ebay.com/00/s/OTAwWDE2MDA=/z/6FkAAOSwErpWHpfG/$_1.JPG?set_id=8800005007'>") htmlData = htmlData.replace("{{ description }}",postInfo) myitem = { "Item": { "Title": genTitle(fname), "Description": "<![CDATA["+htmlData+"]]>", "ItemSpecifics": genItemSpecifics(fname), } } global failFlag if failFlag: print("Something went wrong, skipping {}".format(fname)) failFlag = False return if pictureURLs is not None: myitem["Item"]["PictureDetails"] = {"PictureURL": [x for x in pictureURLs]} myitem = setItemConfig(model,myitem) d = api.execute('AddItem', myitem).dict() itemURL = getItemURL(d["ItemID"]) if LogURL: urlLog = file("urlLog.txt","w") #urlLog.write() urlLog.close() printLine() print(itemURL) printLine() except ConnectionError as e: print(e) print(e.response.dict())
def getAPICommandList(): commandListFile = file(ebayTools.getConfig("default","APICommandList"),"r") commandList = ast.literal_eval(commandListFile.read()) commandListFile.close() return commandList
printLine() print(itemURL) printLine() except ConnectionError as e: print(e) print(e.response.dict()) #endAllItems() AbsolutePath = False VerifyFlag = False init() dn = os.path.dirname(os.path.realpath(__file__)) api = Connection(domain=ebayTools.getConfig("default","Domain"),config_file=os.path.join(dn,"ebay.yaml")) #Ends all active items.. WARNING def m_endall(): endAllItems() #Dynamic pricing based off the prices in Prices.db def m_p(): global dynamicPrice dynamicPrice = True #Verifies listing before posting def m_v(): global VerifyFlag VerifyFlag = True #Changes the listing type def m_lt(listingType): global cfgOverride