# Event based python code

**URL:** <https://forums.digi.com/t/event-based-python-code/13864>\
**Category:** Python\
**Tags:** ethernet, transport, telemetry, wr41, python\
**Created:** [November 4, 2014, 1:53pm UTC](https://forums.digi.com/t/event-based-python-code/13864 "2014-11-04T13:53:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fchavez14](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@fchavez14](https://forums.digi.com/u/fchavez14)\
**Post date:** [November 4, 2014, 1:53pm UTC](https://forums.digi.com/t/event-based-python-code/13864/1 "2014-11-04T13:53:10Z")

</div>

Hi,  
I’m trying to develop a python application for the Digi WR41 with a telemetry card 2 that allows me to set to high an output on the telemetry card when an specific event happens on the transport. As of now the code is not working properly because is inspecting the whole event log file instead of just the most recent event. Is there a way of monitoring only the most recent event rather than the whole file?. Below is the python code that i have developed so far:

import digihw  
import sarcli  
import time

# Constants

DIO1 = 0

def main():

```
# This is what we are looking for in the eventlog.txt
string_match1 = "ETH 0 Out Of Service,Ethernet"

```

filename = “eventlog.txt”

```
# Do forever
while True:
    # Try to open the eventlog.txt file, 'r' stands for "reading"

        filelog = open(filename, 'r')
        str = filelog.read() #read the file one line at a time

   # Check the eventlog.txt file for the string_match value.  
       
       if string_match1 in str:
            digihw.gpio_set_value(DIO1,1) 
        filelog.close()
        time.sleep (1)     

```

if **name** == ‘ **main** ’:  
main()
