Пример #1
0
 def get_text(self):
     global cursor
     if self.error == True:
         return ''
     date = self.get_datetime().date()
     cursor.execute("SELECT format_date(%s)", (date, ))
     return cursor.fetchone()[0]
Пример #2
0
def nicknames(uuid):
    cursor.execute("SELECT * FROM plan_nicknames WHERE uuid=%s", (uuid, ))
    data = cursor.fetchall()
    dData = {}
    lData = []
    for registro in data:
        dData = {"name": registro[2], "last_used": registro[4]}
        lData.append(dData)
    return lData
Пример #3
0
def pitch(sqlid):
    cursor.execute('''SELECT c.Name
                        FROM [LocknutData].[dbo].[Pitch2ThreadDiameter] a

                        INNER JOIN [LocknutData].[dbo].[Pitch] b
                        on b.PitchID = c.PitchID

                        WHERE a.ThreadDiameterID = '{}';'''.format(sqlid))
    return cursor.fetchall()
    cursor.close()
Пример #4
0
def unique(part):
    cursor.execute('''SELECT b.ThreadDiameterID
                        FROM [LocknutData].[dbo].[PartNumber] a

                        INNER JOIN [LocknutData].[dbo].[Pitch2ThreadDiameter] b
                        on b.Pitch2ThreadDiameterID = a.Pitch2ThreadDiameterID

                        WHERE a.Name = '{}';'''.format(part))
    return cursor.fetchone()[0]
    cursor.close()
Пример #5
0
def diameterid(sqlid):
    cursor.execute('''SELECT b.ThreadDiameterID
                        FROM [LocknutData].[dbo].[Pitch2ThreadDiameter] a

                        INNER JOIN [LocknutData].[dbo].[ThreadDiameter] b
                        on b.ThreadDiameterID = a.Pitch2ThreadDiameterID

                        WHERE a.PitchID = {:d};'''.format(sqlid))
    return cursor.fetchall()
    cursor.close()
Пример #6
0
def getid(pitch):
    sql = '''INSERT INTO LocknutData.dbo.Pitch ([Name])
                SELECT %s
                WHERE NOT EXISTS (SELECT 1
                                    FROM LocknutData.dbo.Pitch
                                    WHERE [Name] = '%s');''' % (pitch, pitch)
    cursor.execute(sql)
    cursor.execute('''SELECT PitchID 
                       FROM LocknutData.dbo.Pitch 
                       WHERE Name = '{}';'''.format(pitch))

    return cursor.fetchone()[0]
    cursor.close()
Пример #7
0
def name(part):
    # type: (object) -> object
    """

    :rtype: object
    """
    cursor.execute('''SELECT c.[Name]
                        FROM [LocknutData].[dbo].[PartNumber] a

                        INNER JOIN [LocknutData].[dbo].[Pitch2ThreadDiameter] b
                        on b.Pitch2ThreadDiameterID = a.Pitch2ThreadDiameterID

                        INNER JOIN [LocknutData].[dbo].[ThreadDiameter] c
                        on c.ThreadDiameterID = b.ThreadDiameterID

                        WHERE a.Name = '{}';'''.format(part))
    return cursor.fetchone()[0]
    cursor.close()
Пример #8
0
def addnew(standard_i_d, pitch2_thread_diameter_i_d, pitch_thread_diameter_designation_i_d):
    query = '''INSERT INTO [LocknutData].[dbo].[Standard2PitchThreadDiameter] 
                ([StandardID]
                ,[Pitch2ThreadDiameterID]
                ,[PitchThreadDiameterDesignationID])
                SELECT {:d}
                        ,{:d}
                        ,{:d}
                WHERE NOT EXISTS (SELECT 1 
                                    FROM [LocknutData].[dbo].[Standard2PitchThreadDiameter]  
                                    WHERE [StandardID] = {:d}
                                    AND [Pitch2ThreadDiameterID] = {:d}
                                    AND [PitchThreadDiameterDesignationID] = {:d});''' \
        .format(standard_i_d, pitch2_thread_diameter_i_d, pitch_thread_diameter_designation_i_d, standard_i_d,
                pitch2_thread_diameter_i_d, pitch_thread_diameter_designation_i_d)

    cursor.execute(query)
    cursor.commit()
Пример #9
0
 def day_selected(self, calendar, date_label, fiscal_label, override):
     global cursor
     date_time = self.get_datetime()
     cursor.execute(
         "SELECT id FROM fiscal_years "
         "WHERE active = True AND %s >= start_date "
         "AND %s <= end_date", (date_time, date_time))
     if cursor.fetchone() == None and override == False:
         fiscal_label.show()
         date_string = ''
         date_label.hide()
         self.error = True
         if self.timeout == None:
             self.timeout = GLib.timeout_add_seconds(2, self.force_show)
     else:
         date_string = datetime.strftime(date_time, "%m-%d-%Y")
         date_label.show()
         self.error = False
         if self.timeout != None:
             fiscal_label.hide()
             GLib.source_remove(self.timeout)
             self.timeout = None
     date_label.set_label(str(date_string))
     self.emit('day-selected')
