Exemple #1
0
            "SELECT events.id AS event_id FROM setup.events \
                        JOIN setup.tablet_report_controls ON events.venue_uid = tablet_report_controls.venue_uid \
                        WHERE events.venue_uid = %s \
                        AND event_date BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL seconds_before_event SECOND) \
                        AND tablet_alert_sent = 0 \
                        ORDER BY event_date  ASC", (str(venueUid)))

        #for each of these events send a tablet status alert email
        for eventRow in cursor.fetchall():
            eventUid = eventRow[0]
            if TabletStatusMailer.sendStatusEmail(venueUid, eventUid) == True:
                #assuming everything went well with the email update the event row to mark the tablet status email sent
                cursor.execute(
                    "UPDATE setup.events SET tablet_alert_sent = 1 WHERE id = %s",
                    (eventUid))
                conn.commit()
except Exception, e:
    print "I caught the exception!!!"

    checkmateconfig = CheckMateConfig()
    auth_token = checkmateconfig.HIPCHAT_AUTH_TOKEN
    room_id = checkmateconfig.HIPCHAT_WORKERS_ROOM_ID
    '''
         hipchat_dict = {'auth_token':'987ce42cc059f3a404e18c9f9c9642',
                         'room_id':'518943',
                         'from':'TabletStatCron',
                         'message':'Something went wrong in TabletStatusCron: ' + str(e) + " - " + traceback.format_exc(),
                         'notify':'1',
                         'color':'red'}
        '''
from db_connection import DbConnection
import os.path
import hashlib

MENU_ITEM_IMAGE_PATH = "/data/media/202/images/menu_items/"

db = DbConnection().connection
menuItemCursor = db.cursor()

menuItemCursor.execute("SELECT * FROM menus.menu_items WHERE show_image =1");

menuItems = menuItemCursor.fetchall()

for menuItem in menuItems:
    image = MENU_ITEM_IMAGE_PATH + str(menuItem[0]) + ".png";
    if os.path.isfile(image):
        fileHash = hashlib.md5(open(image).read()).hexdigest()
        cursor = db.cursor()
        cursor.execute("INSERT INTO media.images(pointer_uid, image_type, image_hash, created_at)\
                        VALUES ({0}, 'menu_items', '{1}', NOW())".format(menuItem[0], fileHash))

        db.commit()
    else:
        print "Can't find it: " + image