-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
octopart integration #314
Comments
Python 3 uses 2 different modules for urllib parse and request:
Hope that helps. |
Thanks for the tip, @romain145 . I ended up replacing the urllib stuff with the requests library. Python 2/3 compatibility has been restored. I also removed the parallel scan of the distributor websites. It doesn't appear to have affected the operation of kicost. Timing on a small number of examples shows a speedup of around 50x over the web-scraping version. |
I confirm. One of my projects with 50+ references takes 3.8s! that is a massive improvement.
Attached XML BOM. Is the API key supposed to be the same for all KiCost users? |
Regarding the API key: it's unique to an application. So I have registered KiCost with Octopart and that's the assigned key. Individual users do not need their own key. (This is something I did not realize before.) |
For some reason, the distributors parts number have a prefix, such as "2401_855-", or "2401_81-" that is probably appended by Octopart (The links are trackers that point to Octopart as well). Not sure what the prefix means though... |
I just looked at my spreadsheets and they also have the prepended number. It looks like it's a unique code for each distributor. It may be safe to strip off the initial digits and the underscore to get the actual part number. |
|
@anderwm I've had the same error recently, see #313 (comment)
|
|
Thanks, @anderwm. Using the sku field solves the problem with ordering from the distributors. Thanks also for pointing out that the Octopart response includes multiple offers. By collecting the price breaks for all the offers from Digi-Key, I was able to build a complete price table. |
No problem. Still need some way to pick which package type to use as the sku though(as Cat# in datasheet). If not you wind up with a bunch of reels in your cart that you have to change over. We could use the amount being purchased, or default to cut tape, or pass in something from the command line I guess. |
I'll try using the SKU from the offer with the smallest quantities in the list. If you order enough parts to consume a reel, I think they might automatically apply reel pricing. |
In Digikey, at least, you are advised to that (and order the next price break) when checkout the cart. |
Let's try it that way, then. |
So possibly it is a Me problem then. But most of the Digikey part numbers are coming up as reel for me in the Cat#. For instance, CL21C090CBANNNC shows in the spreadshed as Digikey Cat# 1276-2558-2-ND and the -2 means reel. Edit: I read your earlier comment as that is what you were doing currently. If what I am describing is not implemented yet disregard this comment. |
Right, I haven't fixed the SKU problem. |
sorry...got it |
KiCost now selects the SKU, available quantity, and web page from the cut-tape version. I'm distinguishing the cut-tape part by looking for the offer with the smallest quantity difference between the first two entries in its pricing table. This seems to work after my extensive testing on a single example. Each part offer also has a "packaging" field that could be used if that gives more accurate results. |
This worked quite well for me and the couple of BOMs I tested, and is crazy fast. Does this version make it trivial to add distributors to show in the spreadsheet? As in, if I want to add Arrow is it just a matter of adding it to the distributor_dict somewhere? |
We could set some road map:
I like the folder structure Or even the could be used Some opinions about? |
Sounds good...I stole the Newark code and added Arrow just to see if it really was that easy. It seems to be: |
@anderwm, are your |
just to update the distributor_dict...it is all just the Newark code with find/replace on newark->arrow |
I'll try to move the octopart code to distributors/octopart.py tonight. Do we just want to add Arrow to the list of distributors? Anyone else? I don't have any experience with the currency conversion code, so I'll leave that to someone else. I don't know about using the web scraping stuff in case the Octopart (or other) APIs fail. The web scraping routines go bad over time as the distributors change the structure of their web pages. If the APIs ever fail, then the web scrapers will have probably aged to the point where they'll fail as soon as we try them. It seems like a waste of effort to keep the web scrapers up-to-date and to also build the fail-over code. In the event the APIs ever fail (or their access is restricted), I would rather just go back and re-enable the web scrapers and make whatever changes are necessary at that time. (In addition, I think we've all agreed that we're never going to get the Mouser web scraper working again.) As for making interfaces to individual distributor APIs like Digi-Key, I don't see the point unless somebody really wants to do that. It's just more code and messing with API keys without giving us any new features or better part data than Octopart already provides (I think). |
@hildogjr I would create a new distributor module for the octopart API stuff in distributors/octopart.py. |
I pushed a new version to the octopart branch. The new code is encapsulated in the octopart.py file in the distributors directory. I also added Arrow as a distributor and stripped as much from the code as possible while still allowing it to run. Turns out we need almost nothing in those distributor files. I didn't remove any code from the original set of distributors. Eventually, it might be best to create a PartsList object that handles part grouping and information procurement. Then the query_octopart function could be rolled into that as a method. |
Agreed @mmmaisel. |
Some propose for new organization of the dict() struct, the old one:
Could have the initialization at
In my experience with the total code of KiCost, this will provide a better integration and separation between the informations. |
@mmmaisel, do you think is necessary / good to keep the @xesscorp, could we release this this new KiCost before the next steps? |
@hildogjr I think If you remove fake_browser, I think all functions except |
More fix and clean up did.
|
I think this is full functional. Do you all agree? (ready to release with some more documentation check?) I am moving forward and create
|
I assume the octopart branch is ready to release. The only real change to the documentation that I can think of would be to remove these options that no longer apply: -s Then move the current master branch to something like "web_scraping" and make the octopart branch into the master. Then release it on PyPi. |
@xesscorp, I already removed this from documentation, but could you do the double check? Something more: since march/2018 PyPI changed the documentation file style interpreter. I had to reconfigure the style to *.MD instead *.RST (our RST doesn't pass on the compliance), what created a bad look in the page https://pypi.org/project/kicost/ |
I looked at the documentation. Seems OK except the "-np" option is still listed in the "Command-Line Options" section. Also, the "Parallel Web Scraping" section needs to be removed. In regards to the README.RST and HISTORY.RST files, you can easily convert those into markdown files using pandoc: pandoc readme.rst -o readme.md The problem is you still need to keep the RST files because the documentation uses those to generate the manual in the docs directory using Sphinx unless you translate the doc files into markdown as well. |
Did the remove in the docs. Also change some 'scrape' words to 'scrape/query'. Could we use |
I added readme.md and history.md to the repository. The readme.rst and history.rst files are still there. You'll need to regenerate the markdown versions whenever you modify the RST files. |
Released as 1.0.0 |
Re-opened because KiCost need to deal and warning with "HTTP Status Codes" of https://octopart.com/api/docs/v3/overview |
#331 fix will have to contemplate this enhancement. |
I've created a new branch called "octopart". It gets part information using only the Octopart API (no web scraping). It works for the half-dozen XML input files I've tried it on. It currently has these problems:
All the changes I made are in the kicost.py file. This may not be the best place for it, but it makes the changes obvious.
I also noticed that there is a large delay (several seconds) in kicost before the part data is fetched from Octopart (which takes less than a second). This is caused by another parallel scrape that seems to be checking for the distributor websites? If so, I guess we could remove that since Octopart is being used. (I can't say for sure: this is new code I've never seen before.)
The text was updated successfully, but these errors were encountered: