Giter VIP home page Giter VIP logo

grocy-pyscanner's Introduction

Grocy Py Scanner

This awesome script will allow you the user to add/remove items from the system with just a barcode scanner

The script requires that you edit a few of the variables at the top of the description

UPC_DATABASE_API='UPC_API'

buycott_token='BUYCOTT_API'

GROCY_API='GROCY_API'

This is some arbitrary number. We used a barcode generator and put in some random 7 digit number to use as our ADDID. You could use a barcode off of something that you will never inventory

add_id='ADDID'

This is the URL of your grocy app or IP address.

base_url = 'YOUR_GROCY_URL'

This is where you want the product to go. I created an entry ADDED_UPDATE_LOCATION so that it stands out when going through the prduct list so I know it needs to be addressed.

This could be enhanced with barcodes that represent each location you have, then have the main function do some stuff but eh not worth it for me at this time.

This can be found by clicking on the location in the app and looking at the URL of course if you're curl savvy you could always query the api directly.

location_id = LOCATION_ID

Optional

homeassistant_url='YOUR_HOME_ASSISTANT_URL/DOMAIN/SERVICE'

homeassistant_api='YOUR_HOME_ASSISTANT_API'

I wrote this because I knew there was no way I would be able to get the house on board with using this if they needed to run around with a computer with the scanner attached to it.

So instead I plugged the dongle for my scanner into a raspberry pi that runs my sprinklers and I just run the app from there. Right now I run it in a screen session so that I can see the output.

I'm working on coming up with some sort of a solution to let the user know if the scan worked. Right now best idea I have come up with is to make another API call to my HomeAssistant and then have HomeAssistant do something that informs the user that it worked.

How To Use This

Put this script on whatever machine you want. Your local laptop, raspberry pi it doesn't matter just as long as wherever you put it, is the same place as your barcode scanner. In my case its on my raspberry pi that is running OpenSprinkler because 9 months out of the year that pi is just sitting idle. It doesn't matter where you run this script from though as long as it can make the necessary API calls that it needs to do. If you want to run it on the same machine that you have grocy thats cool too. In my case Grocy is on my docker VM so that was not an option for me hence why I put it on the pi. YMMV. If you have any questions please let me know.

Once you have the script installed just execute it with ./barcode_reader.py I don't have it setup to do logging so it will just print everything to the screen which is handy so you can see what its doing. I'll probably implement logging down the road though. If you don't want to see what its doing just add a & to the end of the command like ./barcode_reader.py &

Update:

04/29/2019: I got the home assistant integration working. For me I have this going to an Echo that is in my kitchen and I have it speak what mode it is in and if I added something it tells me how many it added it by. If this is the first time addding it will say zero because the quantity hasn't been setup properly in the database yet. Once you update the system to the correct quantity for the item then it will work just fine.

The Text To Speech is a little delayed because well it has to make the call to HomeAssistant which in turn has to make the call to convert the Text To Speech to whatever you have playing it.

I am fully open to pull requests as I am certain there are enhancements that someone who is a little more python savvy than myself could come up with or perhaps optimize the code a little more

Right now when its adding you need to let it chunk through that bit before scanning. Once everything is added to the system and its just doing increase/decrease operations you can scan pretty fast because its all local calls.

I have buycott in there because they allow you to have 7 days free before they bill you for the service. I'll probably be changing the order of the services but haven't decided yet.

12/11/2019: Did a lot of code optimization in here to try and clean things up. Also had to put in some error handling for Wal-Mart because they're returning what python says is invalid json so instead of the script puking and dying it now handles the error and keeps moving along.

Enjoy!

grocy-pyscanner's People

Contributors

berrnd avatar thefuzz4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grocy-pyscanner's Issues

Additional Documentation

Can you please provide some additional documentation on where to put this script? I have read through the script and have a decent idea of how it works but I am not sure where to put it so that I can use it.

Cannot run script

Hello,

I am getting an error.

087692009900
Looking up the product_id
404
Traceback (most recent call last):
File "./barcode_reader.py", line 309, in
decrease_inventory(upc)
File "./barcode_reader.py", line 69, in decrease_inventory
product_id_lookup(upc)
File "./barcode_reader.py", line 114, in product_id_lookup
j = r.json()
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python2.7/json/init.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 367, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 4 - line 1 column 15 (char 3 - 14)
Exception TypeError: TypeError('super() takes at least 1 argument (0 given)',) i n <bound method InputDevice.del of InputDevice('/dev/input/event0')> ignored

I am running it on a raspberrypi 4.

Also, what value am I supposed to enter by "UPC_DATABASE_API=?

Thank you

Usage without homeassistant

Hy,
are there any advices for users who dont use homeassistant?
I set up all variables except homeassistant token and get the following output:

400
Traceback (most recent call last):
  File "barcode_reader.py", line 309, in <module>
    decrease_inventory(upc)
  File "barcode_reader.py", line 69, in decrease_inventory
    product_id_lookup(upc)
  File "barcode_reader.py", line 110, in product_id_lookup
    if homeassistant_token != '':
NameError: global name 'homeassistant_token' is not defined

And Yes, i am absolutely new to this. :-)

Accept textfile containing scanned barcodes

At my last job, I would create a text file as I scanned barcodes for retail stuff.
I made this little python script that can take an inventory CSV, and then depending on the workflow, either increment the stock of an item for each time its barcode was scanned, or assume that we have scanned all instances of that product on hand, and set the value for the sum of the occurrences of a given barcode in the textfile.

Here's what that looks like, for me:
https://github.com/jamesbiederbeck/invmgr/blob/master/receivinghelper.py

Here's somepseudocode:
create empty dict "itemcounts"
open scan file
for each row in scan file, if the barcode is not in itemcounts' keys:
itemcounts[barcode] = 1
if barcode is in itemcounts' keys:
itemcounts[barcode] +=1

Then you have a list of quantities and barcodes!
From here it should be easy to add, or update quantities as appropriate

This would go great with one particular barcode scanner on amazon, which could remember all scanned barcodes, then when you scanned a control code, it would write the full list as HID output through a dongle. This made it easy to go back to my desk, after walking around the store with the scanner. So I just opened up a text document, dumped the scanned barcodes, ran my above script, and I had a small inventory file I could merge back into the POS.

This seems like an easy enough process to generalize, and apply here.

something is not working ..

unknown key, scancode=42
unknown key, scancode=45
unknown key, scancode=42
unknown key, scancode=18
unknown key, scancode=42
unknown key, scancode=23
unknown key, scancode=42
unknown key, scancode=23
unknown key, scancode=42
unknown key, scancode=32
XX002XX3XXXX8XX
Looking up the product_id
405
Traceback (most recent call last):
File "barcode_reader.py", line 309, in
decrease_inventory(upc)
File "barcode_reader.py", line 69, in decrease_inventory
product_id_lookup(upc)
File "barcode_reader.py", line 116, in product_id_lookup
product_id = j['product']['id']
KeyError: 'product'
Exception TypeError: TypeError('super() takes at least 1 argument (0 given)',) in <bound method InputDevice.del of InputDevice('/dev/input/event0')> ignored

the product code i'm trying to scan is YHDAA-tech

I pre-added it to my grocy inventory list with a few quantity in there

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.