Code Duplication    Length = 30-30 lines in 2 locations

myems-cleaning/clean_digital_value.py 1 location

@@ 10-39 (lines=30) @@
7
import config
8
9
10
def job(logger):
11
12
    cnx_historical = None
13
    cursor_historical = None
14
    try:
15
        cnx_historical = mysql.connector.connect(**config.myems_historical_db)
16
        cursor_historical = cnx_historical.cursor()
17
    except Exception as e:
18
        logger.error("Error in clean digital value process " + str(e))
19
        if cursor_historical:
20
            cursor_historical.close()
21
        if cnx_historical:
22
            cnx_historical.close()
23
        return
24
25
    expired_utc = datetime.utcnow() - timedelta(days=config.live_in_days)
26
    try:
27
        cursor_historical.execute(" DELETE "
28
                                  " FROM tbl_digital_value "
29
                                  " WHERE utc_date_time < %s ", (expired_utc,))
30
        cnx_historical.commit()
31
    except Exception as e:
32
        logger.error("Error in delete_expired_trend process " + str(e))
33
    finally:
34
        if cursor_historical:
35
            cursor_historical.close()
36
        if cnx_historical:
37
            cnx_historical.close()
38
39
    logger.info("Deleted trend before date time in UTC: " + expired_utc.isoformat()[0:19])
40
41
42
def process(logger):

myems-cleaning/clean_analog_value.py 1 location

@@ 10-39 (lines=30) @@
7
import config
8
9
10
def job(logger):
11
12
    cnx_historical = None
13
    cursor_historical = None
14
    try:
15
        cnx_historical = mysql.connector.connect(**config.myems_historical_db)
16
        cursor_historical = cnx_historical.cursor()
17
    except Exception as e:
18
        logger.error("Error in clean analog value process " + str(e))
19
        if cursor_historical:
20
            cursor_historical.close()
21
        if cnx_historical:
22
            cnx_historical.close()
23
        return
24
25
    expired_utc = datetime.utcnow() - timedelta(days=config.live_in_days)
26
    try:
27
        cursor_historical.execute(" DELETE "
28
                                  " FROM tbl_analog_value "
29
                                  " WHERE utc_date_time < %s ", (expired_utc,))
30
        cnx_historical.commit()
31
    except Exception as e:
32
        logger.error("Error in delete_expired_trend process " + str(e))
33
    finally:
34
        if cursor_historical:
35
            cursor_historical.close()
36
        if cnx_historical:
37
            cnx_historical.close()
38
39
    logger.info("Deleted trend before date time in UTC: " + expired_utc.isoformat()[0:19])
40
41
42
def process(logger):