def main(): def progressHandler(prestaProgressEvent): if prestaProgressEvent.is_finished: print('%s' % prestaProgressEvent.msg) else: print('%i/%i - %s' % (prestaProgressEvent.current_step, prestaProgressEvent.max_step, prestaProgressEvent.msg)) # A CachedPrestaHelper is a PrestaHelper with cache capabilities cachedphelper = CachedPrestaHelper(config.presta_api_url, config.presta_api_key, debug=False, progressCallback=progressHandler) # Force loading cache # cachedphelper.load_from_webshop() #tester = CachedPrestaHelperTest( cachedphelper ) #tester.test_cache() print('******************************************************************') print('* Cache statistics *') print('******************************************************************') print('Type of Helper is %s' % type(cachedphelper)) print('#Carriers = %s' % len(cachedphelper.carriers)) print('#OrderStates = %s' % len(cachedphelper.order_states)) print('#Products = %i' % len(cachedphelper.products)) print('#suppliers = %i' % len(cachedphelper.suppliers)) print('#categories = %i' % len(cachedphelper.categories)) print('#stock availables = %i' % len(cachedphelper.stock_availables)) #print('mise à jour des qty' ) #cachedphelper.stock_availables.update_quantities() #print( 'Voila, c est fait' ) print('******************************************************************') print('* Derniers Messages client *') print('******************************************************************') """ affiche les x derniers messages clients """ id = cachedphelper.get_lastcustomermessage_id() print('last message id: %s' % id) custmsgs = cachedphelper.get_lastcustomermessages(id, 10) for custmsg in reversed(custmsgs): # CustomerMessageData print('--- id: %s---------------' % custmsg.id) print(' date_add: %s' % custmsg.date_add) print(' read : %s' % custmsg.read) print(' Employee: %s' % custmsg.id_employee) print(' id_customer_thread: %s' % custmsg.id_customer_thread) print(custmsg.message) print('') # Ensure cache file to be saved (and will be automatically reloaded) #cachedphelper.save_cache_file() # read char on keyboard print('Press a key to continue:') char = sys.stdin.read(1) return 0
def __init__( self ): self.config = Config() self.h = CachedPrestaHelper( self.config.presta_api_url, self.config.presta_api_key, debug= False ) self.output = PrestaOut() self.state = AppState.WAIT_ORDER # Loaded order self.order = None self.joined_order = [] # other order joined to the shipping self.customer = None self.carrier = '' self.shipping_number = '' self.output.writeln( "Application initialized" )
def __init__( self, screen ): self.screen = screen (self.height, self.width) = screen.getmaxyx() self.subwin = [] # Subwin list self.create_subwin() # Create a SysLog handler self.logger = logging.getLogger() self.logger.setLevel( logging.DEBUG ) # Follow the log with # tail -f /var/log/syslog # formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s') # also mention the python filename in the log formatter = logging.Formatter( os.path.basename(__file__)+' :: %(levelname)s :: %(message)s') sys_handler = SysLogHandler( address = '/dev/log') sys_handler.setLevel( LOGGING_LEVEL ) sys_handler.setFormatter( formatter ) self.logger.addHandler( sys_handler ) self.logger.info( 'Starting app' ) self.config = Config() self.cachedphelper = CachedPrestaHelper( self.config.presta_api_url, self.config.presta_api_key, debug = False ) #, progressCallback = progressHandler ) # initialize global variables self.initialize_globals()
def main(): def progressHandler(prestaProgressEvent): if prestaProgressEvent.is_finished: print('%s' % prestaProgressEvent.msg) else: print('%i/%i - %s' % (prestaProgressEvent.current_step, prestaProgressEvent.max_step, prestaProgressEvent.msg)) def initialize_globals(): """ Initialize the global var @ startup or @ reload """ global ID_SUPPLIER_PARAMS _item = cachedphelper.suppliers.supplier_from_name("PARAMS") #for _item in cachedphelper.suppliers: # print( '%i - %s' % (_item.id,_item.name) ) if _item != None: ID_SUPPLIER_PARAMS = _item.id print('Catched PARAMS supplier :-). ID: %i' % ID_SUPPLIER_PARAMS) # A CachedPrestaHelper is a PrestaHelper with cache capabilities cachedphelper = CachedPrestaHelper(config.presta_api_url, config.presta_api_key, debug=False, progressCallback=progressHandler) # Force loading cache # cachedphelper.load_from_webshop() #tester = CachedPrestaHelperTest( cachedphelper ) #tester.test_cache() print('******************************************************************') print('* Cache statistics *') print('******************************************************************') print('Type of Helper is %s' % type(cachedphelper)) print('#Carriers = %s' % len(cachedphelper.carriers)) print('#OrderStates = %s' % len(cachedphelper.order_states)) print('#Products = %i' % len(cachedphelper.products)) print('#suppliers = %i' % len(cachedphelper.suppliers)) print('#categories = %i' % len(cachedphelper.categories)) print('#stock availables = %i' % len(cachedphelper.stock_availables)) print('#product suppliers available = %i' % len(cachedphelper.product_suppliers)) print('******************************************************************') print('') initialize_globals() #print('mise à jour des qty' ) #cachedphelper.stock_availables.update_quantities() #print( 'Voila, c est fait' ) value = '' while value != '+q': try: value = raw_input('What to do: ') # -- COMMANDS ------------------------------------------ # +q, +s, +r g = re_command.match(value) if g: cmd = g.groups()[0] if cmd == 'q': return if cmd == 's': print('Saving cache...') cachedphelper.save_cache_file() if cmd == 'r': print('Contacting WebShop and reloading...') cachedphelper.load_from_webshop() initialize_globals() # reinit global variables if cmd == 'e': # export the inventory list lst = build_inventory_list(cachedphelper) sorted_lst = sorted(lst, key=lambda cargo: cargo.reference) root = export_to_xmltree(sorted_lst) tree = etree.ElementTree(root) root = Tk() root.filename = tkFileDialog.asksaveasfilename( title="Exporter vers fichier XML", filetypes=(("xml", "*.xml"), ("all files", "*.*"))) if (root.filename == u''): print('User abort!') root.destroy() continue tree.write(root.filename) root.destroy() print('exported to %s' % root.filename) if cmd == 'h': help() # restart loop continue # -- SEARCH ------------------------------------------- # GSM, /-LIPO, #g = re_search_text.match( value ) #if g: # # Text to search = groups()[0] if "demo" or groups()[1] if "/-lipo" # txt = g.groups()[0] if g.groups()[0] else g.groups()[1] # list_products( cachedphelper, key = txt ) # continue except Exception as err: print('[ERROR] %s' % err) traceback.print_exc() # eof While return
def main(): cachedHelper = CachedPrestaHelper(config.presta_api_url, config.presta_api_key, debug=False) lcd = EuropeLcdMatrix(config.lcd_device) lcd.create_european_charset() lcd.clear_screen() lcd.autoscroll(False) lcd.activate_lcd(True) lcd.write_european_pos(1, 1, u'LcdOrderTrack') lcd.write_european_pos(2, 1, u' starting...') # default values for variable last_order_id = -1 last_order_data = None bNewPayment = False paid_count = 0 bankwire_count = 0 # Locate the ID_Payment for "Paiement par carte sur place" PAY_AT_MCH = None for order_state in cachedHelper.order_states: if cachedHelper.order_states.name_from_id( order_state.id).upper().find(u'CARTE SUR PLACE') >= 0: PAY_AT_MCH = order_state.id try: # Force initial update last_update_time = time.time() - UPDATE_DELAY while True: if math.floor(time.time() - last_update_time) >= UPDATE_DELAY: lcd.clear_screen() lcd.write_european(u'Updating...') # Identifying the last Order! last_order_id = cachedHelper.get_lastorder_id() last_orders_data = cachedHelper.get_last_orders(last_order_id, count=1) # bOpenOrder = cachedHelper.order_states.is_open_order( last_orders_data[0].current_state ) # Exclude the REAPPROVISIONNEMENT state from light # the LCD. Payment is effectively DONE but # no work/shipping has to be prepared # New order with "Payment sur place" will deliver money shortly # so it is also like a "new payment" --> switch on the light bNewPayment = (cachedHelper.order_states.is_new_order( last_orders_data[0].current_state) or (cachedHelper.order_states.name_from_id( last_orders_data[0].current_state).upper(). find(u'CARTE SUR PLACE') >= 0)) and ( last_orders_data[0].current_state != OrderStateList.ORDER_STATE_REPLENISH) # Activate LCD when receiving a new payment setLcdColor(lcd, cachedHelper, last_orders_data[0]) lcd.activate_lcd(bNewPayment) paid_count = len( cachedHelper.get_order_ids( cachedHelper.order_states.ORDER_STATE_PAID)) bankwire_count = len( cachedHelper.get_order_ids( cachedHelper.order_states.ORDER_STATE_WAIT_BANKWIRE)) # Also add the "Paiement par carte sur place" in Bankwire count if PAY_AT_MCH: bankwire_count += len( cachedHelper.get_order_ids(PAY_AT_MCH)) last_update_time = time.time() else: sInfo = u'upd in %i sec' % int( UPDATE_DELAY - math.floor(time.time() - last_update_time)) sInfo = (sInfo[:16]).ljust(16) lcd.write_european_pos(2, 1, sInfo) time.sleep(2) # Show Count of payments sPayInfo = u'Pay %s | Vir %s' % (paid_count, bankwire_count) sPayInfo = sPayInfo.center(16) lcd.write_european_pos(1, 1, sPayInfo) # Show information about last Order showOrderInfo(lcd, cachedHelper, last_orders_data[0]) except Exception, e: lcd.clear_screen() lcd.write_european_pos('KABOUM!!') lcd.write_european_pos(2, 1, u'Restart in 5 Min') logging.exception(e) time.sleep(5 * 60) os.system('sudo reboot') return 0
from prestaapi import PrestaHelper, CachedPrestaHelper, OrderStateList from output import PrestaOut from config import Config from pprint import pprint import logging import sys, os, codecs import re, subprocess import signal import datetime # debugging from xml.etree import ElementTree # from enum import Enum config = Config() h = CachedPrestaHelper( config.presta_api_url, config.presta_api_key, debug= False ) #print ("#products = %i" % ( len( h.products ) ) ) class AppState( Enum ): WAIT_ORDER = 0 CONTROL_ORDER = 1 WAIT_SHIPPING = 2 CONTROLED = 3 APPEND_ORDER = 4 # Wait state to append an order class CMD( Enum ): RAW = 0 VERB = 1 # The text value is one of the Verbs dic SET_CARRIER = 2 # Setting the CARRIERS (one of CARRIERS dic), so setting the CARRIER LOAD_ORDER = 3 # Loading an ORDER SCAN_PRODUCT= 4 # Scanning a product
def main(): def progressHandler(prestaProgressEvent): if prestaProgressEvent.is_finished: print('%s' % prestaProgressEvent.msg) else: print('%i/%i - %s' % (prestaProgressEvent.current_step, prestaProgressEvent.max_step, prestaProgressEvent.msg)) def initialize_globals(): """ Initialize the global var @ startup or @ reload """ global ID_SUPPLIER_PARAMS _item = cachedphelper.suppliers.supplier_from_name("PARAMS") #for _item in cachedphelper.suppliers: # print( '%i - %s' % (_item.id,_item.name) ) if _item != None: ID_SUPPLIER_PARAMS = _item.id print('Catched PARAMS supplier :-). ID: %i' % ID_SUPPLIER_PARAMS) # A CachedPrestaHelper is a PrestaHelper with cache capabilities cachedphelper = CachedPrestaHelper(config.presta_api_url, config.presta_api_key, debug=False, progressCallback=progressHandler) # Force loading cache # cachedphelper.load_from_webshop() #tester = CachedPrestaHelperTest( cachedphelper ) #tester.test_cache() print('******************************************************************') print('* Cache statistics *') print('******************************************************************') print('Type of Helper is %s' % type(cachedphelper)) print('#Carriers = %s' % len(cachedphelper.carriers)) print('#OrderStates = %s' % len(cachedphelper.order_states)) print('#Products = %i' % len(cachedphelper.products)) print('#suppliers = %i' % len(cachedphelper.suppliers)) print('#categories = %i' % len(cachedphelper.categories)) print('#stock availables = %i' % len(cachedphelper.stock_availables)) print('#product suppliers available = %i' % len(cachedphelper.product_suppliers)) print('******************************************************************') print('') initialize_globals() #print('mise à jour des qty' ) #cachedphelper.stock_availables.update_quantities() #print( 'Voila, c est fait' ) value = '' while value != '+q': print('=' * 40) print(' +r : reload cache | +s : save cache') print(' +12: ean12 to ean13 | +e : create ean13') print(' id : id product to print | partial_code: to search') print(' +ol: On demand label (Large)| +al : address label') print( ' +os: On demand label (Short)| +openl : open for... label') print(' +ok: On demand label (King) | +w : Warranty') print(' +q : quit ') print('=' * 40) print('') value = raw_input('What to do: ') if value == '+q': pass elif value == '+r': print('Contacting WebShop and reloading...') cachedphelper.load_from_webshop() initialize_globals() # reinit global variables elif value == '+s': print('Saving cache...') cachedphelper.save_cache_file() elif value == '+12': ean12_to_ean13() elif value == '+e': product_id_to_ean13() elif value == '+ol': #On_demand Large label ondemand_label_large() elif value == '+os': #On_demand Short label ondemand_label_short() elif value == '+ok': #On_demand King Size Label line1 = raw_input('Line 1: ') if line1 == '+q' or line1 == '': continue line2 = raw_input('Line 2: ') print_ondemand_label_kingsize(line1, line2) elif value == '+al': # adress Label value = raw_input('How many labels or +q: ') if value == '+q' or value == '0': continue if value == '': value = '1' qty = int(value) if qty > 25: qty = 25 print('Max 25 labels allowed! Value sharped to 25.') print_ondemand_label_large('MC Hobby SPRL', [ unicode(config.company_address[0]), unicode(config.company_address[1]), unicode(config.company_address[2]), unicode(u'TVA/VAT: %s' % config.company_vat), unicode(u'Phone : %s' % config.company_phone), unicode(u'Web : %s' % config.company_url) ], qty) elif value == '+openl': value = raw_input('How many labels or +q: ') if value == '+q' or value == '0': continue if value == '': value = '1' qty = int(value) if qty > 25: qty = 25 print('Max 25 labels allowed! Value sharped to 25.') print_ondemand_label_large('Votre produit ouvert pour:', [ u'[ ] ajout de matériel', u'[ ] contrôle qualité', u'', u'', u'MC Hobby SPRL' ], qty) elif value == '+w': prefix_str = raw_input('Préfix ou +q (ex:ELI-MEGA) : ') if value == '+q': continue counter_start = raw_input( 'N° première étiquette ou +q (ex:150021): ') if counter_start == '+q': continue counter_start = int(counter_start) how_many_label = raw_input( "Combien d'étiquette ou +q : ") if how_many_label == '+q': continue how_many_label = int(how_many_label) print_warranty_label_large(prefix_text=prefix_str, counter_start=counter_start, label_count=how_many_label) elif value.isdigit(): print_for_product(cachedphelper, int(value)) else: print('Looking for product %s...' % value) list_products(cachedphelper, value) return
def main2(): def progressHandler( prestaProgressEvent ): if prestaProgressEvent.is_finished: print( '%s' %prestaProgressEvent.msg ) else: print( '%i/%i - %s' % ( prestaProgressEvent.current_step, prestaProgressEvent.max_step, prestaProgressEvent.msg ) ) # A CachedPrestaHelper is a PrestaHelper with cache capabilities cachedphelper = CachedPrestaHelper( config.presta_api_url, config.presta_api_key, debug = False, progressCallback = progressHandler ) # Force loading cache # cachedphelper.load_from_webshop() #tester = CachedPrestaHelperTest( cachedphelper ) #tester.test_cache() print( '******************************************************************' ) print( '* Cache statistics *' ) print( '******************************************************************' ) print( 'Type of Helper is %s' % type(cachedphelper) ) print( '#Carriers = %s' % len(cachedphelper.carriers) ) print( '#OrderStates = %s' % len( cachedphelper.order_states ) ) print( '#Products = %i' % len( cachedphelper.products ) ) print( '#suppliers = %i' % len( cachedphelper.suppliers ) ) print( '#categories = %i' % len( cachedphelper.categories ) ) print( '#stock availables = %i' % len( cachedphelper.stock_availables ) ) print( '#product suppliers available = %i' % len( cachedphelper.product_suppliers ) ) print( '******************************************************************' ) print( '' ) initialize_globals() #print('mise à jour des qty' ) #cachedphelper.stock_availables.update_quantities() #print( 'Voila, c est fait' ) value = '' while value != '+q': print( '='*40 ) print( ' +r : reload cache | +s : save cache' ) print( ' +q : quit ' ) print( '='*40 ) print( '' ) value = raw_input( 'What to do: ' ) if value == '+q': pass elif value == '+r': print( 'Contacting WebShop and reloading...' ) cachedphelper.load_from_webshop() initialize_globals() # reinit global variables elif value == '+s': print( 'Saving cache...' ) cachedphelper.save_cache_file() elif value.isdigit(): if len(value)<=5: # we are looking for a product ID list_products( cachedphelper, id=int(value) ) else: list_products( cachedphelper, ean=value ) else: print( 'Looking for product %s...' % value ) list_products( cachedphelper, key=value ) return