Пример #10
0
def getid(designation):
    cursor.execute('''SELECT PitchThreadDiameterDesignationID 
           FROM LocknutData.dbo.PitchThreadDiameterDesignation
           WHERE Name = '{}';'''.format(designation))
    if cursor.rowcount == 0:
        cursor.execute(
            '''INSERT INTO LocknutData.dbo.PitchThreadDiameterDesignation
                           (Name)
                           VALUES ('{}');'''.format(designation))
        cursor.commit()
    cursor.execute('''SELECT PitchThreadDiameterDesignationID 
           FROM LocknutData.dbo.PitchThreadDiameterDesignation
           WHERE Name = '{}';'''.format(designation))
    return cursor.fetchone()[0]
    cursor.close()
Пример #11
0
def getid(dia):
    cursor.execute('''SELECT ThreadDiameterID 
           FROM LocknutData.dbo.ThreadDiameter 
           WHERE Name = '{}';'''.format(dia))
    if cursor.rowcount == 0:
        if dia[:1] == 'M':
            unit = 5
            eqv = float(dia[1:]) * 0.0393701
        else:
            unit = 4
            eqv = mixed_to_float(dia)

        cursor.execute('''INSERT INTO LocknutData.dbo.ThreadDiameter
                               (Name, MeasurementUnitID, InchMeasurementEquivalent)
                               VALUES ('{}', {}, {});'''.format(
            dia, unit, eqv))
    cursor.execute('''SELECT ThreadDiameterID 
                           FROM LocknutData.dbo.ThreadDiameter 
                           WHERE Name = '{}';'''.format(dia))
    return cursor.fetchone()[0]
    cursor.close()
Пример #12
0
def relateid(diametername, pitchname):
    """
    :type diametername: object
    :type pitchname: object
    """
    tid = diameter.getid(diametername)
    pid = pitch.getid(pitchname)

    cursor.execute('''SELECT Pitch2ThreadDiameterID
                       FROM LocknutData.dbo.Pitch2ThreadDiameter
                       WHERE PitchID = %i
                       AND ThreadDiameterID = %i''' % (pid, tid))
    if cursor.rowcount == 0:
        cursor.execute('''INSERT INTO LocknutData.dbo.Pitch2ThreadDiameter
                           (PitchID, ThreadDiameterID)
                           VALUES (%i, %i);''' % (pid, tid))
        cursor.commit()
    cursor.execute('''SELECT Pitch2ThreadDiameterID
                       FROM LocknutData.dbo.Pitch2ThreadDiameter
                       WHERE PitchID = %i
                       AND ThreadDiameterID = %i''' % (pid, tid))
    return cursor.fetchone()[0]
Пример #13
0
def query_request(query, type="GET"):
    if type == "GET":
        cursor.execute(query)
        data = cursor.fetchall()
        return data
Пример #14
0
def units(dia):
    cursor.execute('''SELECT MeasurementUnitID
           FROM LocknutData.dbo.ThreadDiameter 
           WHERE Name = '{}';'''.format(dia))
    return cursor.fetchone()[0]
    cursor.close()
Пример #15
0
import modify_photo
import random
from main import db, cursor, bot, get_username_or_first_name, awake_mysql_db


def create_markup_pin():
    markup_pin = telebot.types.InlineKeyboardMarkup()
    markup_pin.row(telebot.types.InlineKeyboardButton("Pin", callback_data="pin"),
                   telebot.types.InlineKeyboardButton("Dismiss", callback_data="dismiss"))
    return markup_pin


awake_mysql_db()

# Check if there was a birthday yesterday ------------------------------------------------------------------
cursor.execute("SELECT * FROM was_birthday")
was_birthdays = cursor.fetchall()

for past_birthday in was_birthdays:
    chat_id_of_past_birthday, new_photo_of_past_birthday_id, old_photo_of_past_birthday_id = past_birthday
    # If users blocked the bot, it won't be able to find the chat ------------------------------------------
    try:
        chat = bot.get_chat(chat_id_of_past_birthday)
    except telebot.apihelper.ApiException:
        chat = None
    if not chat:
        sql = "DELETE FROM birthdays WHERE Chat_Id = %s"
        val = (chat_id_of_past_birthday,)
        cursor.execute(sql, val)
        db.commit()
        continue